Skip to content

Commit be8e784

Browse files
committed
fix(tokens): preserve net transfer amount on TxProcessingScreen
Store the computed netTransferAmount at confirmation time instead of re-deriving it from the live keypad input, which gets reset to zero when the exchange rate observer fires during transaction processing. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 4acf338 commit be8e784

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
8686
val buyProgress: LoadingSuccessState = LoadingSuccessState(),
8787
val sellProgress: LoadingSuccessState = LoadingSuccessState(),
8888
val processingProgress: LoadingSuccessState = LoadingSuccessState(),
89+
val confirmedNetTransferAmount: Fiat? = null,
8990
) {
9091
val sellFee: Double?
9192
get() {
@@ -133,7 +134,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
133134
}
134135

135136
val netTransferAmount: Fiat
136-
get() = when (purpose) {
137+
get() = confirmedNetTransferAmount ?: when (purpose) {
137138
is TokenSwapPurpose.BalanceIncrease -> enteredAmount
138139
else -> Fiat(fiat = enteredAmount.decimalValue - feeAmount.decimalValue, currencyCode = enteredAmount.currencyCode)
139140
}
@@ -204,7 +205,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
204205

205206
data class CreateAndSendTransactionToWallet(val token: Token, val amount: LocalFiat) : Event
206207

207-
data class OnAmountAccepted(val amount: LocalFiat) : Event
208+
data class OnAmountAccepted(val amount: LocalFiat, val netTransferAmount: Fiat) : Event
208209

209210
data class ProceedWithPurchase(val amount: LocalFiat) : Event
210211
data class ProceedWithSale(val amount: LocalFiat) : Event
@@ -477,9 +478,10 @@ class BuySellSwapTokenViewModel @Inject constructor(
477478
balance = stateFlow.value.reservesBalance.convertingToUsdIfNeeded(rate),
478479
rate = rate
479480
)
481+
val netAmount = amountFiat.nativeAmount
480482

481483
dispatchEvent(Event.UpdateBuyState(loading = true))
482-
dispatchEvent(Event.OnAmountAccepted(amountFiat))
484+
dispatchEvent(Event.OnAmountAccepted(amountFiat, netTransferAmount = netAmount))
483485
dispatchEvent(Event.ProceedWithPurchase(amountFiat))
484486
}
485487

@@ -493,7 +495,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
493495
nativeAmount = nativeAmount,
494496
)
495497

496-
dispatchEvent(Event.OnAmountAccepted(amountFiat))
498+
dispatchEvent(Event.OnAmountAccepted(amountFiat, netTransferAmount = nativeAmount))
497499
dispatchEvent(Event.UpdateBuyState(loading = true))
498500
dispatchEvent(
499501
Event.CreateAndSendTransactionToWallet(
@@ -512,8 +514,9 @@ class BuySellSwapTokenViewModel @Inject constructor(
512514
balance = tokenWithBalance.balance,
513515
rate = rate,
514516
)
517+
val netAmount = stateFlow.value.netTransferAmount
515518

516-
dispatchEvent(Event.OnAmountAccepted(amountFiat))
519+
dispatchEvent(Event.OnAmountAccepted(amountFiat, netTransferAmount = netAmount))
517520
dispatchEvent(Event.ShowSellReceipt)
518521
}
519522
}
@@ -662,6 +665,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
662665
is Event.OnAmountAccepted -> { state ->
663666
val entryState = state.amountEntryState
664667
state.copy(
668+
confirmedNetTransferAmount = event.netTransferAmount,
665669
amountEntryState = entryState.copy(
666670
selectedAmount = event.amount,
667671
)

0 commit comments

Comments
 (0)