chore(runway): cherry-pick refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0#28416
Merged
Conversation
…PredictPayWithAnyTokenInfo cp-7.73.0 (#28396) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR refactors the deposit amount flow in the Predict buy-with-any-token feature to improve correctness, reduce redundant re-computations, and align the token amount update pattern with Perps. **What changed:** - **Moved `depositAmount` computation** from `usePredictBuyInfo` into `PredictPayWithAnyTokenInfo`, co-locating the calculation with the component that consumes it. This eliminates an unnecessary prop hop and keeps the headless component self-contained. - **Gated deposit amount updates on input focus** — deposit amount is only committed when the user finishes editing (input blur), preventing redundant effect runs and state churn while the user is actively typing. - **Removed `isQuotesStale` logic** from `usePredictBuyConditions` — this workaround for `TransactionPayController` timing gaps is no longer needed, simplifying the pay fees loading derivation. - **Added `EngineService.flushState()`** after deposit amount, token amount, and pay token mutations to ensure immediate state consistency for the deposit-and-order batch flow. - **Aligned token amount callback with `amountHuman`** — `updateTokenAmountCallback` now passes the fiat-converted `amountHuman` from `useTransactionCustomAmount` instead of the rounded deposit amount, matching the Perps pattern. **Files changed (8):** | File | Change | | ------------------------------------- | --------------------------------------------------------------------------------------------- | | `PredictPayWithAnyTokenInfo.tsx` | Major — owns deposit amount computation, input focus gating, state flush | | `PredictPayWithAnyTokenInfo.test.tsx` | Major — new test sections for computation, gating, dedup behavior | | `PredictBuyWithAnyToken.tsx` | Minor — passes `currentValue`, `preview`, `isInputFocused` instead of `depositAmount` | | `PredictBuyWithAnyToken.test.tsx` | Minor — updated mock interface | | `usePredictBuyInfo.ts` | Minor — removed `depositAmount` return, removed `usePredictBalance` and `MINIMUM_BET` imports | | `usePredictBuyInfo.test.ts` | Minor — removed `depositAmount` tests and related mocks | | `usePredictBuyConditions.ts` | Moderate — removed `isQuotesStale`, simplified `isPayFeesLoading` | | `usePredictBuyConditions.test.ts` | Moderate — removed `isQuotesStale` tests and `getNativeTokenAddress` mock | <!-- 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? --> ## **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: null ## **Related issues** Fixes: #28413 ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] 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). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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 Predict buy payment/deposit amount propagation into the confirmations flow, including new state-flush behavior; mistakes could cause incorrect amounts or extra state churn during order placement. > > **Overview** > Refactors the Predict buy-with-any-token flow so `PredictPayWithAnyTokenInfo` owns **deposit amount calculation and propagation** (based on `currentValue`, `preview` fees, and `usePredictBalance`) and only commits updates when the amount input is *not focused*. > > Removes `depositAmount` from `usePredictBuyInfo` and updates the screen/component wiring accordingly; `updatePendingAmount`/`updateTokenAmount` now de-dupe repeated emissions, use `amountHuman` for token updates, and call `EngineService.flushState()` after mutating confirmation/payment state. > > Simplifies pay-fee loading in `usePredictBuyConditions` by dropping the `isQuotesStale` workaround and associated native-token normalization logic, with tests updated/expanded to cover the new deposit gating and rounding behavior. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5526d80. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/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 |
|
Contributor
|
force merge this PR as the audit issue will be fixed by #28459 |
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
This PR refactors the deposit amount flow in the Predict
buy-with-any-token feature to improve correctness, reduce redundant
re-computations, and align the token amount update pattern with Perps.
What changed:
depositAmountcomputation fromusePredictBuyInfointoPredictPayWithAnyTokenInfo, co-locating the calculation with thecomponent that consumes it. This eliminates an unnecessary prop hop and
keeps the headless component self-contained.
only committed when the user finishes editing (input blur), preventing
redundant effect runs and state churn while the user is actively typing.
isQuotesStalelogic fromusePredictBuyConditions—this workaround for
TransactionPayControllertiming gaps is no longerneeded, simplifying the pay fees loading derivation.
EngineService.flushState()after deposit amount, tokenamount, and pay token mutations to ensure immediate state consistency
for the deposit-and-order batch flow.
amountHuman—updateTokenAmountCallbacknow passes the fiat-convertedamountHumanfrom
useTransactionCustomAmountinstead of the rounded deposit amount,matching the Perps pattern.
Files changed (8):
| File | Change |
| ------------------------------------- |
|
|
PredictPayWithAnyTokenInfo.tsx| Major — owns deposit amountcomputation, input focus gating, state flush |
|
PredictPayWithAnyTokenInfo.test.tsx| Major — new test sections forcomputation, gating, dedup behavior |
|
PredictBuyWithAnyToken.tsx| Minor — passescurrentValue,preview,isInputFocusedinstead ofdepositAmount||
PredictBuyWithAnyToken.test.tsx| Minor — updated mock interface ||
usePredictBuyInfo.ts| Minor — removeddepositAmountreturn,removed
usePredictBalanceandMINIMUM_BETimports ||
usePredictBuyInfo.test.ts| Minor — removeddepositAmounttestsand related mocks |
|
usePredictBuyConditions.ts| Moderate — removedisQuotesStale,simplified
isPayFeesLoading||
usePredictBuyConditions.test.ts| Moderate — removedisQuotesStaletests and
getNativeTokenAddressmock |Changelog
CHANGELOG entry: null
Related issues
Fixes: #28413
Manual testing steps
Screenshots/Recordings
Before
After
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 Predict buy payment/deposit amount propagation into the
confirmations flow, including new state-flush behavior; mistakes could
cause incorrect amounts or extra state churn during order placement.
Overview
Refactors the Predict buy-with-any-token flow so
PredictPayWithAnyTokenInfoowns deposit amount calculation andpropagation (based on
currentValue,previewfees, andusePredictBalance) and only commits updates when the amount input isnot focused.
Removes
depositAmountfromusePredictBuyInfoand updates thescreen/component wiring accordingly;
updatePendingAmount/updateTokenAmountnow de-dupe repeatedemissions, use
amountHumanfor token updates, and callEngineService.flushState()after mutating confirmation/payment state.Simplifies pay-fee loading in
usePredictBuyConditionsby droppingthe
isQuotesStaleworkaround and associated native-token normalizationlogic, with tests updated/expanded to cover the new deposit gating and
rounding behavior.
Reviewed by Cursor Bugbot for commit
5526d80. Bugbot is set up for automated
code reviews on this repo. Configure
here.