Commit d7ffcee
chore(runway): cherry-pick fix(predict): stabilize Predict pay-with-any-token quote updates (#30187)
- fix(predict): stabilize Predict pay-with-any-token quote updates
cp-7.77.0 (#30064)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.
In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->
## **Description**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
This fixes Predict pay-with-any-token quote and CTA timing issues that
could appear when users changed payment tokens.
The quote trigger previously deduped updates only by amount, so a new
transaction or selected token using the same amount could skip
`updatePendingAmount` / `updateTokenAmountCallback` and fail to start
the quote request. This PR keys those emissions by transaction id, token
address, and chain id so the same amount is still emitted when the
active transaction or payment token changes.
The Predict buy CTA could also remain enabled briefly while the payment
selector was closing and before the new quote loading state appeared.
This PR adds a Predict-only payment-selector navigation lock in
`usePredictBuyConditions`, disables the buy CTA/pay row immediately when
the selector opens, and releases the lock one second after the screen
regains focus.
It also waits for account tokens before defaulting back to Predict
balance, avoiding an early fallback while token data is still empty.
Finally, this keeps transaction-pay alert text visible in the Predict
bottom-sheet flow, including while quote/pay-fee loading is in progress,
and persists order-failed banners after the controller refreshes active
order state, preventing alert/banner flicker.
When a pay-totals alert is returned with fee data, the displayed Total
now still includes the deposit fee so users can see the actual amount
required by the selected payment token.
## **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 bugs that could prevent Predict
pay-with-any-token quotes and alerts from refreshing correctly after
changing payment tokens
## **Related issues**
Fixes:
[PRED-882](https://consensyssoftware.atlassian.net/browse/PRED-882?atlOrigin=eyJpIjoiNTlkZTZkMmI1MTJkNDEyZmE0ZTE5NjUxZmVhNDg1ZjQiLCJwIjoiaiJ9)
## **Manual testing steps**
```gherkin
Feature: Predict pay with any token quote refresh
Scenario: user changes the payment token before placing a bet
Given the Predict pay-with-any-token feature is enabled
And the user opens a Predict buy preview with a valid bet amount
And an external payment token is selected
When the user opens the payment token selector
Then the buy CTA is disabled while the selector is open
When the user selects a different supported payment token
And the selector closes
Then the buy CTA remains disabled while the quote refresh starts
And the quote request is triggered for the selected token and current bet amount
And the buy CTA only becomes enabled after the quote state has settled
Scenario: user sees payment and order errors in the Predict bottom sheet
Given the user opens a Predict buy preview in bottom-sheet mode
When the selected payment token cannot cover the quote
Then the transaction-pay alert remains visible
When order placement fails
Then the order-failed banner remains visible until the user retries, changes the amount, or closes the sheet
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
N/A
### **After**
N/A
## **Pre-merge author checklist**
<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.
Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->
- [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.
#### Performance checks (if applicable)
- [x] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [x] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [x] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->
- [ ] 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.
<!-- Generated with the help of the pr-description AI skill -->
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches Predict buy/payment gating, navigation timing, and error
surfacing logic; issues could block order placement or hide critical
alerts if the new lock/settling conditions misfire.
>
> **Overview**
> **Predict pay-with-any-token quote/CTA timing is hardened.** Adds a
payment-selector navigation lock (with 1s delayed unlock + 5s safety
timeout) and threads it through
`PredictBuyWithAnyToken`/`usePredictBuyConditions` to disable the buy
CTA and `PredictPayWithRow` immediately while the selector is
opening/closing.
>
> **Quote settling and emissions are made token/tx-aware.**
`usePredictBuyConditions` now treats settling as a *token+chain+amount*
key (not just token address), and `PredictPayWithAnyTokenInfo` dedupes
`updatePendingAmount`/`updateTokenAmount` by `transactionMeta.id + token
address + chainId` so selecting a new token/tx with the same amount
still re-triggers quotes.
>
> **Error UX is refined for sheet mode.** `usePredictBuyError` now
returns `errorMessageSource`, prioritizes blocking pay-alert text (even
while pay fees load), persists `order_failed` banners across controller
refreshes, and clears persisted banners on token change;
`PredictBuyWithAnyToken` conditionally suppresses only
insufficient-balance helper text in Change Payment/Add Funds modes while
keeping blocking pay alerts visible alongside banners.
>
> **Default token and fee display behavior is adjusted.**
`usePredictDefaultPaymentToken` waits for account tokens before falling
back, and `usePredictBuyInfo` always computes `depositFee` from
`payTotals` (including when pay alerts exist) without caching a “last
accepted” fee during confirming.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ea34d01. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[PRED-882]:
https://consensyssoftware.atlassian.net/browse/PRED-882?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[ec66ea6](ec66ea6)
[PRED-882]:
https://consensyssoftware.atlassian.net/browse/PRED-882?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: Caainã Jeronimo <caainaje@gmail.com>1 parent e0b88b9 commit d7ffcee
15 files changed
Lines changed: 1023 additions & 239 deletions
File tree
- app/components/UI/Predict
- constants
- views/PredictBuyWithAnyToken
- components
- PredictPayWithAnyTokenInfo
- PredictPayWithRow
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
Lines changed: 82 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| |||
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| 165 | + | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
| |||
167 | 176 | | |
168 | 177 | | |
169 | 178 | | |
| 179 | + | |
| 180 | + | |
170 | 181 | | |
171 | 182 | | |
172 | 183 | | |
173 | 184 | | |
174 | 185 | | |
175 | 186 | | |
| 187 | + | |
176 | 188 | | |
177 | 189 | | |
178 | 190 | | |
| |||
314 | 326 | | |
315 | 327 | | |
316 | 328 | | |
317 | | - | |
| 329 | + | |
318 | 330 | | |
319 | 331 | | |
320 | 332 | | |
321 | 333 | | |
| 334 | + | |
322 | 335 | | |
323 | 336 | | |
324 | 337 | | |
| 338 | + | |
325 | 339 | | |
326 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
327 | 347 | | |
328 | 348 | | |
329 | 349 | | |
| |||
406 | 426 | | |
407 | 427 | | |
408 | 428 | | |
| 429 | + | |
409 | 430 | | |
410 | 431 | | |
411 | 432 | | |
| 433 | + | |
412 | 434 | | |
413 | 435 | | |
414 | 436 | | |
| |||
476 | 498 | | |
477 | 499 | | |
478 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
479 | 522 | | |
480 | 523 | | |
481 | 524 | | |
| |||
662 | 705 | | |
663 | 706 | | |
664 | 707 | | |
| 708 | + | |
665 | 709 | | |
666 | 710 | | |
667 | 711 | | |
| |||
771 | 815 | | |
772 | 816 | | |
773 | 817 | | |
774 | | - | |
| 818 | + | |
775 | 819 | | |
776 | 820 | | |
777 | 821 | | |
| 822 | + | |
778 | 823 | | |
779 | 824 | | |
780 | 825 | | |
| |||
783 | 828 | | |
784 | 829 | | |
785 | 830 | | |
786 | | - | |
| 831 | + | |
787 | 832 | | |
788 | 833 | | |
789 | 834 | | |
| 835 | + | |
790 | 836 | | |
791 | 837 | | |
792 | 838 | | |
793 | 839 | | |
794 | 840 | | |
795 | 841 | | |
796 | 842 | | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
797 | 875 | | |
798 | 876 | | |
Lines changed: 86 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
71 | 117 | | |
72 | 118 | | |
73 | 119 | | |
| |||
186 | 232 | | |
187 | 233 | | |
188 | 234 | | |
| 235 | + | |
| 236 | + | |
189 | 237 | | |
190 | 238 | | |
191 | 239 | | |
192 | 240 | | |
193 | 241 | | |
194 | 242 | | |
195 | 243 | | |
196 | | - | |
197 | 244 | | |
198 | 245 | | |
199 | 246 | | |
200 | 247 | | |
201 | 248 | | |
| 249 | + | |
202 | 250 | | |
203 | 251 | | |
204 | 252 | | |
| |||
227 | 275 | | |
228 | 276 | | |
229 | 277 | | |
| 278 | + | |
230 | 279 | | |
231 | | - | |
| 280 | + | |
232 | 281 | | |
233 | 282 | | |
234 | 283 | | |
| |||
297 | 346 | | |
298 | 347 | | |
299 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
300 | 353 | | |
301 | 354 | | |
302 | 355 | | |
| |||
312 | 365 | | |
313 | 366 | | |
314 | 367 | | |
| 368 | + | |
315 | 369 | | |
316 | 370 | | |
317 | 371 | | |
| |||
336 | 390 | | |
337 | 391 | | |
338 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
339 | 413 | | |
340 | 414 | | |
341 | 415 | | |
| |||
396 | 470 | | |
397 | 471 | | |
398 | 472 | | |
399 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
400 | 477 | | |
401 | 478 | | |
402 | 479 | | |
403 | 480 | | |
404 | | - | |
| 481 | + | |
405 | 482 | | |
406 | | - | |
407 | | - | |
408 | | - | |
| 483 | + | |
409 | 484 | | |
410 | 485 | | |
411 | 486 | | |
| |||
431 | 506 | | |
432 | 507 | | |
433 | 508 | | |
434 | | - | |
| 509 | + | |
435 | 510 | | |
436 | 511 | | |
| 512 | + | |
437 | 513 | | |
438 | 514 | | |
439 | 515 | | |
| |||
459 | 535 | | |
460 | 536 | | |
461 | 537 | | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
| 538 | + | |
| 539 | + | |
476 | 540 | | |
477 | 541 | | |
478 | 542 | | |
| |||
0 commit comments