Skip to content

fix(perps): leverage not displayed in position details#41535

Open
abretonc7s wants to merge 6 commits intomainfrom
fix/tat-2796-leverage-display
Open

fix(perps): leverage not displayed in position details#41535
abretonc7s wants to merge 6 commits intomainfrom
fix/tat-2796-leverage-display

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Apr 8, 2026

Description

Fix TAT-2796 — leverage was not visible on the perps position details page despite being available on the position object.

This PR replaces #41469, which was opened against the wrong base branch (fix/metamask-metamask-extension-41350) due to a corrupted local origin/HEAD symbolic-ref. That made it diff 968 files even though only 4 files were actually changed. Recreating cleanly here against main.

The fix has two commits:

  1. Add the leverage row to PerpsMarketDetailPage's Details Section, plus a perpsInjectPositions test hook on window.stateHooks (gated by METAMASK_DEBUG/IN_TEST) for recipe-based E2E validation.
  2. Combine direction + leverage into a single row to match the mobile PerpsPositionCard pattern ("Long 3x" / "Short 3x" instead of two separate rows).

Changelog

Fixed

  • Leverage now displays on the perps position details page, combined with direction as "Long Nx" / "Short Nx" matching mobile UX

Added

  • window.stateHooks.perpsInjectPositions debug-only test hook for E2E recipe validation

Related issues

Fixes: TAT-2796

Manual testing steps

  1. Open the extension on a perps-enabled testnet account with at least one open position
  2. Navigate to the position details page for any open position
  3. Confirm the Details Section shows a row reading "Long Nx" or "Short Nx" (where N is the position's leverage value, e.g. "Long 3x")
  4. Confirm the row has data-testid="perps-position-leverage" for automation

Screenshots/Recordings

Evidence available in task artifacts — will be added by reviewer if needed.

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

Low Risk
Low risk UI-only change that formats and renders position.leverage.value alongside direction; main risk is minor rendering/test brittleness if leverage is missing or formatting differs.

Overview
Perps position details now show leverage. The direction row in PerpsMarketDetailPage is updated to render Long/Short {leverage}x and adds data-testid="perps-position-leverage" for automation.

Tests updated to assert the leverage element renders and displays the expected combined label (e.g., Long 3x).

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

Add leverage row to the Details Section of PerpsMarketDetailPage.
The row was missing despite leverage data being available on the
Position object. Uses existing perpsLeverage i18n key and
position.leverage.value with data-testid for recipe validation.

Also adds perpsInjectPositions test hook to window.stateHooks
(gated by METAMASK_DEBUG/IN_TEST) for recipe-based E2E validation.
Matches mobile PerpsPositionCard pattern — "Long 3x" / "Short 3x" on
one row instead of separate Direction and Leverage rows.

Moves data-testid="perps-position-leverage" to the direction value text.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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.

@metamaskbotv2
Copy link
Copy Markdown
Contributor

metamaskbotv2 bot commented Apr 8, 2026

✨ Files requiring CODEOWNER review ✨

👨‍🔧 @MetaMask/perps (2 files, +17 -1)
  • 📁 ui/
    • 📁 pages/
      • 📁 perps/
        • 📄 perps-market-detail-page.test.tsx +14 -0
        • 📄 perps-market-detail-page.tsx +3 -1

@github-actions github-actions bot added the size-M label Apr 8, 2026
@abretonc7s abretonc7s marked this pull request as ready for review April 10, 2026 02:43
@abretonc7s abretonc7s requested a review from a team as a code owner April 10, 2026 02:43
Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

Reviewed by Cursor Bugbot for commit 2c89a39. Configure here.

@abretonc7s
Copy link
Copy Markdown
Contributor Author

Field Value
Run 3181689d
Duration
Model sonnet
Nudges 0
Grade ungraded
Cost $1.1935
Worker report

No report available.

Remove state-inspector.js and perpsInjectPositions hook that were
accidentally included. These are test infrastructure changes unrelated
to the leverage display fix.
…-display

# Conflicts:
#	ui/pages/perps/perps-market-detail-page.test.tsx
…etamask-extension into fix/tat-2796-leverage-display
@sonarqubecloud
Copy link
Copy Markdown

@metamaskbotv2
Copy link
Copy Markdown
Contributor

metamaskbotv2 bot commented Apr 10, 2026

Builds ready [52b21e2]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24236213540 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount
🟡 load_new_account
[Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • loadNewAccount/load_new_account: +19%
  • loadNewAccount/total: +19%
  • bridgeUserActions/bridge_load_asset_picker: -42%
  • bridgeUserActions/bridge_search_token: -25%
  • bridgeUserActions/total: -23%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.5s
  • 🟡 confirmTx/FCP: p75 2.4s
  • 🟡 bridgeUserActions/FCP: p75 2.5s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/uiStartup: -14%
  • startupStandardHome/load: -16%
  • startupStandardHome/domContentLoaded: -18%
  • startupStandardHome/firstReactRender: -13%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -21%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/domInteractive: -15%
  • startupPowerUserHome/backgroundConnect: +120%
  • startupPowerUserHome/numNetworkReqs: -48%
  • startupStandardHome/uiStartup: -13%
  • startupStandardHome/load: -12%
  • startupStandardHome/domContentLoaded: -12%
  • startupStandardHome/backgroundConnect: -30%
  • startupStandardHome/firstReactRender: -24%
  • startupStandardHome/loadScripts: -12%
  • startupStandardHome/setupStore: -14%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -24%
  • startupPowerUserHome/numNetworkReqs: +42%
  • startupStandardHome/domInteractive: -59%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/numNetworkReqs: -16%
  • startupPowerUserHome/backgroundConnect: -20%
  • startupPowerUserHome/setupStore: +51%
  • startupStandardHome/domInteractive: -32%
  • startupStandardHome/backgroundConnect: -12%
  • startupStandardHome/initialActions: -44%
  • startupStandardHome/setupStore: -60%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/backgroundConnect: -37%
  • startupPowerUserHome/setupStore: -25%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 720ms
  • 🔴 startupPowerUserHome/INP: p75 672ms
  • 🟡 startupPowerUserHome/LCP: p75 3.9s
  • 🟡 startupPowerUserHome/LCP: p75 3.7s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -87%
  • onboardingImportWallet/confirmSrpToPwForm: -22%
  • onboardingImportWallet/pwFormToMetricsScreen: -25%
  • onboardingImportWallet/metricsToWalletReadyScreen: -47%
  • onboardingImportWallet/doneButtonToHomeScreen: -80%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +21%
  • onboardingImportWallet/total: -47%
  • onboardingNewWallet/srpButtonToPwForm: -77%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/doneButtonToAssetList: -27%
  • onboardingNewWallet/total: -28%
  • assetDetails/assetClickToPriceChart: -43%
  • assetDetails/total: -43%
  • solanaAssetDetails/assetClickToPriceChart: -70%
  • solanaAssetDetails/total: -70%
  • importSrpHome/openAccountMenuAfterLogin: -65%
  • importSrpHome/homeAfterImportWithNewWallet: -69%
  • importSrpHome/total: -60%
  • sendTransactions/selectTokenToSendFormLoaded: -26%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -96%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 224ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 224ms
  • 🟡 importSrpHome/FCP: p75 2.6s
  • 🟡 sendTransactions/INP: p75 232ms
  • 🟡 sendTransactions/FCP: p75 2.5s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: 71 Bytes (0%)
  • common: 20 Bytes (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants