chore(runway): cherry-pick fix(perps): sync pending payment token and reset on asset change cp-7.72.0#28252
Merged
Conversation
… reset on asset change cp-7.72.0 (#28086) ## **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** ```gherkin 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** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!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. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ed6e439. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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. |
Contributor
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - skip-smart-e2e-selection label found All E2E tests pre-selected. |
|
Contributor
|
✅ E2E Fixture Validation — Schema is up to date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
Screenshots/Recordings
N/A — no UI changes, logic-only fix in payment token sync.
Before
N/A
After
N/A
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
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
initialAssetby clearingPerpsController.setSelectedPaymentTokenon asset change and ensuring pending token config is re-applied for
the new asset.
Adjusts pending-config sync so it can apply even when
selectedPaymentTokenisnull, and only re-syncs when either thepayTokenor 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.