Skip to content

feat(predict): add a local Settlement activity kind to shared Activity - #38411

Merged
matallui merged 3 commits into
mainfrom
feat/pred-1405-settlement-kind
Oct 29, 2026
Merged

matallui merged 3 commits into
mainfrom
feat/pred-1405-settlement-kind

Conversation

@matallui

@matallui matallui commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

PredictNext calls a resolved market paying out a held position a Settlement. Kalshi settles automatically, so the legacy predictionClaimWinnings kind ("Claimed winnings") doesn't fit. This PR adds a predictionSettled kind to shared Activity so E5 (PRED-1410) can map canonical Settlements into it.

Local first, then upstream. ActivityKind comes 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 reads prediction* kinds, client-utils functions only return ActivityItem, and mobile gets ActivityKind from app/util/activity-adapters/types.ts only. The kind is not persisted, not in analytics and not in navigation params. The local declaration is a single block in types.ts (LocalActivityKindShapes). It maps predictionSettled to 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:

  • Types (app/util/activity-adapters/types.ts): the local kind and item variant. Settlement extras on data, as plain decimal strings because shared code can't import PredictNext types (ADR-0020): outcomeLabel, marketQuestion, side, result (yes / no / scalar), shares and an optional realizedPnl. data.token carries proceeds with direction in. There's no manual-Claim marker.
  • Venue chain key: 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.
  • Row: receive icon, "Settled" title, the market question as subtitle, the proceeds amount, and membership in the Predictions filter.
  • Details: TemplateLoader → PredictDetails sends predictionSettled to a new PredictSettlementDetails template. 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 when realizedPnl is absent.
  • Fix found along the way: getMaybeHexChainId treated any CAIP-2 namespace that bridge-controller doesn't know as EVM, so formatChainIdToHex threw on kalshi:mainnet and crashed the row in useConvertToFiat. It now returns undefined for any CAIP-2 ID outside eip155, as its doc already promised. The Activity details hooks (useActivityNetworkName, useActivityAmountsFiat) go through the same function.
  • Contract doc: the "Shared Activity kinds" section now names predictionSettled, the venue constant and the local-then-upstream approach.

predictionClaimWinnings and 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 in usePredictActivityItems.

Changelog

CHANGELOG entry: null

Related issues

Refs: PRED-1405

Manual testing steps

N/A. Nothing produces predictionSettled items 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 through TemplateLoader with fixture items for a win, a loss (proceeds "0"), an absent realizedPnl and a scalar result.

Screenshots/Recordings

N/A. No reachable UI until E5.

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

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 predictionSettled activity kind (declared locally in activity adapters until @metamask/client-utils ships it) so Kalshi Settlements can appear in Activity without reusing legacy Claimed winnings. Items carry settlement fields on data (market question, side, result, shares, optional net P&L) and use KALSHI_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 when realizedPnl is absent).

Also fixes getMaybeHexChainId so unknown non-eip155 CAIP-2 IDs (including kalshi:mainnet) return undefined instead 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.

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
@matallui matallui self-assigned this Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added size-L pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels Oct 28, 2026
@metamask-ci metamask-ci Bot added the team-predict Predict team label Oct 28, 2026
@metamask-ci

metamask-ci Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Pre-merge author checklist has unchecked items (e.g. "I've tested with a power user scenario"). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@matallui

Copy link
Copy Markdown
Contributor Author

QA report

Result: all scenarios pass, no crashes. Opening Settlement details is blocked as expected until PRED-1410.

Setup: iOS simulator, dev build v8.19.0, at branch tip 40d7d00. The QA wallet has no Predict or EVM history, so I mocked the HTTP responses for the Polymarket and EVM activity rows. Nothing produces predictionSettled items until PRED-1410. To see them, I added three fixture Settlements to usePredictActivityItems in a temporary local patch: a win, a loss and a scalar result, all with chainId: kalshi:mainnet. I reverted the patch afterwards and never committed it.

