fix(tokens): correct non USD Phantom add-money flow - #1173
Merged
Conversation
The "Add money via Phantom" flow was broken for non-USD (e.g. INR) users and mis-navigated on the buy-shortfall path. - Interpret the Phantom add-money amount in the user's selected currency. The confirm path forced exchange.rateForUsd(), labelling e.g. ₹500 as $500, so compute() skipped the FX conversion and produced an underlyingTokenAmount ~83x too large — checkBalances then rejected the deposit as InsufficientUsdc. Now uses exchange.preferredRate. - Localize the "Enter up to X" max-balance hint. The AddMoney max came from USD-denominated token balances; convert it to the preferred currency so the hint (and the over-max comparison) match what the user is typing. - Guard purchaseMethodController.selections against the amount-less deposit-sheet selection (the CoinbaseOnRamp branch already did this). Without it, tapping Phantom in the buy-shortfall sheet double-navigated the buy flow to PhantomConnect, stranding the user on the connect prompt after the add-money flow finished. - Replace the buy flow with the add-money route so finishing the top-up returns to the token screen (origin) instead of the abandoned amount-to-buy step. - Make the Phantom Processing step terminal via replaceStack, with InnerFlowNavigator unit tests covering the back-stack behavior.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the Add money via Phantom flow, which was broken for non-USD (e.g. INR) users and mis-navigated on the buy-shortfall path. Found and verified on-device with the app set to INR.
Changes
Currency mislabel (the deposit failure). The Phantom confirm path forced
exchange.rateForUsd(), so the entered amount (in the user's selected currency) was labelled USD — e.g. ₹500 treated as $500.compute()then skipped the FX conversion and produced anunderlyingTokenAmount~83× too large, socheckBalancesrejected the deposit asInsufficientUsdc(surfacing atgetTokenAccountBalance). Now usesexchange.preferredRate.Unlocalized max hint. The "Enter up to X" / over-max hint used a USD-denominated max while the user typed in their local currency.
maxAmountFlownow converts the token balance to the preferred currency, so the hint and the over-max comparison agree with the entry field.Stranded on the connect prompt (buy-shortfall path).
purchaseMethodController.selectionsis a hot flow with two collectors. ThePhantomWalletbranch lacked the amount-less-selection guard thatCoinbaseOnRampalready had, so tapping Phantom in the deposit sheet double-firedPhantomSelectedand navigated the buy flow toPhantomConnect— which reappeared after the nested add-money flow finished. Hoisted thepurchaseAmountguard so amount-less deposit-sheet selections are ignored.Returned one screen short. The buy-shortfall add-money route stacked on top of the buy flow, so completion popped back to the amount-to-buy step. The
OpenScreenhandler nowreplaces the buy flow, so finishing the top-up returns to the token screen (origin) — matching add-money launched directly from the token screen. Note: this abandons the in-progress buy (re-tap Buy with the new balance).Processing is terminal. The two Phantom→Processing handlers use
replaceStack(listOf(Processing))so leaving Processing exits the flow rather than surfacing buried connect/confirm steps. AddedInnerFlowNavigatorTestcases covering the back-stack behavior (the forward-slide animation is preserved — nav3 treats a root swap as a forward navigation).Test plan
:ui:navigation:testDebugUnitTest --tests InnerFlowNavigatorTest— green (9/9).