Skip to content

fix(perps): sync pending payment token and reset on asset change cp-7.72.0#28086

Merged
aganglada merged 3 commits into
mainfrom
fix/perps/pending-config-restore
Apr 1, 2026
Merged

fix(perps): sync pending payment token and reset on asset change cp-7.72.0#28086
aganglada merged 3 commits into
mainfrom
fix/perps/pending-config-restore

Conversation

@michalconsensys

@michalconsensys michalconsensys commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Description

When switching between perps assets (e.g. from BTC to ETH), the "Pay with" token selection could get out of sync — the pending config from the previous asset would either not be restored or would conflict with the newly selected asset's payment token.

Changelog

CHANGELOG entry: Fixed payment token not restoring correctly when switching between perps assets

Related issues

Fixes jira issue: https://consensyssoftware.atlassian.net/browse/TAT-2785

Manual testing steps

Feature: Perps pay-with token persistence across asset switches

  Scenario: User switches perps asset and pending pay token is restored
    Given the user has a pending pay-with token config saved for ETH perps
    And the user is currently viewing BTC perps order view

    When the user switches to ETH perps
    Then the pay-with token row displays the previously saved payment token for ETH

  Scenario: User switches asset and controller state is reset
    Given the user is viewing BTC perps with a selected payment token

    When the user switches to ETH perps
    Then the controller's selectedPaymentToken is reset to null
    And the new asset's pending config (if any) is applied

  Scenario: User opens perps with no prior selectedPaymentToken in controller
    Given the user has a pending pay-with config but no selectedPaymentToken in the controller

    When the user opens the perps order view
    Then the pending config is applied and the correct pay token is displayed

Screenshots/Recordings

N/A — no UI changes, logic-only fix in payment token sync.

Before

N/A

After

N/A

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
Touches perps payment-token synchronization logic and controller state resets, which can affect what token a user trades with across asset switches. Changes are localized and covered by new unit tests, but regressions could impact user transaction configuration.

Overview
Fixes perps “Pay with” token desynchronization when switching initialAsset by clearing PerpsController.setSelectedPaymentToken on asset change and ensuring pending token config is re-applied for the new asset.

Adjusts pending-config sync so it can apply even when selectedPaymentToken is null, and only re-syncs when either the payToken or controller-selected token differs from the pending token (avoiding unnecessary overwrites). Adds targeted tests covering asset-change cleanup and the new sync edge cases.

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

Move appliedPendingTokenRef assignment before state updates to prevent
stale ref reads. Add cleanup effect to reset selectedPaymentToken when
initialAsset changes. Broaden sync guard to also reconcile
selectedPaymentToken with pending config.
@michalconsensys michalconsensys self-assigned this Mar 30, 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-perps Perps team label Mar 30, 2026
@github-actions github-actions Bot added size-M and removed size-S labels Mar 30, 2026
@michalconsensys michalconsensys marked this pull request as ready for review March 30, 2026 11:51
@michalconsensys michalconsensys requested a review from a team as a code owner March 30, 2026 11:51

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

Automation status: blocked for DSYS-616 migration-docs workflow.

This run is in MetaMask/metamask-mobile on branch cursor/mmds-component-migration-docs-8efb, but the requested task targets MetaMask/metamask-design-system.

Required docs targets are not present in this workspace:

  • packages/design-system-react/MIGRATION.md
  • packages/design-system-react-native/MIGRATION.md
  • packages/design-system-react/src/components/{ComponentName}/README.mdx
  • packages/design-system-react-native/src/components/{ComponentName}/README.md

Additionally, the required Atlassian/Jira MCP integration is unavailable in this run (atlassian MCP server not found), so the DSYS-616 story/component cannot be sourced from Jira.

Per the audit/quality gate, the run is stopped without code changes, lint, or PR updates.

Please re-run this automation in MetaMask/metamask-design-system with Atlassian MCP configured.

Open in Web View Automation 

Sent by Cursor Automation: DSYS-616: MMDS - Create/Update migration docs

Comment thread app/components/UI/Perps/Views/PerpsOrderView/PerpsPayRow.tsx Outdated
…le sync

Move the ref assignment before the if-block so pending config is marked
as handled even when payToken/selectedPaymentToken already match. This
prevents the sync effect from re-firing and overwriting a user's manual
token selection on subsequent re-renders.

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

Comment thread app/components/UI/Perps/Views/PerpsOrderView/PerpsPayRow.tsx
@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Mar 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are isolated to PerpsPayRow.tsx and its test file. The component handles payment token selection in the Perps order flow. Key changes: (1) race condition fix - appliedPendingTokenRef is now set before setPayToken calls, (2) new cleanup useEffect that resets PerpsController.setSelectedPaymentToken(null) when initialAsset changes to prevent stale token state, (3) pending config sync now applies even when selectedPaymentToken is null, (4) added selectedPaymentToken address/chainId check to sync condition. These are bug fixes in the Perps Add Funds payment token selection flow. The component is only imported by PerpsOrderView.tsx, so impact is contained to Perps. SmokePerps is the primary tag. Per SmokePerps description, SmokeWalletPlatform (Trending section) and SmokeConfirmations (Add Funds deposits are on-chain transactions) must also be selected.

Performance Test Selection:
No performance impact. Changes are bug fixes in token selection logic (ref ordering, null checks, cleanup effect). No rendering performance, list rendering, or data loading changes that would affect measurable performance metrics.

View GitHub Actions results

@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

@michalconsensys michalconsensys changed the title fix(perps): sync pending payment token and reset on asset change fix(perps): sync pending payment token and reset on asset change cp-7.72.0 Apr 1, 2026
@michalconsensys michalconsensys added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@aganglada aganglada added this pull request to the merge queue Apr 1, 2026
@aganglada aganglada removed this pull request from the merge queue due to a manual request Apr 1, 2026
@aganglada aganglada added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 596bf1e Apr 1, 2026
187 of 189 checks passed
@aganglada aganglada deleted the fix/perps/pending-config-restore branch April 1, 2026 10:32
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 1, 2026
@weitingsun weitingsun added release-7.73.0 Issue or pull request that will be included in release 7.73.0 and removed release-101.2.0 labels Apr 1, 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-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants