Skip to content

fix: balance double counting pnl#41796

Merged
gambinish merged 5 commits into
mainfrom
perps/fix/balance-inconsistency-pnl
Apr 16, 2026
Merged

fix: balance double counting pnl#41796
gambinish merged 5 commits into
mainfrom
perps/fix/balance-inconsistency-pnl

Conversation

@gambinish

@gambinish gambinish commented Apr 15, 2026

Copy link
Copy Markdown
Member

Description

Fixes issue where PnL was being double counted in total balance

Changelog

CHANGELOG entry: fix perps total balance miscalculation

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

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
Changes user-visible balance math in the perps UI and could misrepresent funds if the upstream totalBalance semantics differ; scope is limited to display logic with added test coverage.

Overview
Fixes perps UI balance calculations by stopping the addition of unrealizedPnl onto totalBalance, aligning both PerpsBalanceDropdown and PerpsMarketBalanceActions with the updated meaning of totalBalance.

PerpsBalanceDropdown now renders PerpsControlBarSkeleton while usePerpsLiveAccount reports isInitialLoading, and tests were updated to mock the hook, assert the corrected formatted total, and cover the loading state.

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

@metamaskbotv2

metamaskbotv2 Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

✨ Files requiring CODEOWNER review ✨

👨‍🔧 @MetaMask/perps (3 files, +33 -10)
  • 📁 ui/
    • 📁 components/
      • 📁 app/
        • 📁 perps/
          • 📁 perps-balance-dropdown/
            • 📄 perps-balance-dropdown.test.tsx +23 -5
            • 📄 perps-balance-dropdown.tsx +8 -2
          • 📁 perps-market-balance-actions/
            • 📄 perps-market-balance-actions.tsx +2 -3

@metamaskbotv2

metamaskbotv2 Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
Builds ready [aea5412]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): 71bd826 | Date: 10/14/58243 | Pipeline: 24475909771 | Baseline logs

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

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_load_asset_picker: -28%
  • bridgeUserActions/bridge_search_token: +40%
  • bridgeUserActions/total: +18%

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

  • 🟡 loadNewAccount/FCP: p75 2.5s
  • 🟡 confirmTx/FCP: p75 2.5s
  • 🟡 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: -20%
  • startupStandardHome/domContentLoaded: -10%
  • startupStandardHome/domInteractive: +13%
  • startupStandardHome/backgroundConnect: +17%
  • startupStandardHome/initialActions: -33%
  • startupStandardHome/loadScripts: -14%
  • startupStandardHome/setupStore: +14%
  • startupPowerUserHome/uiStartup: -27%
  • startupPowerUserHome/backgroundConnect: +90%
  • startupPowerUserHome/numNetworkReqs: +20%
  • startupStandardHome/uiStartup: -19%
  • startupStandardHome/load: -14%
  • startupStandardHome/domContentLoaded: -13%
  • startupStandardHome/firstPaint: +32%
  • startupStandardHome/backgroundConnect: -32%
  • startupStandardHome/firstReactRender: -30%
  • startupStandardHome/loadScripts: -14%
  • startupStandardHome/setupStore: -13%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/uiStartup: -25%
  • startupPowerUserHome/domInteractive: -10%
  • startupPowerUserHome/numNetworkReqs: +32%
  • startupStandardHome/domInteractive: -36%
  • startupStandardHome/backgroundConnect: +19%
  • startupStandardHome/initialActions: +33%
  • startupStandardHome/numNetworkReqs: -16%
  • startupPowerUserHome/uiStartup: -32%
  • startupPowerUserHome/backgroundConnect: -30%
  • startupPowerUserHome/setupStore: +24%
  • startupStandardHome/domInteractive: -16%
  • startupStandardHome/initialActions: +14%
  • startupStandardHome/setupStore: -54%
  • startupPowerUserHome/uiStartup: -27%
  • startupPowerUserHome/backgroundConnect: -21%
  • startupPowerUserHome/numNetworkReqs: -11%

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

  • 🔴 startupPowerUserHome/INP: p75 736ms
  • 🔴 startupPowerUserHome/INP: p75 800ms
  • 🟡 startupPowerUserHome/LCP: p75 3.6s
  • 🟡 startupPowerUserHome/INP: p75 208ms
  • 🟡 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: -85%
  • onboardingImportWallet/metricsToWalletReadyScreen: -34%
  • onboardingImportWallet/doneButtonToHomeScreen: -76%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +26%
  • onboardingImportWallet/total: -44%
  • onboardingNewWallet/srpButtonToPwForm: -75%
  • onboardingNewWallet/createPwToRecoveryScreen: +12%
  • onboardingNewWallet/skipBackupToMetricsScreen: -66%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: +18%
  • onboardingNewWallet/doneButtonToAssetList: -32%
  • onboardingNewWallet/total: -31%
  • assetDetails/assetClickToPriceChart: -31%
  • assetDetails/total: -31%
  • solanaAssetDetails/assetClickToPriceChart: -65%
  • solanaAssetDetails/total: -65%
  • importSrpHome/openAccountMenuAfterLogin: -68%
  • importSrpHome/homeAfterImportWithNewWallet: -71%
  • importSrpHome/total: -62%
  • sendTransactions/openSendPageFromHome: -26%
  • sendTransactions/selectTokenToSendFormLoaded: -25%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -97%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +10%

