Skip to content

feat: update Perps and Predictions sections to display unrealized P&L#27844

Merged
PatrykLucka merged 3 commits into
mainfrom
TMCU-584-add-unrealized-pnl-on-perps-and-predict-sections
Mar 27, 2026
Merged

feat: update Perps and Predictions sections to display unrealized P&L#27844
PatrykLucka merged 3 commits into
mainfrom
TMCU-584-add-unrealized-pnl-on-perps-and-predict-sections

Conversation

@PatrykLucka

@PatrykLucka PatrykLucka commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Description

Users with open Perpetuals or Predict positions could not see aggregate unrealized P&L on the wallet homepage next to those sections, and the Perps tab “Your positions” subtitle duplicated similar layout logic.

This PR:

  • Wallet homepage — Perps: Shows a sub-row under “Perpetuals” with aggregate unrealized P&L (and ROE %) when the user has filled open positions; hides it for privacy mode, while loading account data, or when there are no positions (including orders-only — no row). Colors follow profit (green) / loss (red) / flat (default text).
  • Wallet homepage — Predict: Shows the same style of row under “Predictions” using the existing unrealized P&L API (useUnrealizedPnL); pull-to-refresh also invalidates that query. Respects privacy mode.
  • Perps home (tab): Keeps the positions subtitle visible whenever there are open positions (including flat P&L), uses design-system text colors, and reuses the shared HomepageSectionUnrealizedPnlRow for the value + “Unrealized P&L” line so layout matches the homepage spec (4px under title, 8px between value and label).
  • Shared UI: New HomepageSectionUnrealizedPnlRow under homepage components (used by homepage sections + PerpsHomeSection).
  • Predict: formatPredictUnrealizedPnLStringParts in format.ts centralizes i18n interpolation for unrealized P&L strings; PredictPositionsHeader and PredictionsSection both use it.

Changelog

CHANGELOG entry: Added unrealized P&L summary on the wallet homepage for Perpetuals and Predictions, and aligned the Perps home “Your positions” subtitle with the same layout.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-584

Manual testing steps

Feature: Unrealized P&L on homepage Perps and Predict

  Scenario: Perps section shows aggregate unrealized P&L with open positions
    Given the user has at least one open Perpetuals position and privacy mode is off
    When the user views the wallet homepage
    Then the Perpetuals section shows a line with signed dollar P&L, percentage, and an unrealized P&L label below the section title
    And positive P&L is green and negative P&L is red

  Scenario: Perps section hides P&L without open positions
    Given the user has no open Perpetuals positions (only limit orders or none)
    When the user views the wallet homepage
    Then no unrealized P&L sub-row appears under Perpetuals and spacing below the title is unchanged

  Scenario: Predict section shows unrealized P&L with open positions
    Given the user has open Predict positions and privacy mode is off
    When the user views the wallet homepage
    Then the Predictions section shows the unrealized P&L sub-row consistent with design

  Scenario: Privacy mode hides homepage P&L values
    Given privacy mode is enabled
    When the user views the wallet homepage with Perps and/or Predict positions
    Then unrealized P&L sub-rows for those sections are not shown

  Scenario: Perps tab positions subtitle matches homepage styling
    Given the user has open Perps positions
    When the user opens the Perps home screen
    Then “Your positions” shows the unrealized P&L value and label with the same visual treatment as the homepage row

Screenshots/Recordings

Before

After

Pre-merge author checklist

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
Medium risk: adds new homepage UI rows driven by live Perps account state and Predict react-query data (including query invalidation on refresh), which could affect loading/visibility states and performance but does not touch auth or funds movement.

Overview
Adds a shared HomepageSectionUnrealizedPnlRow component and uses it to display aggregate unrealized P&L under the Wallet homepage Perpetuals and Predictions section titles when the user has open positions (and not in privacy mode), including loading placeholders and tone-based coloring.

Refactors Perps tab PerpsHomeSection/PerpsHomeView to reuse the same value+label row, switch to design-system TextColor tokens, and keep the positions subtitle visible whenever positions exist (including flat P&L). Predict’s positions header and homepage section now share a centralized formatPredictUnrealizedPnLStringParts formatter, and Predictions pull-to-refresh also invalidates the unrealized P&L query; tests were updated/added accordingly.

Written by Cursor Bugbot for commit 50ae867. This will update automatically on new commits. Configure here.

