Skip to content

Commit 9348a66

Browse files
committed
fix(tokens): recompute the net transfer on re-entry
The private `netTransferAmount` producer deferred to `State.confirmedNetTransferAmount` — its own output from a previous trip through the entry screen — while `enteredAmount` and `feeAmount` beside it recomputed from the live amount delegate. All three feed the same `OnAmountAccepted` event, so a second pass produced a receipt that mixed the new entry with the old total: enter $1, go back, enter $0.50, and the receipt paired a $0.50 debit and a $0.005 fee with a $0.99 "You Receive". The cache-first read is a leftover from before #829, when a single getter on `State` served both roles and the keypad lived on `State` too; there it was what pinned the number once accepted. The delegate split gave that freeze its own home in `State.netTransferAmount`, but the producer copy kept the prefix. `enteredAmount` and `feeAmount` were rewritten during that split and came out cache-free, which is the asymmetry behind the bug. Affects v1's Sell path the same way, so it is left ungated — a wrong number is not a v1 pixel worth preserving.
1 parent 6c5dcb3 commit 9348a66

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui

‎apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui/SwapViewModel.kt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,19 @@ class SwapViewModel @Inject constructor(
493493
return enteredAmount.launchpadSellFee(bps)
494494
}
495495

496-
/** What the user actually receives: entered minus the fee, unless the fee rides on top. */
496+
/**
497+
* What the user actually receives: entered minus the fee, unless the fee rides on top.
498+
*
499+
* Always recomputed from the live entry rather than read back from
500+
* [State.confirmedNetTransferAmount], because this getter is what *produces* that snapshot --
501+
* [enteredAmount] and [feeAmount] feed the same event and recompute the same way. Deferring to
502+
* the previous confirmation made a second trip through the entry screen re-confirm the first
503+
* trip's total: enter $1, go back, enter $0.50, and the receipt paired a $0.50 debit and a
504+
* $0.005 fee with a $0.99 "You Receive". Readers that need the snapshot after the entry screen
505+
* is gone use [State.netTransferAmount], which is where the caching belongs.
506+
*/
497507
private val netTransferAmount: Fiat
498-
get() = stateFlow.value.confirmedNetTransferAmount ?: when {
508+
get() = when {
499509
stateFlow.value.purpose is SwapPurpose.BalanceIncrease -> enteredAmount
500510
stateFlow.value.isConvertingFromDollars -> enteredAmount
501511
else -> Fiat(

0 commit comments

Comments
 (0)