Repository navigation
feat(predict): add a local Settlement activity kind to shared Activity - #38411
Conversation
getMaybeHexChainId treated any namespace bridge-controller doesn't know as EVM and threw from formatChainIdToHex. An activity row with a venue chain key such as kalshi:mainnet crashed in useConvertToFiat. Refs: PRED-1405
Widen ActivityKind locally with predictionSettled so PRED-1410 isn't blocked on a @metamask/client-utils release. The local kind reuses the predictionClaimWinnings item shape and is declared in one block in activity-adapters/types.ts, to delete once a client-utils bump ships it. - Settlement extras (outcomeLabel, marketQuestion, side, result, shares, realizedPnl) as plain decimal strings - KALSHI_VENUE_CHAIN_ID (kalshi:mainnet) venue-scoped chain key - Row: receive icon, "Settled" title, market subtitle, proceeds amount - Predictions filter membership - Settlement details template rendered from the item alone Refs: PRED-1405
…nstant Refs: PRED-1405
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
Smart E2E Test SelectionSelected E2E tags: ALL AI Confidence: 100 E2E reasoningExpand to readHard rule seed (en-locale-change) mandates ALL tags due to changes in locales/languages/en.json. The locale changes add new prediction settlement strings (settled_title, shares_settled, settlement_result_won/lost/partial) that feed UI text and E2E label selectors — these are not cosmetic. Beyond the locale trigger, the PR introduces functional changes to the Predictions feature:
Primary affected flows: SmokePredictions (prediction activity display, settlement details), SmokeWalletPlatform (activity list/Trending section), SmokeConfirmations (activity details). The locale change alone justifies ALL per the hard rule, and the functional scope across activity display components reinforces broad coverage. |
|










Description
PredictNext calls a resolved market paying out a held position a Settlement. Kalshi settles automatically, so the legacy
predictionClaimWinningskind ("Claimed winnings") doesn't fit. This PR adds apredictionSettledkind to shared Activity so E5 (PRED-1410) can map canonical Settlements into it.Local first, then upstream.
ActivityKindcomes from@metamask/client-utils. To keep E5 from waiting on a client-utils release, mobile widens the kind locally, and the same kind goes upstream in a separate MetaMask/core PR. This is safe because no client-utils mapper or formatter produces or readsprediction*kinds, client-utils functions only returnActivityItem, and mobile getsActivityKindfromapp/util/activity-adapters/types.tsonly. The kind is not persisted, not in analytics and not in navigation params. The local declaration is a single block intypes.ts(LocalActivityKindShapes). It mapspredictionSettledto the client-utils kind whose item shape it reuses (predictionClaimWinnings). Once a client-utils bump ships the kind, the follow-up deletes that entry.What's in it:
app/util/activity-adapters/types.ts): the local kind and item variant. Settlement extras ondata, as plain decimal strings because shared code can't import PredictNext types (ADR-0020):outcomeLabel,marketQuestion,side,result(yes/no/scalar),sharesand an optionalrealizedPnl.data.tokencarriesproceedswith directionin. There's no manual-Claim marker.KALSHI_VENUE_CHAIN_ID(kalshi:mainnet), exported from the activity adapters. It is never Polygon or any other real chain, and it only keys the details source for Next items.TemplateLoader→PredictDetailssendspredictionSettledto a newPredictSettlementDetailstemplate. It renders from the item alone, with no lookup by id: the proceeds hero, outcome and market, status and date, result (Won / Lost / Partial payout), shares settled and Net P&L. The Net P&L row is omitted whenrealizedPnlis absent.getMaybeHexChainIdtreated any CAIP-2 namespace that bridge-controller doesn't know as EVM, soformatChainIdToHexthrew onkalshi:mainnetand crashed the row inuseConvertToFiat. It now returnsundefinedfor any CAIP-2 ID outsideeip155, as its doc already promised. The Activity details hooks (useActivityNetworkName,useActivityAmountsFiat) go through the same function.predictionSettled, the venue constant and the local-then-upstream approach.predictionClaimWinningsand the legacy Polymarket path are unchanged. Out of scope, all in E5 (PRED-1410): mapping canonical entries to rows, the Next details resolver, and venue branching inusePredictActivityItems.Changelog
CHANGELOG entry: null
Related issues
Refs: PRED-1405
Manual testing steps
N/A. Nothing produces
predictionSettleditems until E5 (PRED-1410) maps Kalshi Settlements. Unit tests cover the row (icon, title, subtitle, amount, no network badge) and filter membership. A component view test renders the Settlement template throughTemplateLoaderwith fixture items for a win, a loss (proceeds"0"), an absentrealizedPnland ascalarresult.Screenshots/Recordings
N/A. No reachable UI until E5.
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Touches shared activity typing, list/details rendering, and chain-id normalization used by fiat hooks; behavior is test-covered but spans predict UI and bridge utilities.
Overview
Adds a
predictionSettledactivity kind (declared locally in activity adapters until@metamask/client-utilsships it) so Kalshi Settlements can appear in Activity without reusing legacy Claimed winnings. Items carry settlement fields ondata(market question, side, result, shares, optional net P&L) and useKALSHI_VENUE_CHAIN_ID(kalshi:mainnet) as a venue key—not a real chain.List rows treat settlements like other predict trades: receive icon, Settled title, market question subtitle, signed proceeds in USD, and inclusion in the Predictions filter only.
Details route through
PredictSettlementDetails, rendering proceeds, outcome/market context, won/lost/partial result, shares settled, and optional Net P&L (hidden whenrealizedPnlis absent).Also fixes
getMaybeHexChainIdso unknown non-eip155CAIP-2 IDs (includingkalshi:mainnet) returnundefinedinstead of throwing during fiat conversion. New i18n strings, contract doc updates, fixtures, and tests cover rows, icons, filters, details, and the chain-id helper.Reviewed by Cursor Bugbot for commit 40d7d00. Bugbot is set up for automated code reviews on this repo. Configure here.