aboutsummaryrefslogtreecommitdiff
path: root/cashier
diff options
context:
space:
mode:
Diffstat (limited to 'cashier')
-rw-r--r--cashier/src/main/java/net/taler/cashier/BalanceFragment.kt20
-rw-r--r--cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt13
-rw-r--r--cashier/src/main/res/values/strings.xml1
3 files changed, 25 insertions, 9 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
index fa9600b..c0e2aca 100644
--- a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
+++ b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
@@ -164,13 +164,19 @@ class BalanceFragment : Fragment() {
private fun onAmountConfirmed(amount: Amount) {
if (amount.isZero()) {
ui.amountView.error = getString(R.string.withdraw_error_zero)
- } else if (!withdrawManager.hasSufficientBalance(amount)) {
- ui.amountView.error = getString(R.string.withdraw_error_insufficient_balance)
- } else {
- ui.amountView.error = null
- withdrawManager.withdraw(amount)
- actionBalanceFragmentToTransactionFragment().let {
- findNavController().navigate(it)
+ } else when (withdrawManager.hasSufficientBalance(amount)) {
+ true -> {
+ ui.amountView.error = null
+ withdrawManager.withdraw(amount)
+ actionBalanceFragmentToTransactionFragment().let {
+ findNavController().navigate(it)
+ }
+ }
+ false -> {
+ ui.amountView.error = getString(R.string.withdraw_error_insufficient_balance)
+ }
+ null -> {
+ ui.amountView.error = getString(R.string.withdraw_error_currency_mismatch)
}
}
}
diff --git a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
index 1b809bb..601b59a 100644
--- a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
+++ b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
@@ -73,11 +73,20 @@ class WithdrawManager(
private val mLastTransaction = MutableLiveData<LastTransaction>()
val lastTransaction: LiveData<LastTransaction> = mLastTransaction
+ /**
+ * Returns null if the given [amount] can't be compared to the balance
+ * e.g. due to mismatching currency.
+ */
@UiThread
- fun hasSufficientBalance(amount: Amount): Boolean {
+ fun hasSufficientBalance(amount: Amount): Boolean? {
val balanceResult = viewModel.balance.value
if (balanceResult !is BalanceResult.Success) return false
- return balanceResult.amount.positive && amount <= balanceResult.amount.amount
+ return try {
+ balanceResult.amount.positive && amount <= balanceResult.amount.amount
+ } catch (e : IllegalStateException) {
+ Log.e(TAG, "Error comparing amounts", e)
+ null
+ }
}
@UiThread
diff --git a/cashier/src/main/res/values/strings.xml b/cashier/src/main/res/values/strings.xml
index bcaab74..8e28d28 100644
--- a/cashier/src/main/res/values/strings.xml
+++ b/cashier/src/main/res/values/strings.xml
@@ -26,6 +26,7 @@
<string name="withdraw_into">How much e-cash should be withdrawn?</string>
<string name="withdraw_error_zero">Enter positive amount!</string>
<string name="withdraw_error_insufficient_balance">Insufficient balance</string>
+ <string name="withdraw_error_currency_mismatch">Error: Bank reported a different currency</string>
<string name="withdraw_error_fetch">Error communicating with bank: %s</string>
<string name="withdraw_error_timeout">No wallet tried to withdraw. Please try again.</string>
<string name="withdraw_error_offline" translatable="false">@string/balance_offline</string>