refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0 #28396
Conversation
depositAmount was only consumed by PredictPayWithAnyTokenInfo, so the component should own its computation. This reduces the shared hook's surface area and makes the data flow more explicit.
Remove normalizeQuoteComparableAddress, isPaymentTokenRequired, and isQuotesStale logic from usePredictBuyConditions, simplifying isPayFeesLoading to only check controller loading states. Move useTransactionCustomAmount call earlier in PredictPayWithAnyTokenInfo for consistent hook ordering.
|
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. |
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - draft PR All E2E tests pre-selected. |
|
✅ E2E Fixture Validation — Schema is up to date |
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5526d80. Configure here.




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 the component that consumes it. This eliminates an unnecessary prop hop and keeps the headless component self-contained.isQuotesStalelogic fromusePredictBuyConditions— this workaround forTransactionPayControllertiming gaps is no longer needed, simplifying the pay fees loading derivation.EngineService.flushState()after deposit amount, token amount, and pay token mutations to ensure immediate state consistency for the deposit-and-order batch flow.amountHuman—updateTokenAmountCallbacknow passes the fiat-convertedamountHumanfromuseTransactionCustomAmountinstead of the rounded deposit amount, matching the Perps pattern.Files changed (8):
PredictPayWithAnyTokenInfo.tsxPredictPayWithAnyTokenInfo.test.tsxPredictBuyWithAnyToken.tsxcurrentValue,preview,isInputFocusedinstead ofdepositAmountPredictBuyWithAnyToken.test.tsxusePredictBuyInfo.tsdepositAmountreturn, removedusePredictBalanceandMINIMUM_BETimportsusePredictBuyInfo.test.tsdepositAmounttests and related mocksusePredictBuyConditions.tsisQuotesStale, simplifiedisPayFeesLoadingusePredictBuyConditions.test.tsisQuotesStaletests andgetNativeTokenAddressmockChangelog
CHANGELOG entry: null
Related issues
Fixes: #28413
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
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 and propagation (based oncurrentValue,previewfees, andusePredictBalance) and only commits updates when the amount input is not focused.Removes
depositAmountfromusePredictBuyInfoand updates the screen/component wiring accordingly;updatePendingAmount/updateTokenAmountnow de-dupe repeated emissions, useamountHumanfor token updates, and callEngineService.flushState()after mutating confirmation/payment state.Simplifies pay-fee loading in
usePredictBuyConditionsby dropping theisQuotesStaleworkaround and associated native-token normalization logic, 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.