Skip to content

fix(perps): prevent payment token reverting when switching in Pay With modal cp-7.66.0#26120

Merged
michalconsensys merged 1 commit intomainfrom
fix/perps/pending-config
Feb 16, 2026
Merged

fix(perps): prevent payment token reverting when switching in Pay With modal cp-7.66.0#26120
michalconsensys merged 1 commit intomainfrom
fix/perps/pending-config

Conversation

@michalconsensys
Copy link
Contributor

@michalconsensys michalconsensys commented Feb 16, 2026

Description

When opening the Perps order view, the component syncs the transaction "pay token" from pending config (e.g. last selected payment token). The previous logic re-ran this sync on every effect run, so if the user changed the token in the "Pay With" modal, a later effect could overwrite their choice with the pending token again.

Changes:

  • Pending config is now applied once per load (or when initialAsset changes). A ref tracks which pending token was already applied so we don’t overwrite the user’s in-session token selection.
  • When initialAsset changes (e.g. user switches from BTC to ETH), the "applied" state is reset so pending config is re-applied for the new asset.
  • When pending config has no selected token, setSelectedPaymentToken(null) is only called once, not on every effect run.

This keeps the intended "restore from pending config" behavior on first load and on asset change, without undoing the user’s token choice when they’ve already changed it in the same session.

Changelog

CHANGELOG entry: Fixed Perps order view reverting the user’s payment token selection to the pending config after they had changed it in the Pay With modal.

Related issues

Jira issue: https://consensyssoftware.atlassian.net/browse/TAT-2572
Fixes: #26118

Manual testing steps

Feature: Perps order view pay token and pending config
  Scenario: user changes payment token and it is not overwritten by pending config
    Given user is on Perps order view with a pending payment token (e.g. USDC)
    And pay token is initially synced from pending config
    When user opens Pay With modal and selects a different token (e.g. DAI)
    Then the selected token remains DAI and is not reverted to the pending token (USDC)

  Scenario: pending config is re-applied when switching asset
    Given user is on Perps order view for asset BTC with pending token A
    And pay token was synced to token A
    When user switches to asset ETH (e.g. different market) and pending config has token B for ETH
    Then pay token is synced to token B for the new asset

Screenshots/Recordings

Before

After

Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-02-16.at.14.10.35.mov

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
Small, localized state-sync change in a UI component with added unit tests; main risk is subtle regressions in when pending config is re-applied across rerenders/assets.

Overview
Fixes a Perps order flow bug where the pending trade configuration could repeatedly re-sync and revert the user’s payment token after they changed it in the Pay With modal.

PerpsPayRow now tracks (via refs) whether a pending payment token (or explicit null) has already been applied, only applying it once per view load and resetting that applied state when initialAsset changes so the correct pending token is re-applied per market. Tests were expanded to cover the “apply once”, “don’t overwrite after user switch”, “re-apply on asset change”, and “don’t re-null repeatedly” behaviors.

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

…h modal

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
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 Feb 16, 2026
@michalconsensys michalconsensys marked this pull request as ready for review February 16, 2026 13:11
@michalconsensys michalconsensys requested a review from a team as a code owner February 16, 2026 13:11
@michalconsensys michalconsensys changed the title fix(perps): prevent payment token reverting when switching in Pay With modal fix(perps): prevent payment token reverting when switching in Pay With modal cp-7.66.0 Feb 16, 2026
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The PR modifies the PerpsPayRow component which is part of the Perps order flow. The changes introduce ref-based tracking to prevent overwriting user's in-session token selection when switching tokens in the Pay With modal. This is a bug fix that affects the payment token selection UX in the Perps feature.

Key changes:

  1. Added useRef hooks to track applied pending config state
  2. Modified useEffect hooks to only apply pending config on initial load or when switching asset
  3. Added comprehensive unit tests for the new behavior

The changes are contained within the Perps feature area and interact with PerpsController. Following the tag description guidance:

  • SmokePerps: Direct impact on Perps functionality (payment token selection in order flow)
  • SmokeWalletPlatform: Required as Perps is a section inside the Trending tab
  • SmokeConfirmations: Required as Add Funds deposits are on-chain transactions

This is a medium risk change because it modifies state management logic in a financial feature, but the changes are well-scoped and include comprehensive test coverage.

Performance Test Selection:
The changes modify React hooks and refs for state management in the PerpsPayRow component. While the changes are primarily bug fixes for UX behavior, they do affect the rendering logic and state updates in the Perps order flow. The @PerformancePreps tag covers perps market loading, position management, and add funds flow, which aligns with the affected component. Running this performance test will help ensure the ref-based tracking doesn't introduce any rendering performance regressions.

View GitHub Actions results

@sonarqubecloud
Copy link

@michalconsensys michalconsensys added this pull request to the merge queue Feb 16, 2026
Merged via the queue into main with commit 6c5d77a Feb 16, 2026
121 checks passed
@michalconsensys michalconsensys deleted the fix/perps/pending-config branch February 16, 2026 14:51
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2026
@metamaskbot metamaskbot added the release-7.67.0 Issue or pull request that will be included in release 7.67.0 label Feb 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.67.0 Issue or pull request that will be included in release 7.67.0 size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix UI issue when switching payment tokens

3 participants