diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentComposable.kt index 3663d1d3..5fa03b37 100644 --- 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 @@ -94,6 +95,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 +205,18 @@ 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()), 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 +594,7 @@ fun PaymentChoice( R.string.payment_tokens_insufficient, ) } else { - stringResource( - R.string.payment_balance_insufficient, - ) + stringResource(choice.details.insufficientResId()) }, ) } @@ -594,6 +603,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, diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml index 89750709..484e5749 100644 --- 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 You\'ve already paid for this purchase. Total: %1$s This payment was automatically confirmed + Available: %1$s Insufficient balance Purchase not possible due to age restriction Payment service is missing the global fee configuration, this likely means it is misconfigured