fix(tokens): allow buying a currency with a non-USDF balance - #1171
Merged
Conversation
The buy gate on the token info screen checked only the USDF reserve balance (hasReserves), so a user holding another Flipcash currency but no USDF was routed to the Add Money flow instead of the swap screen — even though the swap flow already supports funding a buy with any held currency. Gate on whether the user holds a displayable balance in some token other than the one being bought (hasFundableBalance), mirroring the swap token picker's own eligibility rule. Replaces the USDF-only reserves observation with an all-token balances observation.
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.
Problem
On the token info screen, tapping Buy with zero USDF but a balance in another Flipcash currency wrongly routed the user to the Add Money flow. The buy gate checked only the USDF reserve balance, even though the swap flow already supports funding a buy with any held currency.
Root cause
TokenInfoViewModelgated the Buy action onState.hasReserves, which is USDF-only (observeReservesBalance()→balanceForToken(Mint.usdf)). With no USDF,!hasReservesshort-circuited to the Add Money prompt before the user ever reached the funding-token picker.Fix
State.hasFundableBalance: true when the user holds a displayable balance in some token other than the one being bought — mirroring the swap picker's own eligibility rule (address != desiredToken && hasDisplayableValue), so we never route to an empty picker.tokenCoordinator.tokenBalances(all mints) instead ofobserveReservesBalance()(USDF only), using the sameFiat.hasDisplayableValue"has real money" check as the existinghasBalance()/hasGiveableBalance()gates.if (!hasFundableBalance && addMoney). FF-off behavior is unchanged; retired the now-dead reserves tracking that existed only for this gate.Tests
Added
TokenInfoViewModelStateTest(5 cases): no balance → Add Money; only the target token → Add Money; another currency → buy allowed (the regression); USDF present → buy allowed; reducer wiring. Green againstcode/cash.Audit of other Add Money gates
Swept every deposit/Add Money gate for the same USDF-only bug class. All other reachable gates (give, tip, send cash, launch/create currency, scanner, swap amount caps) already use all-currency helpers. The one USDF-only comparison in
SwapViewModel.checkBalanceLimit(BalanceIncreasebranch) is unreachable dead code —checkBalanceLimit()is only invoked forBalanceDecrease(Sell); Buy goes throughcheckFundingAmount()→transactionLimit(), which is already all-currency aware. Left untouched here; flagging as a latent landmine worth removing separately.