Skip to content

Commit f1caa3d

Browse files
authored
Merge pull request #683 from code-payments/fix/withdrawal-currency-mismatch
fix(withdrawal): prevent currency mismatch when entryRate is null
2 parents 2206b1a + bfcb388 commit f1caa3d

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/WithdrawalViewModel.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal class WithdrawalViewModel @Inject constructor(
106106
val feeInEntryCurrency: Fiat?
107107
get() {
108108
val fee = feeAmount ?: return null
109-
val rate = entryRate ?: return fee
109+
val rate = entryRate ?: return null
110110
return fee.convertingTo(rate)
111111
}
112112

@@ -120,7 +120,7 @@ internal class WithdrawalViewModel @Inject constructor(
120120
val netTransferAmount: Fiat
121121
get() {
122122
val amount = amountEntryState.selectedAmount.localFiat.nativeAmount
123-
val fee = feeInEntryCurrency ?: 0.toFiat(amount.currencyCode)
123+
val fee = feeInEntryCurrency ?: 0.00.toFiat(amount.currencyCode)
124124
return amount - fee
125125
}
126126

@@ -138,7 +138,7 @@ internal class WithdrawalViewModel @Inject constructor(
138138
return EnteredAmountError.InsufficientFunds
139139
}
140140

141-
val fee = feeInEntryCurrency ?: 0.toFiat(tokenBalance.currencyCode)
141+
val fee = feeInEntryCurrency ?: 0.00.toFiat(tokenBalance.currencyCode)
142142

143143
if (enteredAmount.valueLessThanOrEqualTo(fee)) {
144144
return EnteredAmountError.TooLow
@@ -229,6 +229,7 @@ internal class WithdrawalViewModel @Inject constructor(
229229

230230
init {
231231
numberInputHelper.reset()
232+
dispatchEvent(Event.OnEntryRateUpdated(exchange.entryRate))
232233

233234
stateFlow
234235
.mapNotNull { it.selectedTokenAddress }
@@ -605,7 +606,7 @@ internal class WithdrawalViewModel @Inject constructor(
605606
usdf = it,
606607
rate = amount.localFiat.rate
607608
)
608-
} ?: LocalFiat.fromUsd(0.toFiat(), rate = amount.localFiat.rate)
609+
} ?: LocalFiat.fromUsd(0.00.toFiat(), rate = amount.localFiat.rate)
609610

610611
transactionController.withdrawUsdf(
611612
amount = amount,

0 commit comments

Comments
 (0)