@PatrykLucka PatrykLucka self-assigned this Mar 24, 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.

@metamaskbot metamaskbot added the team-mobile-ux Mobile UX team label Mar 24, 2026
@PatrykLucka PatrykLucka marked this pull request as ready for review March 24, 2026 09:37
@PatrykLucka PatrykLucka requested review from a team as code owners March 24, 2026 09:37
@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Mar 24, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps, @PerformancePredict
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR introduces UI changes to the Homepage's Perps and Predictions sections, plus the PerpsHomeView:

  1. PerpsSection (Homepage): Now shows an aggregate unrealized P&L row (HomepageSectionUnrealizedPnlRow) when the user has filled positions. Adds usePerpsLiveAccount hook and privacy mode integration. This directly affects the Perps section in the Trending/Homepage tab.

  2. PredictionsSection (Homepage): Now shows unrealized P&L row for Predict positions. Adds useUnrealizedPnL hook, privacy mode integration, and query invalidation on refresh.

  3. PerpsHomeView: Minor logic fix (removed zero-PnL check so P&L shows even when flat) and updated TextColor enum values from deprecated to new design system values.

  4. PerpsHomeSection: Refactored subtitle rendering to use the new shared HomepageSectionUnrealizedPnlRow component.

  5. New HomepageSectionUnrealizedPnlRow component: Shared UI component used by both Perps and Predictions sections.

  6. format.ts utility: New formatPredictUnrealizedPnLStringParts function extracted and shared.

Tag selection rationale:

  • SmokePerps: Directly affected — PerpsSection homepage display and PerpsHomeView both changed. Per tag description, also requires SmokeWalletPlatform and SmokeConfirmations.
  • SmokePredictions: Directly affected — PredictionsSection homepage display changed. Per tag description, also requires SmokeWalletPlatform and SmokeConfirmations.
  • SmokeWalletPlatform: Required by both SmokePerps and SmokePredictions (Trending tab contains both sections). The Trending tab is the entry point for these subsections.
  • SmokeConfirmations: Required by both SmokePerps and SmokePredictions per their tag descriptions (deposits/positions are on-chain transactions).

Risk is medium because these are UI display changes to existing features (not core logic), but they introduce new data subscriptions (hooks) and a new shared component that could affect rendering behavior across multiple homepage sections.

Performance Test Selection:
Two new data hooks are added to homepage sections: usePerpsLiveAccount in PerpsSection and useUnrealizedPnL in PredictionsSection. These add new data subscriptions that run on the homepage/Trending tab. The new HomepageSectionUnrealizedPnlRow component renders conditionally for users with positions. These changes could affect homepage rendering performance for users with active Perps or Predict positions. @PerformancePreps covers perps market loading and balance display, and @PerformancePredict covers prediction market list loading and balance display — both are directly relevant to the new P&L row rendering.

View GitHub Actions results

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@caieu caieu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aganglada aganglada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one non-blocking nit

Comment on lines +154 to +178
{/* Value + muted label: same row as wallet homepage unrealized P&L (8px gap). */}
{subtitle && subtitleSuffix ? (
<HomepageSectionUnrealizedPnlRow
label={subtitleSuffix}
valueText={subtitle}
valueColor={subtitleColor}
paddingHorizontal={0}
marginTop={1}
valueTestID={subtitleTestID}
labelTestID={
subtitleTestID ? `${subtitleTestID}-suffix` : undefined
}
/>
) : subtitle ? (
<Box marginTop={1}>
<Text
variant={TextVariant.BodyMd}
color={subtitleColor}
fontWeight={FontWeight.Medium}
testID={subtitleTestID}
>
{subtitle}
</Text>
</Box>
) : null}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] We could exact this to it's own component (non-blocking)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think we could do that at some point, now I'm pretty sure we will be still changing things around here, so I think we could leave this subtitle thing separated for now

@PatrykLucka PatrykLucka added this pull request to the merge queue Mar 27, 2026
Merged via the queue into main with commit 2324e7c Mar 27, 2026
181 of 183 checks passed
@PatrykLucka PatrykLucka deleted the TMCU-584-add-unrealized-pnl-on-perps-and-predict-sections branch March 27, 2026 11:04
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2026
@metamaskbot metamaskbot added the release-7.73.0 Issue or pull request that will be included in release 7.73.0 label Mar 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.73.0 Issue or pull request that will be included in release 7.73.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-L team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants