metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

feat: activity details for perps and predict

Open PatrykLucka opened this issue 5 months ago • 6 comments

Description

Adds redesigned Activity Details support for Perps and Predict activity rows behind the transactions redesign flow.

This PR routes Perps and Predict domain activity to the new ActivityDetails screen, using preloaded domain items when provider-backed data cannot be safely re-read outside its source/provider tree. It adds dedicated Perps and Predict templates, shared timeline/footer/frame building blocks, Polymarket deep links, Perps block explorer links, and domain-specific formatting for trades, orders, funding, deposits, withdrawals, predictions, cash-outs, and winnings claims.

It also expands Perps activity adapter coverage for historical order rows, preserves Polymarket market slugs for details links, and standardizes canceled copy in the redesigned activity surfaces.

Changelog

CHANGELOG entry: Added redesigned activity details for Perps and Predict transactions

Related issues

Fixes:

Manual testing steps

Feature: Redesigned activity details for Perps and Predict

  Scenario: user opens a Perps trade from Activity
    Given the transactions redesign feature flag is enabled
    And the user has Perps trade activity in the Activity list

    When the user taps the Perps activity row
    Then the Activity Details screen opens
    And the Perps trade details, status, date, fees, explorer CTA, and "Trade again" CTA are shown

  Scenario: user opens a Perps funds movement from Activity
    Given the transactions redesign feature flag is enabled
    And the user has Perps deposit or withdrawal activity in the Activity list

    When the user taps the Perps funds movement row
    Then the Activity Details screen opens
    And the funds amount, account metadata, network metadata, step timeline, and fund/withdraw CTA are shown

  Scenario: user opens a Predict market activity from Activity
    Given the transactions redesign feature flag is enabled
    And the user has Predict placed, cashed out, or claim winnings activity in the Activity list

    When the user taps the Predict activity row
    Then the Activity Details screen opens
    And the prediction market context, amount/share rows, Polymarket CTA, and "Place another prediction" CTA are shown where applicable

  Scenario: user opens a Predict funds movement from Activity
    Given the transactions redesign feature flag is enabled
    And the user has Predict add funds or withdraw funds activity in the Activity list

    When the user taps the Predict funds row
    Then the Activity Details screen opens
    And the funds amount, account metadata, network metadata, step timeline, and fund/withdraw CTA are shown

Screenshots/Recordings

Before

After

Screenshot 2026-06-25 at 14 58 09 Screenshot 2026-06-25 at 14 58 17 Screenshot 2026-06-25 at 14 58 26 Screenshot 2026-06-25 at 14 58 52 Screenshot 2026-06-25 at 14 59 04 Screenshot 2026-06-25 at 14 59 13 Screenshot 2026-06-25 at 14 59 20 Screenshot 2026-06-25 at 14 59 28

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
    • See trace() for usage and addToken for an example

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 Large new navigation and detail UI for trading/prediction flows with preloaded-item resolution; adapter changes affect which perps orders appear in activity and how they are classified.

Overview With the transactions redesign enabled, Perps and Predict rows now open the shared Activity Details screen instead of legacy dedicated flows (bridges still use their own screen). Navigation passes an optional preloadedItem so domain rows whose raw data cannot be re-fetched outside the provider tree still render correctly; lookup also indexes perps/predict ids and prefers the preloaded row over hash collisions.

TemplateLoader wires new PerpsDetails and PredictDetails templates (plus shared frame, step timeline, webview footer, and perps hero/metadata). Perps covers trades, orders, funding, and deposit/withdrawal timelines with explorer and repeat CTAs; Predict covers market activity (Polymarket link, P&L when present), claim winnings, and fund movements.

The perps activity adapter now maps historical order rows (filled/canceled/rejected) into activity kinds, including new limitShort / limitCloseShort, with list titles/icons updated accordingly. Polymarket parsing preserves slug, eventSlug, and P&L fields for details and deep links.

Copy/UI polish: transaction.canceled (US spelling) in redesigned surfaces, Predict buy/sell divider fix, and Total Net P&L capitalization.

Reviewed by Cursor Bugbot for commit 25e6771b98a4ef07d0cee98ab83278f0a859ca94. Bugbot is set up for automated code reviews on this repo. Configure here.

PatrykLucka avatar Jun 25 '26 12:06 PatrykLucka

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[bot] avatar Jun 25 '26 12:06 github-actions[bot]

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 on Android"). 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.

metamask-ci avatar Jun 25 '26 16:06 metamask-ci

Requesting changes, but this is close to ready. I agree that preloadedItem is the right approach for Perps and Predict rows because the details screen should render the provider backed item it was opened from.

The changes I am blocking on are:

  1. Order rows currently drop the position size subtitle because sourceToken.amount is missing.
  2. Limit order titles from transformOrdersToTransactions can be displayed as market orders.

Non-blocking follow-up: I think the new Perps detail formatters should be aligned with the existing Perps formatter contract. I also noticed the legacy Perps order detail screen likely mishandles Triggered-order fees by checking the display text instead of the filled status type; I would not change this new Activity Details behavior to match that legacy zero fee display.

Solid call outs let me look into the issues you raised

Update: Fixed here 07ab66e

vinnyhoward avatar Jun 25 '26 20:06 vinnyhoward

Found these:

🔴 High Severity

H1 — preloadedItem is a non-serializable object in React Navigation params

Files: ActivityList.tsx → ActivityDetails.types.ts → ActivityDetails.tsx

The PR passes a full ActivityListItem object as a navigation parameter to avoid re-fetching provider-backed Perps/Predict items outside their source tree:

navigation.navigate(Routes.ACTIVITY_DETAILS, {
  chainId: item.chainId,
  txIdentifier: item.hash,
  ...(raw.type === 'perpsTransaction' || raw.type === 'predictActivity'
    ? { preloadedItem: item }
    : {}),
});

Problems:

  • React Navigation serializes route params to JSON for state persistence, deep-link rehydration, and @react-navigation/devtools. Non-serializable values (nested class instances, functions, circular references inside raw.data) trigger a dev warning and silently break state persistence for the ActivityDetails route.
  • If state is ever restored from persistence (app killed and re-opened via a background notification), the screen will have the chainId/txIdentifier params but no preloadedItem, and Perps/Predict rows will fall through to "not found."
  • There is no guard in the current useActivityDetailsItem to skip lookup and return the preloaded item — the branch must introduce this, but it needs to be verified.

Recommendation: Use a module-scoped ref store (e.g. Map<hash, ActivityListItem>) or React context to hand off the transient item before navigating, and keep route params serializable. If preloadedItem stays in params, the ActivityDetails route must be explicitly excluded from any persisted navigation state and documented as such.


H2 — Claim breakdown ignores totalNetPnlUsd / netPnlUsd (regression vs. legacy)

Files: PredictProviderActivityDetails.tsx, PredictDetailsShared.tsx

The PR adds totalNetPnlUsd and netPnlUsd to PredictActivity and the Polymarket parser, but the new claim template never consumes them. ClaimWinningsBreakdown receives only entry.amount and renders the same gross amount in both the "Total Net P&L" row and the per-market row.

The legacy PredictActivityDetail.tsx correctly used dedicated fields:

// Legacy claim branch
formatCurrencyValue(activity.totalNetPnlUsd ?? entryAmount, { showSign: true }); // total row
formatCurrencyValue(activity.netPnlUsd ?? entryAmount,      { showSign: true }); // market row

When the API supplies real P&L figures, users will see the gross claimed amount displayed twice instead of the correct total and per-market P&L values. This is a behavioral regression relative to the legacy screen.

Note: The cashed-out (isSell) P&L path was correctly updated in a follow-up commit to use netPnlUsd with sign-aware coloring. The claim path was missed.

Fix: Mirror the legacy approach — pass activity.totalNetPnlUsd ?? entry.amount for the total row and activity.netPnlUsd ?? entry.amount for the market row inside ClaimWinningsBreakdown.


🟠 Medium Severity

M1 — Order sourceToken.amount derived from subtitle string parsing is fragile

Files: perps-transaction.ts (commit 1af5022)

After reviewer feedback, order row sourceToken.amount is recovered by parsing transaction.subtitle (format: "<size> <symbol>"):

const [sizeStr] = transaction.subtitle?.split(' ') ?? [];
sourceToken: { amount: sizeStr, symbol: transaction.asset, direction }

This is parsing a human-readable display string as structured data. If formatOrderLabel changes its subtitle format (e.g. adds a prefix, uses a non-breaking space, or localizes), sizeStr will silently become undefined or garbage without any test failure. The original approach of computing from size / limitPrice was equally fragile for limit-price-absent cases.

Recommendation: Either surface size as a dedicated structured field in PerpsTransaction.order, or add a guard and fallback with a logged warning so the failure mode is visible rather than silent.


M2 — Predict withdrawal timeline is silently omitted

Files: PredictFundsDetails.tsx

const steps =
  isDeposit && item.status !== 'cancelled'
    ? getPredictFundsSteps(item.status, item.timestamp)
    : undefined;

The timeline is only built for deposits. Withdrawal rows never render the step timeline, despite the PR description stating "the funds amount, account metadata, network metadata, step timeline, and fund/withdraw CTA are shown" for all Predict funds movements.

There are no predict.transactions.steps locale keys defined for withdrawal (only bridge_funds / add_funds are present). If withdrawal timelines are genuinely out of scope for this PR, the code needs a comment explaining why, and the PR description should be corrected. If withdrawal timelines are needed, the locale keys and step builder are missing.


M3 — Triggered order fees diverge from legacy screen

Files: PerpsDetails template (activity details), legacy PerpsOrderTransactionView

The new Activity Details template treats triggered orders as fully executed (maps to statusType: Filled, filled: 100% via transformOrdersToTransactions) and shows calculated order fees.

The legacy PerpsOrderTransactionView zeroes fees for triggered orders by checking order.text === 'Filled' as the gate.

Per HyperLiquid docs, triggered and filled are separate statuses: triggered means the trigger condition fired, while fees appear on the actual fill/trade record. This means:

  • The new screen may show non-zero fees for triggered orders that have not yet produced a fill.
  • The two details surfaces (legacy and new) show different fee values for the same order.

This was raised as a non-blocking follow-up by geositta but is a real UX correctness risk. A Product decision is needed on whether to gate fee display on a shared helper that checks actual fill data.


MarioAslau avatar Jun 25 '26 22:06 MarioAslau

🔴 High Severity

H1 — preloadedItem is a non-serializable object in React Navigation params

Files: ActivityList.tsx → ActivityDetails.types.ts → ActivityDetails.tsx

The PR passes a full ActivityListItem object as a navigation parameter to avoid re-fetching provider-backed Perps/Predict items outside their source tree:

navigation.navigate(Routes.ACTIVITY_DETAILS, {
  chainId: item.chainId,
  txIdentifier: item.hash,
  ...(raw.type === 'perpsTransaction' || raw.type === 'predictActivity'
    ? { preloadedItem: item }
    : {}),
});

Problems:

  • React Navigation serializes route params to JSON for state persistence, deep-link rehydration, and @react-navigation/devtools. Non-serializable values (nested class instances, functions, circular references inside raw.data) trigger a dev warning and silently break state persistence for the ActivityDetails route.
  • If state is ever restored from persistence (app killed and re-opened via a background notification), the screen will have the chainId/txIdentifier params but no preloadedItem, and Perps/Predict rows will fall through to "not found."
  • There is no guard in the current useActivityDetailsItem to skip lookup and return the preloaded item — the branch must introduce this, but it needs to be verified.

Recommendation: Use a module-scoped ref store (e.g. Map<hash, ActivityListItem>) or React context to hand off the transient item before navigating, and keep route params serializable. If preloadedItem stays in params, the ActivityDetails route must be explicitly excluded from any persisted navigation state and documented as such.

Fixed here using transient store b79a420

H2 — Claim breakdown ignores totalNetPnlUsd / netPnlUsd (regression vs. legacy)

Files: PredictProviderActivityDetails.tsx, PredictDetailsShared.tsx

The PR adds totalNetPnlUsd and netPnlUsd to PredictActivity and the Polymarket parser, but the new claim template never consumes them. ClaimWinningsBreakdown receives only entry.amount and renders the same gross amount in both the "Total Net P&L" row and the per-market row.

The legacy PredictActivityDetail.tsx correctly used dedicated fields:

// Legacy claim branch
formatCurrencyValue(activity.totalNetPnlUsd ?? entryAmount, { showSign: true }); // total row
formatCurrencyValue(activity.netPnlUsd ?? entryAmount,      { showSign: true }); // market row

When the API supplies real P&L figures, users will see the gross claimed amount displayed twice instead of the correct total and per-market P&L values. This is a behavioral regression relative to the legacy screen.

Note: The cashed-out (isSell) P&L path was correctly updated in a follow-up commit to use netPnlUsd with sign-aware coloring. The claim path was missed.

Fix: Mirror the legacy approach — pass activity.totalNetPnlUsd ?? entry.amount for the total row and activity.netPnlUsd ?? entry.amount for the market row inside ClaimWinningsBreakdown.

This is fixed here c229759

🟠 Medium Severity

M1 — Order sourceToken.amount derived from subtitle string parsing is fragile

Files: perps-transaction.ts (commit 1af5022)

After reviewer feedback, order row sourceToken.amount is recovered by parsing transaction.subtitle (format: "<size> <symbol>"):

