aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-05-29 13:58:08 -0600
committerIván Ávalos <avalos@disroot.org>2024-05-29 14:05:33 -0600
commitc78239399c89cdf9ccb87f9f97a15e0806fb1003 (patch)
tree74c501499ee6051d541ac3736a9c7f53191b38bf
parent79f3a999da50e87687132d057d7c635285f4c4ae (diff)
downloadtaler-android-c78239399c89cdf9ccb87f9f97a15e0806fb1003.tar.gz
taler-android-c78239399c89cdf9ccb87f9f97a15e0806fb1003.tar.bz2
taler-android-c78239399c89cdf9ccb87f9f97a15e0806fb1003.zip
[wallet] Skip template form if only one currency is usabledev/ivan-avalos/checktemplate
bug 0008854
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt4
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt9
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PayTemplateFragment.kt12
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt4
4 files changed, 20 insertions, 9 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
index 4d96566..d744183 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
@@ -47,7 +47,9 @@ fun PayTemplateComposable(
PayTemplateError(stringResource(R.string.payment_balance_insufficient))
} else when (val p = payStatus) {
is PayStatus.Checked -> {
- val usableCurrencies = currencies.intersect(p.supportedCurrencies.toSet()).toList()
+ val usableCurrencies = currencies
+ .intersect(p.supportedCurrencies.toSet())
+ .toList()
if (usableCurrencies.isEmpty()) {
// If user doesn't have any supported currency, they can't pay either
PayTemplateError(stringResource(R.string.payment_balance_insufficient))
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt
index df9153f..4c3f0a5 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt
@@ -103,11 +103,14 @@ class WalletTemplateDetails(
fun isAmountEditable() = templateContract.amount == null
- fun isCurrencyEditable() = requiredCurrency == null && templateContract.currency == null
+ fun isCurrencyEditable(usableCurrencies: List<String>) = isAmountEditable()
+ && requiredCurrency == null
+ && templateContract.currency == null
+ && usableCurrencies.size > 1
- fun isTemplateEditable() = isSummaryEditable()
+ fun isTemplateEditable(usableCurrencies: List<String>) = isSummaryEditable()
|| isAmountEditable()
- || isCurrencyEditable()
+ || isCurrencyEditable(usableCurrencies)
// NOTE: it is important to nullify non-editable values!
fun toTemplateParams() = TemplateParams(
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateFragment.kt
index d212540..51c0bc0 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateFragment.kt
@@ -38,6 +38,7 @@ class PayTemplateFragment : Fragment() {
private val model: MainViewModel by activityViewModels()
private lateinit var uriString: String
private lateinit var uri: Uri
+ private val currencies by lazy { model.getCurrencies() }
override fun onCreateView(
inflater: LayoutInflater,
@@ -54,7 +55,7 @@ class PayTemplateFragment : Fragment() {
val payStatus = payStatusFlow.collectAsStateLifecycleAware(initial = PayStatus.None)
TalerSurface {
PayTemplateComposable(
- currencies = model.getCurrencies(),
+ currencies = currencies,
payStatus = payStatus.value,
onCreateAmount = model::createAmount,
onSubmit = this@PayTemplateFragment::createOrder,
@@ -79,8 +80,13 @@ class PayTemplateFragment : Fragment() {
showError(payStatus.error)
}
- is PayStatus.Checked -> if (!payStatus.details.isTemplateEditable()) {
- createOrder(payStatus.details.toTemplateParams())
+ is PayStatus.Checked -> {
+ val usableCurrencies = currencies
+ .intersect(payStatus.supportedCurrencies.toSet())
+ .toList()
+ if (!payStatus.details.isTemplateEditable(usableCurrencies)) {
+ createOrder(payStatus.details.toTemplateParams())
+ }
}
else -> {}
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt
index e8926a7..2febfbb 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt
@@ -93,7 +93,7 @@ fun PayTemplateOrderComposable(
amount = amount,
currency = currency,
currencies = usableCurrencies,
- readOnlyCurrency = !templateDetails.isCurrencyEditable(),
+ readOnlyCurrency = !templateDetails.isCurrencyEditable(usableCurrencies),
readOnlyAmount = !templateDetails.isAmountEditable(),
onAmountChosen = { a, c ->
amount = a
@@ -103,7 +103,7 @@ fun PayTemplateOrderComposable(
Button(
modifier = Modifier.padding(16.dp),
- enabled = !templateDetails.isSummaryEditable() || !summary.isNullOrBlank(),
+ enabled = !templateDetails.isSummaryEditable() || summary.isNotBlank(),
onClick = {
when (val res = onCreateAmount(amount, currency)) {
is AmountResult.InsufficientBalance -> onError(R.string.payment_balance_insufficient)