taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit edfc59fbff80f4c8de276263a77e37e41ca1b01a
parent 4d8c3626593ca75cbda764e71660c7b3fe83f6b6
Author: Iván Ávalos <avalos@disroot.org>
Date:   Tue, 24 Nov 2026 13:00:34 +0100

[wallet] show insufficient balance reason and available funds (fixes #12066)

Diffstat:
Mwallet/src/main/java/net/taler/wallet/payment/PromptPaymentComposable.kt | 57+++++++++++++++++++++++++++++++++++++++++++++++++++------
Mwallet/src/main/res/values-de/strings.xml | 1+
Mwallet/src/main/res/values-fr/strings.xml | 1+
Mwallet/src/main/res/values/strings.xml | 1+
4 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentComposable.kt @@ -17,6 +17,7 @@ package net.taler.wallet.payment import android.graphics.Bitmap +import androidx.annotation.StringRes import androidx.compose.animation.animateContentSize import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image @@ -69,6 +70,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch @@ -94,6 +96,7 @@ import net.taler.wallet.compose.cardPaddings import net.taler.wallet.donau.DonauInfo import net.taler.wallet.donau.DonauSelector import net.taler.wallet.donau.DonauToggle +import net.taler.wallet.payment.GetChoicesForPaymentResponse.ChoiceSelectionDetail import net.taler.wallet.payment.GetChoicesForPaymentResponse.ChoiceSelectionDetail.InsufficientBalance import net.taler.wallet.payment.GetChoicesForPaymentResponse.ChoiceSelectionDetail.PaymentPossible import net.taler.wallet.payment.TokenAvailabilityHint.MerchantUnexpected @@ -203,9 +206,19 @@ fun PromptPaymentComposable( } else if (choice.details is InsufficientBalance) { Text( modifier = Modifier.padding(bottom = 3.dp), - text = stringResource(R.string.payment_balance_insufficient), + text = stringResource(choice.details.insufficientResId()), + textAlign = TextAlign.End, color = MaterialTheme.colorScheme.error, ) + choice.details.balanceDetails?.let { details -> + Text( + modifier = Modifier.padding(bottom = 3.dp), + text = stringResource( + R.string.payment_balance_available, + details.balanceAvailable.withSpec(choice.details.amountRaw.spec), + ), + ) + } } } else null, leading = { @@ -583,9 +596,7 @@ fun PaymentChoice( R.string.payment_tokens_insufficient, ) } else { - stringResource( - R.string.payment_balance_insufficient, - ) + stringResource(choice.details.insufficientResId()) }, ) } @@ -594,6 +605,16 @@ fun PaymentChoice( } } +/** + * The reason wallet-core gave for not being able to pay this choice, e.g. that + * the merchant does not accept the payment service, falling back to the plain + * "insufficient balance" when there is no more specific reason. + */ +@StringRes +private fun ChoiceSelectionDetail.insufficientResId(): Int = + (this as? InsufficientBalance)?.balanceDetails?.causeHint?.stringResId() + ?: R.string.payment_balance_insufficient + @Composable fun PaymentInput( input: ContractInput, @@ -898,7 +919,9 @@ private val contractTermsV1 = ContractTerms.V1( @Preview @Composable -fun PromptPaymentV0Preview() { +fun PromptPaymentV0Preview( + insufficientBalance: Boolean = false, +) { TalerSurface { PromptPaymentComposable(PayStatus.Choices( transactionId = "txn:payment:2309203920", @@ -909,7 +932,23 @@ fun PromptPaymentV0Preview() { amountRaw = Amount.fromJSONString("KUDOS:10"), inputs = listOf(), outputs = listOf(), - details = PaymentPossible( + details = if (insufficientBalance) { + InsufficientBalance( + amountRaw = Amount.fromJSONString("KUDOS:10"), + balanceDetails = PaymentInsufficientBalanceDetails( + causeHint = InsufficientBalanceHint.WalletBalanceAvailableInsufficient, + amountRequested = Amount.fromJSONString("KUDOS:10"), + balanceAvailable = Amount.fromJSONString("KUDOS:0.5"), + balanceMaterial = Amount.fromJSONString("KUDOS:0.5"), + balanceAgeAcceptable = Amount.fromJSONString("KUDOS:0.5"), + balanceReceiverAcceptable = Amount.fromJSONString("KUDOS:10"), + balanceReceiverDepositable = Amount.fromJSONString("KUDOS:10"), + balanceExchangeDepositable = Amount.fromJSONString("KUDOS:10"), + maxEffectiveSpendAmount = Amount.fromJSONString("KUDOS:10"), + perExchange = emptyMap(), + ) + ) + } else PaymentPossible( amountRaw = Amount.fromJSONString("KUDOS:10"), amountEffective = Amount.fromJSONString("KUDOS:10.2"), ), @@ -921,6 +960,12 @@ fun PromptPaymentV0Preview() { @Preview @Composable +fun PromptPaymentInsufficientV0Preview() { + PromptPaymentV0Preview(true) +} + +@Preview +@Composable fun PromptPaymentV1Preview() { TalerSurface { PromptPaymentComposable(PayStatus.Choices( diff --git a/wallet/src/main/res/values-de/strings.xml b/wallet/src/main/res/values-de/strings.xml @@ -24,6 +24,7 @@ <string name="payment_button_confirm">Zahlung bestätigen</string> <string name="payment_label_order_summary">Einkauf</string> <string name="payment_error">Fehler: %s</string> + <string name="payment_balance_available">Verfügbar: %1$s</string> <string name="payment_balance_insufficient">Guthaben unzureichend</string> <string name="payment_aborted">Abgebrochen</string> <string name="payment_failed">Fehlgeschlagen</string> diff --git a/wallet/src/main/res/values-fr/strings.xml b/wallet/src/main/res/values-fr/strings.xml @@ -31,6 +31,7 @@ <string name="nav_error">Erreur</string> <string name="button_back">Retour</string> <string name="payment_label_order_summary">Achat</string> + <string name="payment_balance_available">Disponible : %1$s</string> <string name="payment_balance_insufficient">Solde insuffisant !</string> <string name="payment_already_paid">Vous avez déjà payé pour cet achat.</string> <string name="withdraw_exchange">Prestataire</string> diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml @@ -283,6 +283,7 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish <string name="payment_already_paid">You\'ve already paid for this purchase.</string> <string name="payment_amount_total">Total: %1$s</string> <string name="payment_automatic_execution">This payment was automatically confirmed</string> + <string name="payment_balance_available">Available: %1$s</string> <string name="payment_balance_insufficient">Insufficient balance</string> <string name="payment_balance_insufficient_hint_age_restricted">Purchase not possible due to age restriction</string> <string name="payment_balance_insufficient_hint_exchange_missing_global_fees">Payment service is missing the global fee configuration, this likely means it is misconfigured</string>