const [sizeStr] = transaction.subtitle?.split(' ') ?? [];
sourceToken: { amount: sizeStr, symbol: transaction.asset, direction }

This is parsing a human-readable display string as structured data. If formatOrderLabel changes its subtitle format (e.g. adds a prefix, uses a non-breaking space, or localizes), sizeStr will silently become undefined or garbage without any test failure. The original approach of computing from size / limitPrice was equally fragile for limit-price-absent cases.

Recommendation: Either surface size as a dedicated structured field in PerpsTransaction.order, or add a guard and fallback with a logged warning so the failure mode is visible rather than silent.


M2 — Predict withdrawal timeline is silently omitted

Files: PredictFundsDetails.tsx

const steps =
  isDeposit && item.status !== 'cancelled'
    ? getPredictFundsSteps(item.status, item.timestamp)
    : undefined;

The timeline is only built for deposits. Withdrawal rows never render the step timeline, despite the PR description stating "the funds amount, account metadata, network metadata, step timeline, and fund/withdraw CTA are shown" for all Predict funds movements.

There are no predict.transactions.steps locale keys defined for withdrawal (only bridge_funds / add_funds are present). If withdrawal timelines are genuinely out of scope for this PR, the code needs a comment explaining why, and the PR description should be corrected. If withdrawal timelines are needed, the locale keys and step builder are missing.

  • M1: order size now only uses the subtitle token when it's a valid number else omits it no garbage, with the transformOrdersToTransactions test guarding against format drift.

  • M2: the Predict step timeline is intentionally deposit-only documented in-code, and I'll fix the PR description. Fix here: c229759

M3 — Triggered order fees diverge from legacy screen

Files: PerpsDetails template (activity details), legacy PerpsOrderTransactionView

The new Activity Details template treats triggered orders as fully executed (maps to statusType: Filled, filled: 100% via transformOrdersToTransactions) and shows calculated order fees.

The legacy PerpsOrderTransactionView zeroes fees for triggered orders by checking order.text === 'Filled' as the gate.

Per HyperLiquid docs, triggered and filled are separate statuses: triggered means the trigger condition fired, while fees appear on the actual fill/trade record. This means:

  • The new screen may show non-zero fees for triggered orders that have not yet produced a fill.
  • The two details surfaces (legacy and new) show different fee values for the same order.

This was raised as a non-blocking follow-up by geositta but is a real UX correctness risk. A Product decision is needed on whether to gate fee display on a shared helper that checks actual fill data.

This was flagged earlier by @geositta as well. Leaving it as is for now and waiting on Product's verdict on what to do @MarioAslau

vinnyhoward avatar Jun 26 '26 01:06 vinnyhoward

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection: The PR introduces significant changes to the Activity Details and Activity List flows for Perps and Predictions:

  1. SmokePerps: Directly impacted by:

    • New PerpsDetails template for rendering perps activity details (trades, orders, funding, deposits/withdrawals)
    • ActivityList.tsx now routes perps transactions through ActivityDetails screen via preloadedActivityItemStore
    • New order transaction support in perps-transaction.ts (limit/market short orders)
    • New ActivityDetailsPerps.utils.ts utility file
    • New activity kinds: limitShort, limitCloseShort
    • Per tag description, SmokePerps also requires SmokeWalletPlatform (Trending section) and SmokeConfirmations
  2. SmokePredictions: Directly impacted by:

    • New PredictDetails template for rendering predict activity details
    • ActivityList.tsx now routes predict activities through ActivityDetails screen
    • Bug fix in PredictActivityDetail.tsx for conditional rendering
    • New predict-specific strings in locales
    • Per tag description, SmokePredictions also requires SmokeWalletPlatform and SmokeConfirmations
  3. SmokeWalletPlatform: Impacted by:

    • Transaction history display changes (ActivityList routing changes)
    • "cancelled" → "canceled" string change in en.json and useActivityListItemRowContent.ts affects all transaction status displays
    • Activity list item row content changes
  4. SmokeConfirmations: Required as a dependent tag per both SmokePerps and SmokePredictions tag descriptions (deposits/withdrawals and position operations are on-chain transactions).

Performance Test Selection: The changes are focused on UI rendering for activity details (Perps/Predict), routing logic in the activity list, and new templates. These are not performance-sensitive paths - they affect detail screens that are navigated to after tapping an activity item, not core app launch, login, asset loading, or swap flows. No performance test tags are warranted.

View GitHub Actions results

github-actions[bot] avatar Jun 26 '26 02:06 github-actions[bot]