🌐 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 232ms
  • 🟡 importSrpHome/FCP: p75 2.5s
  • 🟡 sendTransactions/INP: p75 208ms
  • 🟡 sendTransactions/FCP: p75 2.4s
  • 🟡 swap/FCP: p75 2.4s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: -1 Bytes (0%)
  • common: 229 Bytes (0%)

@gambinish gambinish marked this pull request as ready for review April 15, 2026 21:09
@gambinish gambinish requested a review from a team as a code owner April 15, 2026 21:09

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 a0351ea. Configure here.

@metamaskbotv2

metamaskbotv2 Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
Builds ready [bafc9b3]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): 71bd826 | Date: 10/14/58243 | Pipeline: 24480507275 | Baseline logs

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

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_load_asset_picker: -11%

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

  • 🟡 loadNewAccount/FCP: p75 2.5s
  • 🟡 confirmTx/FCP: p75 2.5s
  • 🟡 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: -19%
  • startupStandardHome/domInteractive: +17%
  • startupStandardHome/backgroundConnect: +16%
  • startupStandardHome/firstReactRender: -10%
  • startupStandardHome/initialActions: -33%
  • startupStandardHome/loadScripts: -14%
  • startupPowerUserHome/uiStartup: -26%
  • startupPowerUserHome/backgroundConnect: +62%
  • startupPowerUserHome/setupStore: +21%
  • startupPowerUserHome/numNetworkReqs: -51%
  • startupStandardHome/uiStartup: -20%
  • startupStandardHome/load: -15%
  • startupStandardHome/domContentLoaded: -15%
  • startupStandardHome/backgroundConnect: -33%
  • startupStandardHome/firstReactRender: -23%
  • startupStandardHome/loadScripts: -15%
  • startupStandardHome/setupStore: -13%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/uiStartup: -28%
  • startupPowerUserHome/domInteractive: -22%
  • startupPowerUserHome/numNetworkReqs: -42%
  • startupStandardHome/domInteractive: -19%
  • startupStandardHome/backgroundConnect: +26%
  • startupStandardHome/initialActions: -33%
  • startupStandardHome/numNetworkReqs: -16%
  • startupPowerUserHome/uiStartup: -33%
  • startupPowerUserHome/backgroundConnect: -29%
  • startupPowerUserHome/firstReactRender: -15%
  • startupPowerUserHome/setupStore: -15%
  • startupPowerUserHome/numNetworkReqs: -10%
  • startupStandardHome/uiStartup: -15%
  • startupStandardHome/domInteractive: -32%
  • startupStandardHome/backgroundConnect: -11%
  • startupStandardHome/firstReactRender: -12%
  • startupStandardHome/initialActions: -43%
  • startupStandardHome/setupStore: -64%
  • startupPowerUserHome/uiStartup: -27%
  • startupPowerUserHome/backgroundConnect: -13%
  • startupPowerUserHome/setupStore: -17%
  • startupPowerUserHome/numNetworkReqs: -20%

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

  • 🔴 startupPowerUserHome/INP: p75 808ms
  • 🔴 startupPowerUserHome/INP: p75 728ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/INP: p75 272ms
  • 🟡 startupPowerUserHome/LCP: p75 3.9s
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: -85%
  • onboardingImportWallet/metricsToWalletReadyScreen: -47%
  • onboardingImportWallet/doneButtonToHomeScreen: -76%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +18%
  • onboardingImportWallet/total: -44%
  • onboardingNewWallet/srpButtonToPwForm: -79%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/doneButtonToAssetList: -23%
  • onboardingNewWallet/total: -25%
  • assetDetails/assetClickToPriceChart: -27%
  • assetDetails/total: -27%
  • solanaAssetDetails/assetClickToPriceChart: -64%
  • solanaAssetDetails/total: -64%
  • importSrpHome/openAccountMenuAfterLogin: -61%
  • importSrpHome/homeAfterImportWithNewWallet: -71%
  • importSrpHome/total: -61%
  • sendTransactions/openSendPageFromHome: -25%
  • sendTransactions/selectTokenToSendFormLoaded: -28%
  • sendTransactions/reviewTransactionToConfirmationPage: +35%
  • sendTransactions/total: +32%
  • swap/openSwapPageFromHome: -97%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

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

  • 🟡 assetDetails/INP: p75 208ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 240ms
  • 🟡 importSrpHome/FCP: p75 2.6s
  • 🟡 sendTransactions/INP: p75 240ms
  • 🟡 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: 330 Bytes (0%)
  • common: 229 Bytes (0%)

@abretonc7s

Copy link
Copy Markdown
Contributor

Automated Review — PR #41796

BETA — Automated review from the farmslot pipeline.

Recommendation APPROVE
Runner unknown / unknown
Tier standard
Cost N/A (N/A tokens)
Recipe N/A

Summary

The PR correctly fixes a double-counting bug where unrealizedPnl was being added to totalBalance to compute accountValue, but totalBalance (from Hyperliquid's API) already includes unrealized PnL. The fix removes the + unrealizedPnl in both PerpsBalanceDropdown and PerpsMarketBalanceActions, and adds a loading skeleton guard in PerpsBalanceDropdown for the isInitialLoading state. This aligns with how mobile handles the same value.

Full review details

Recipe Coverage

# AC (verbatim) Target env Recipe nodes (IDs) Screenshot filename Visual verdict Justification
1 "PnL should not be double-counted in total balance display in PerpsBalanceDropdown" fullscreen ac1-wait-balance-dropdown, ac1-eval-balance-state, ac1-screenshot-balance-dropdown evidence-ac1-perps-balance-dropdown.png PROVEN Screenshot shows Total balance: $11,246.78 matching totalBalance (11246.784) from eval_ref. Unrealized P&L (+$0.07) shown separately. If double-counted, total would be ~$11,246.85.
2 "PnL should not be double-counted in PerpsMarketBalanceActions" fullscreen (none) (none) UNTESTABLE Component not imported by any page — not rendered in any live route. Code change identical to AC1.
3 "PerpsBalanceDropdown shows loading skeleton during isInitialLoading" fullscreen (none) (none) UNTESTABLE Transient hook state, cannot be triggered via CDP. Covered by unit test.

Overall recipe coverage: 1/3 ACs PROVEN
Untestable: AC2 (component not rendered in live routes), AC3 (transient hook state)

Coverage escalation: AC2, AC3 not proven in browser.
Reason: AC2's component is not mounted in any live route (code review confirms identical fix to AC1). AC3 is a transient React state testable only via unit tests (which pass).
Human reviewer must validate manually before merging.

Prior Reviews

Reviewer State Date Addressed? Notes
cursor COMMENTED 2026-04-15 N/A Automated Bugbot review
gambinish COMMENTED 2026-04-15 N/A Comment only, no changes requested

No CHANGES_REQUESTED reviews.

Acceptance Criteria Validation

# Criterion Status Evidence
1 Balance not double-counted in PerpsBalanceDropdown PASS Recipe ac1-eval-balance-state: totalBalance=11246.78, displayed as $11,246.78 (not $11,246.85). Screenshot evidence.
2 Balance not double-counted in PerpsMarketBalanceActions PASS (code review) Identical fix to AC1. Component not in any live route. Unit tests pass.
3 Loading skeleton during isInitialLoading PASS (unit test) New test "renders loading skeleton when account data is still loading" passes.

Code Quality

  • Pattern adherence: Follows existing codebase conventions. Uses formatCurrencyWithMinThreshold (per perps formatting rules).
  • Complexity: Appropriate — removes unnecessary computation.
  • Type safety: No type issues. Correctly destructures isInitialLoading from hook return.
  • Error handling: Adequate — defaults to '0' via nullish coalescing.
  • Anti-pattern findings: None. No import boundary violations, no missing LavaMoat updates, no new UI without testIDs.

Fix Quality

  • Best approach: Yes. This is the minimal correct fix. totalBalance from Hyperliquid is accountValue (perps equity + spot), which already includes unrealized PnL. Mobile uses totalBalance directly (confirmed in PerpsHomeView.tsx:129). The old code was simply wrong.
  • Would not ship: Nothing blocks merge.
  • Test quality: Good. The balance dropdown test asserts $15,250.00 (correct) vs old $15,625.00 (double-counted). The loading skeleton test checks both positive (skeleton visible) and negative (balance NOT visible) conditions. One gap: perps-market-balance-actions.test.tsx doesn't assert the displayed balance amount — but since the component isn't rendered in any live route, this is low risk.
  • Brittleness: Low. Simple parseFloat(totalBalance) with no intermediate state, caching, or module-level constants.

Live Validation

  • Recipe: generated
  • Result: PASS — 4/4 nodes passed in 1358ms
  • Evidence: 1 screenshot (evidence-ac1-perps-balance-dropdown.png) + baseline.png
  • Webpack errors: none
  • Log monitoring: Webpack serving PR code, builds completed successfully

Correctness

  • Diff vs stated goal: Aligned — removes double-counting of PnL in balance display
  • Edge cases: When account is null, defaults to '0' (existing behavior preserved). The isInitialLoading guard returns skeleton before accessing account data.
  • Race conditions: None — usePerpsLiveAccount handles loading state internally
  • Backward compatibility: Preserved — no API or prop changes

Static Analysis

  • lint:tsc: PASS (2 pre-existing warnings in unrelated files)
  • Tests: 19/19 pass (15 balance-dropdown + 4 market-balance-actions)

Mobile Comparison

  • Status: ALIGNED
  • Details: Mobile's PerpsHomeView.tsx:129 uses totalBalance directly without adding unrealizedPnl, exactly matching this fix. No formatting divergence — both use their respective currency formatters on the raw totalBalance.

Architecture & Domain

  • No MV3 implications — pure UI component changes
  • No LavaMoat impact — no new dependencies
  • Import boundaries respected — PerpsControlBarSkeleton imported from sibling perps-skeletons package
  • No controller state changes requiring migrations

Risk Assessment

  • LOW — Removes an incorrect computation. The fix is a strict subtraction of behavior (removing the + unrealizedPnl addition). Aligns with mobile. Well-tested.

Recommended Action

APPROVE
Clean, correct fix that aligns extension balance display with mobile and the Hyperliquid API semantics. The loading skeleton addition is a sensible defensive improvement.

Line comments (1 comments: 1 suggestion)
  • [suggestion] ui/components/app/perps/perps-market-balance-actions/perps-market-balance-actions.tsx:66: Suggestion: The existing test file for this component (perps-market-balance-actions.test.tsx) doesn't assert on the displayed balance amount. Consider adding a test similar to the dropdown's displays the formatted total balance from mock data test to guard against future regressions in this component's balance calculation.
Recipe (N/A)
{
  "title": "Verify fix: balance not double-counting PnL",
  "validate": {
    "workflow": {
      "pre_conditions": ["wallet.unlocked", "perps.feature_enabled"],
      "entry": "setup-navigate-perps",
      "nodes": {
        "setup-navigate-perps": {
          "action": "call",
          "ref": "perps/navigate-perps-tab",
          "next": "ac1-wait-balance-dropdown"
        },
        "ac1-wait-balance-dropdown": {
          "action": "wait_for",
          "test_id": "perps-balance-dropdown",
          "timeout_ms": 10000,
          "next": "ac1-eval-balance-state"
        },
        "ac1-eval-balance-state": {
          "action": "eval_ref",
          "ref": "perps-balance",
          "save_as": "account_state",
          "assert": {
            "operator": "not_null",
            "field": "totalBalance"
          },
          "next": "ac1-screenshot-balance-dropdown"
        },
        "ac1-screenshot-balance-dropdown": {
          "action": "screenshot",
          "filename": "evidence-ac1-perps-balance-dropdown.png",
          "next": "done"
        },
        "done": {
          "action": "end",
          "status": "pass",
          "message": "AC1: Balance dropdown displays totalBalance directly (no double-counting PnL). AC2: UNTESTABLE — PerpsMarketBalanceActions not rendered in any live route, code review only. AC3: UNTESTABLE — loading skeleton is transient hook state, covered by unit tests."
        }
      }
    }
  }
}

No video evidence recorded.

@abretonc7s abretonc7s 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.

Automated review — see comment above for full details.

// Account value = totalBalance + unrealizedPnl (includes open position PnL)
const accountValue = parseFloat(totalBalance) + parseFloat(unrealizedPnl);
// totalBalance is HL accountValue (perps equity, already includes unrealizedPnl) + spot
const accountValue = parseFloat(totalBalance);

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.

suggestion — Suggestion: The existing test file for this component (perps-market-balance-actions.test.tsx) doesn't assert on the displayed balance amount. Consider adding a test similar to the dropdown's displays the formatted total balance from mock data test to guard against future regressions in this component's balance calculation.

@abretonc7s

Copy link
Copy Markdown
Contributor

Visual Evidence

Evidence/baseline

Evidence/baseline

Evidence/evidence Ac1 Perps Balance Dropdown

Evidence/evidence Ac1 Perps Balance Dropdown

@sonarqubecloud

Copy link
Copy Markdown

@geositta geositta 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.

The balance/PnL correction looks right and aligns with mobile/Core: totalBalance is already the account value, so removing the extra + unrealizedPnl fixes the inconsistency without changing the intended data model.

The reconnect and healthcheck additions look reasonable for the current architecture, and the focused tests plus circular dependency check are green.

@gambinish gambinish added this pull request to the merge queue Apr 16, 2026
@metamaskbotv2

metamaskbotv2 Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor
Builds ready [5ecb63c]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): 71bd826 | Date: 10/14/58243 | Pipeline: 24485864820 | Baseline logs

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

📈 Results compared to the previous 5 runs on main

  • loadNewAccount/load_new_account: -58%
  • loadNewAccount/total: -58%
  • bridgeUserActions/bridge_load_page: -32%
  • bridgeUserActions/bridge_load_asset_picker: -67%
  • bridgeUserActions/bridge_search_token: -11%
  • bridgeUserActions/total: -26%

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

  • 🟡 loadNewAccount/FCP: p75 1.9s
  • 🟡 confirmTx/FCP: p75 1.9s
  • 🟡 bridgeUserActions/FCP: p75 1.9s
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: -22%
  • startupStandardHome/load: -11%
  • startupStandardHome/domContentLoaded: -13%
  • startupStandardHome/backgroundConnect: +12%
  • startupStandardHome/firstReactRender: -10%
  • startupStandardHome/initialActions: -33%
  • startupStandardHome/loadScripts: -16%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/uiStartup: -26%
  • startupPowerUserHome/domInteractive: -15%
  • startupPowerUserHome/backgroundConnect: +79%
  • startupPowerUserHome/firstReactRender: -11%
  • startupPowerUserHome/numNetworkReqs: +13%
  • startupStandardHome/uiStartup: -20%
  • startupStandardHome/load: -15%
  • startupStandardHome/domContentLoaded: -14%
  • startupStandardHome/firstPaint: +15%
  • startupStandardHome/backgroundConnect: -33%
  • startupStandardHome/firstReactRender: -23%
  • startupStandardHome/loadScripts: -14%
  • startupStandardHome/setupStore: -13%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/uiStartup: -28%
  • startupPowerUserHome/domInteractive: -21%
  • startupPowerUserHome/firstPaint: -12%
  • startupPowerUserHome/numNetworkReqs: +22%
  • startupStandardHome/uiStartup: -13%
  • startupStandardHome/domInteractive: -56%
  • startupStandardHome/initialActions: +33%
  • startupPowerUserHome/uiStartup: -33%
  • startupPowerUserHome/backgroundConnect: -34%
  • startupStandardHome/uiStartup: -11%
  • startupStandardHome/domInteractive: -37%
  • startupStandardHome/initialActions: -43%
  • startupStandardHome/setupStore: -54%
  • startupPowerUserHome/uiStartup: -25%
  • startupPowerUserHome/backgroundConnect: -32%
  • startupPowerUserHome/setupStore: +25%
  • startupPowerUserHome/numNetworkReqs: -11%

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

  • 🔴 startupPowerUserHome/INP: p75 680ms
  • 🔴 startupPowerUserHome/INP: p75 672ms
  • 🟡 startupPowerUserHome/LCP: p75 3.6s
  • 🟡 startupPowerUserHome/INP: p75 208ms
  • 🟡 startupPowerUserHome/LCP: p75 3.8s
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: -83%
  • onboardingImportWallet/metricsToWalletReadyScreen: -21%
  • onboardingImportWallet/doneButtonToHomeScreen: -79%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +27%
  • onboardingImportWallet/total: -45%
  • onboardingNewWallet/srpButtonToPwForm: -78%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -27%
  • onboardingNewWallet/doneButtonToAssetList: -22%
  • onboardingNewWallet/total: -25%
  • assetDetails/assetClickToPriceChart: -54%
  • assetDetails/total: -54%
  • solanaAssetDetails/assetClickToPriceChart: -74%
  • solanaAssetDetails/total: -74%
  • importSrpHome/openAccountMenuAfterLogin: -76%
  • importSrpHome/homeAfterImportWithNewWallet: -69%
  • importSrpHome/total: -60%
  • sendTransactions/openSendPageFromHome: -22%
  • sendTransactions/selectTokenToSendFormLoaded: -28%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -97%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

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

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

Merged via the queue into main with commit 3b7cf0d Apr 16, 2026
210 checks passed
@gambinish gambinish deleted the perps/fix/balance-inconsistency-pnl branch April 16, 2026 01:20
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
@metamaskbot metamaskbot added the release-13.28.0 Issue or pull request that will be included in release 13.28.0 label Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.28.0 Issue or pull request that will be included in release 13.28.0 size-S team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants