Commit 905777f
chore(runway): cherry-pick fix(perps): prevent payment token reverting when switching in Pay With modal cp-7.66.0 (#26130)
- fix(perps): prevent payment token reverting when switching in Pay With
modal cp-7.66.0 (#26120)
## **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**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
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**
```gherkin
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**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
https://github.com/user-attachments/assets/f0d32725-e490-4379-a890-cec76f1691d6
## **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 order payment-token sync logic that drives transaction
parameters; regression could cause incorrect token selection, but change
is scoped and covered by new unit tests.
>
> **Overview**
> Prevents the Perps order view from re-applying the *pending trade
configuration* payment token on subsequent renders, which previously
could revert a user’s in-session selection after using the Pay With
modal.
>
> `PerpsPayRow` now tracks the last pending token applied via a
`useRef`, only syncing it once per load and resetting when
`initialAsset` changes; it also ensures `setSelectedPaymentToken(null)`
is only dispatched once when no pending token exists. Tests were
expanded to cover “apply once”, asset-switch re-apply, and
no-repeat-null behavior.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
090eb88. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Co-authored-by: Cursor <cursoragent@cursor.com>
[6c5d77a](6c5d77a)
Co-authored-by: Michal Szorad <michal.szorad@consensys.net>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 6eacf8d commit 905777f
2 files changed
Lines changed: 186 additions & 17 deletions
Lines changed: 148 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
303 | 450 | | |
Lines changed: 38 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
132 | 153 | | |
133 | 154 | | |
134 | | - | |
135 | | - | |
| 155 | + | |
| 156 | + | |
136 | 157 | | |
137 | 158 | | |
138 | | - | |
139 | | - | |
| 159 | + | |
| 160 | + | |
140 | 161 | | |
141 | | - | |
142 | 162 | | |
143 | 163 | | |
144 | | - | |
145 | | - | |
| 164 | + | |
| 165 | + | |
146 | 166 | | |
147 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
148 | 172 | | |
149 | 173 | | |
150 | 174 | | |
151 | 175 | | |
152 | | - | |
153 | | - | |
154 | 176 | | |
155 | 177 | | |
156 | 178 | | |
| |||
0 commit comments