# Scenario Result
1 Settlement rows under the Predictions filter ✅ Pass
2 Opening a Settlement row ✅ No crash. Details are unavailable, as expected until PRED-1410
3 Legacy Predict activity (placed, cashed out, claimed) ✅ Pass
4 EVM activity rows and details after the getMaybeHexChainId change ✅ Pass
5 Swap screen sanity check ✅ Pass

1–2. Settlement rows

Every row shows the title "Settled", the market question as subtitle and the proceeds amount. The amounts are +$10.00 for the win, +$0.00 for the loss and +$5.00 for the scalar result. No row has a network badge, and kalshi:mainnet no longer crashes the row. The legacy Predict rows sit below them in the same filter.

Tapping a Settlement opens the standard "Transaction details are unavailable" screen without a crash. The lookup that resolves these items from route params arrives with PRED-1410. Until then, the component view test in ActivityDetails.predict.view.test.tsx covers the Settlement details template, including a win, a loss, an absent P&L and a scalar result.

Settlement rows With the legacy rows Opening a Settlement
Three Settled rows under the Predictions filter Settled rows above Prediction placed, Cashed out and Claimed winnings Transaction details are unavailable screen

The avatars show the letter placeholder because the fixture image URL doesn't resolve. A unit test covers the receive-icon mapping for this kind, but no screenshot shows it.

3. Legacy Predict activity

The Prediction placed (-$4.20), Cashed out (+$7.50) and Claimed winnings (+$5.49) rows render as before. Their details screens show the same fields as before:

  • Prediction placed: predicted amount, shares bought, price per share and "View on Polymarket".
  • Cashed out: shares sold and price per share.
  • Claimed winnings: the +$5.49 header and the Total Net P&L breakdown.
Claimed winnings details
Claimed winnings details with +$5.49 and Total Net P&L

4–5. EVM activity and Swap

The EVM rows still show fiat values and network badges: the Ethereum send shows -$1,165.32, and the swap shows the Linea badge. The send's details show "Ethereum Main Network", the network fee and a total of $1,165.37. The Swap screen loads, token selection works and prices load. Nothing was submitted.

EVM rows Send details Swap
Sent ETH and Swapped rows with network badges and fiat Sent ETH details with network name and fiat total Swap screen with ETH to USDT

Repo checks

  • Unit tests: the ActivityListItemRow, resolveIconType, PredictDetails.utils, ActivityScreen types and bridge util suites pass.
  • View tests: ActivityDetails.predict.view.test.tsx passes all 22 tests on iOS and Android.
  • Type check: tsc passes.

Not related to this PR

  • In the dev environment, the accounts API balance and transaction endpoints return 403. With no balance loaded, the Swap input shows $0 for a typed amount.
  • At launch the app logs Snap storage warnings. They predate this change.

@matallui matallui removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Oct 28, 2026
@matallui
matallui marked this pull request as ready for review October 28, 2026 15:38
@matallui
matallui requested review from a team as code owners October 28, 2026 15:38
@github-actions

Copy link
Copy Markdown
Contributor

Smart E2E Test Selection

Selected E2E tags: ALL

AI Confidence: 100

E2E reasoning

Expand to read

Hard 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:

  1. New predictionSettled activity kind (Kalshi settlement support) added to activity-adapters types and index
  2. ActivityListItemRow components updated to handle predictionSettled (resolveIconType, titleLabels, useActivityListItemRowContent)
  3. New PredictSettlementDetails component and PredictDetails.utils.ts settlement outcome logic
  4. TemplateLoader updated to route predictionSettled to PredictDetails
  5. Component view test presets/renderers updated with Kalshi settlement fixtures

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.

View run

@sonarqubecloud

Copy link
Copy Markdown

@matallui
matallui enabled auto-merge October 28, 2026 20:30
@matallui
matallui added this pull request to the merge queue Oct 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 29, 2026
@matallui
matallui added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 3884bf7 Oct 29, 2026
221 of 222 checks passed
@matallui
matallui deleted the feat/pred-1405-settlement-kind branch October 29, 2026 10:38
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 29, 2026
@metamask-ci metamask-ci Bot added the release-8.19.0 Issue or pull request that will be included in release 8.19.0 label Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.19.0 Issue or pull request that will be included in release 8.19.0 size-L team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants