diff --git a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.kt b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.kt index 0066a6660e..f7f1de2f9e 100644 --- a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.kt @@ -24,6 +24,7 @@ import android.net.Uri import android.os.Bundle import android.view.View import android.widget.Toast +import androidx.annotation.StringRes import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope @@ -174,17 +175,8 @@ class SendCoinsFragment: Fragment(R.layout.send_coins_fragment) { } else if (dryRunException != null) { errorMessage = when (dryRunException) { is Wallet.DustySendRequested -> getString(R.string.send_coins_error_dusty_send) - is InsufficientMoneyException -> if (!requirePinForBalance || userAuthorizedDuring) { - getString( - if (viewModel.isCoinJoinInsufficentMoneyException) { - R.string.send_coins_error_insufficient_mixed_money - } else { - R.string.send_coins_error_insufficient_money - } - ) - } else { - "" - } + is InsufficientCoinJoinMoneyException -> getErrorMessage(R.string.send_coins_error_insufficient_mixed_money) + is InsufficientMoneyException -> getErrorMessage(R.string.send_coins_error_insufficient_money) is Wallet.CouldNotAdjustDownwards -> getString(R.string.send_coins_error_dusty_send) else -> dryRunException.toString() } @@ -207,6 +199,12 @@ class SendCoinsFragment: Fragment(R.layout.send_coins_fragment) { ) } + private fun getErrorMessage(@StringRes errorMessage: Int) = if (!requirePinForBalance || userAuthorizedDuring) { + getString(errorMessage) + } else { + "" + } + private suspend fun authenticateOrConfirm() { if (!viewModel.everythingPlausible()) { return diff --git a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsViewModel.kt b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsViewModel.kt index 9e63f7db92..eaded63b88 100644 --- a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsViewModel.kt @@ -57,6 +57,7 @@ import javax.inject.Inject import kotlin.math.min class SendException(message: String) : Exception(message) +class InsufficientCoinJoinMoneyException(ex: InsufficientMoneyException) : InsufficientMoneyException(ex.missing, "${ex.message} [coinjoin]") @HiltViewModel class SendCoinsViewModel @Inject constructor( @@ -124,11 +125,6 @@ class SendCoinsViewModel @Inject constructor( private var coinJoinMode: CoinJoinMode = CoinJoinMode.NONE - val isCoinJoinInsufficentMoneyException: Boolean - get() { - return coinJoinMode != CoinJoinMode.NONE && !currentAmount.isGreaterThan(wallet.getBalance(MaxOutputAmountCoinSelector())) - } - init { blockchainStateDao.observeState() .filterNotNull() @@ -303,7 +299,11 @@ class SendCoinsViewModel @Inject constructor( dryrunSendRequest = sendRequest _dryRunSuccessful.value = true } catch (ex: Exception) { - dryRunException = ex + dryRunException = if (ex is InsufficientMoneyException && coinJoinMode != CoinJoinMode.NONE && !currentAmount.isGreaterThan(wallet.getBalance(MaxOutputAmountCoinSelector()))) { + InsufficientCoinJoinMoneyException(ex) + } else { + ex + } _dryRunSuccessful.value = false } }