Skip to content

Commit 9b48654

Browse files
committed
fix: check all sanity checks
1 parent 1fb55b4 commit 9b48654

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private fun Content(
244244
text = stringResource(dialog.message),
245245
confirmText = stringResource(R.string.wallet__send_yes),
246246
dismissText = stringResource(R.string.common__cancel),
247-
onConfirm = { onEvent(SendEvent.ConfirmAmountWarning) },
247+
onConfirm = { onEvent(SendEvent.ConfirmAmountWarning(dialog)) },
248248
onDismiss = {
249249
onEvent(SendEvent.DismissAmountWarning)
250250
onBack()

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class AppViewModel @Inject constructor(
303303

304304
SendEvent.SpeedAndFee -> setSendEffect(SendEffect.NavigateToFee)
305305
SendEvent.SwipeToPay -> onSwipeToPay()
306-
SendEvent.ConfirmAmountWarning -> onConfirmAmountWarning()
306+
is SendEvent.ConfirmAmountWarning -> onConfirmAmountWarning(it.warning)
307307
SendEvent.DismissAmountWarning -> onDismissAmountWarning()
308308
SendEvent.PayConfirmed -> onConfirmPay()
309309
SendEvent.BackToAmount -> setSendEffect(SendEffect.PopBack(SendRoute.Amount))
@@ -839,15 +839,21 @@ class AppViewModel @Inject constructor(
839839

840840
val settings = settingsStore.data.first()
841841
val amountInUsd = currencyRepo.convertSatsToFiat(amountSats.toLong(), "USD").getOrNull() ?: return
842-
if (amountInUsd.value > BigDecimal(SEND_AMOUNT_WARNING_THRESHOLD) && settings.enableSendAmountWarning) {
842+
if (
843+
amountInUsd.value > BigDecimal(SEND_AMOUNT_WARNING_THRESHOLD) &&
844+
settings.enableSendAmountWarning &&
845+
SanityWarning.VALUE_OVER_100_USD !in _sendUiState.value.confirmedWarnings
846+
) {
843847
_sendUiState.update {
844848
it.copy(showSanityWarningDialog = SanityWarning.VALUE_OVER_100_USD)
845849
}
846850
return
847851
}
848852

849-
if (amountSats > BigDecimal.valueOf(walletRepo.balanceState.value.totalSats.toLong())
850-
.times(BigDecimal(0.5)).toLong().toUInt()
853+
if (
854+
amountSats > BigDecimal.valueOf(walletRepo.balanceState.value.totalSats.toLong())
855+
.times(BigDecimal(0.5)).toLong().toUInt() &&
856+
SanityWarning.OVER_HALF_BALANCE !in _sendUiState.value.confirmedWarnings
851857
) {
852858
_sendUiState.update {
853859
it.copy(showSanityWarningDialog = SanityWarning.OVER_HALF_BALANCE)
@@ -864,8 +870,11 @@ class AppViewModel @Inject constructor(
864870
utxosToSpend = _sendUiState.value.selectedUtxos,
865871
).getOrNull() ?: return
866872

867-
if (totalFee > BigDecimal.valueOf(amountSats.toLong())
868-
.times(BigDecimal(0.5)).toLong().toUInt()
873+
if (
874+
totalFee > BigDecimal.valueOf(
875+
amountSats.toLong()
876+
).times(BigDecimal(0.5)).toLong().toUInt() &&
877+
SanityWarning.FEE_OVER_HALF_VALUE !in _sendUiState.value.confirmedWarnings
869878
) {
870879
_sendUiState.update {
871880
it.copy(showSanityWarningDialog = SanityWarning.FEE_OVER_HALF_VALUE)
@@ -874,7 +883,10 @@ class AppViewModel @Inject constructor(
874883
}
875884

876885
val feeInUsd = currencyRepo.convertSatsToFiat(totalFee.toLong(), "USD").getOrNull() ?: return
877-
if (feeInUsd.value > BigDecimal(TEN_USD)) {
886+
if (
887+
feeInUsd.value > BigDecimal(TEN_USD) &&
888+
SanityWarning.FEE_OVER_10_USD !in _sendUiState.value.confirmedWarnings
889+
) {
878890
_sendUiState.update {
879891
it.copy(showSanityWarningDialog = SanityWarning.FEE_OVER_10_USD)
880892
}
@@ -1364,15 +1376,16 @@ class AppViewModel @Inject constructor(
13641376
}
13651377
}
13661378

1367-
private fun onConfirmAmountWarning() {
1379+
private fun onConfirmAmountWarning(warning: SanityWarning) {
13681380
viewModelScope.launch {
13691381
_sendUiState.update {
13701382
it.copy(
13711383
showSanityWarningDialog = null,
1372-
shouldConfirmPay = true,
1384+
confirmedWarnings = it.confirmedWarnings + warning
13731385
)
13741386
}
13751387
}
1388+
onSwipeToPay()
13761389
}
13771390

13781391
private fun onDismissAmountWarning() {
@@ -1473,7 +1486,7 @@ sealed interface SendEvent {
14731486
data object SwipeToPay : SendEvent
14741487
data object SpeedAndFee : SendEvent
14751488
data object PaymentMethodSwitch : SendEvent
1476-
data object ConfirmAmountWarning : SendEvent
1489+
data class ConfirmAmountWarning(val warning: SanityWarning) : SendEvent
14771490
data object DismissAmountWarning : SendEvent
14781491
data object PayConfirmed : SendEvent
14791492
data object BackToAmount : SendEvent

0 commit comments

Comments
 (0)