commit d012270b571e069fa0203c45f45bbd780da088fe parent 8c29dac8af252a7e9128f27b2e1d53a6058554ab Author: Iván Ávalos <avalos@disroot.org> Date: Thu, 23 Jul 2026 00:14:08 +0200 [wallet] don't calculate balance on template edit screen Diffstat:
7 files changed, 17 insertions(+), 44 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt @@ -230,6 +230,7 @@ class MainViewModel( mViewMode.value = ViewMode.Transactions(scopeInfo, stateFilter = stateFilter) } + // FIXME: get rid of this ugliness! use wallet-core! @UiThread fun createAmount(amountText: String, currency: String, incoming: Boolean = false): AmountResult { val amount = try { diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt @@ -34,6 +34,7 @@ import net.taler.common.Amount import net.taler.common.CurrencySpecification import net.taler.wallet.main.AmountResult import net.taler.wallet.R +import net.taler.wallet.balances.ScopeInfo import net.taler.wallet.compose.LoadingScreen import net.taler.wallet.compose.TalerSurface import net.taler.wallet.systemBarsPaddingBottom @@ -43,9 +44,7 @@ fun PayTemplateComposable( currencies: List<String>, payStatus: PayStatus, getCurrencySpec: (String) -> CurrencySpecification?, - onCreateAmount: (String, String) -> AmountResult, onSubmit: (params: TemplateParams) -> Unit, - onError: (msg: String) -> Unit, onRetry: (() -> Unit)? = null, ) { if (currencies.isEmpty()) { @@ -62,8 +61,6 @@ fun PayTemplateComposable( PayTemplateOrderComposable( usableCurrencies = usableCurrencies, templateDetails = p.details, - onCreateAmount = onCreateAmount, - onError = onError, onSubmit = onSubmit, getCurrencySpec = getCurrencySpec, ) @@ -131,11 +128,7 @@ fun PayTemplateLoadingPreview() { PayTemplateComposable( payStatus = PayStatus.Loading, currencies = listOf("KUDOS", "ARS"), - onCreateAmount = { text, currency -> - AmountResult.Success(amount = Amount.fromString(currency, text)) - }, onSubmit = { _ -> }, - onError = { _ -> }, getCurrencySpec = { null }, ) } @@ -148,11 +141,7 @@ fun PayTemplateNoCurrenciesPreview() { PayTemplateComposable( payStatus = PayStatus.None, currencies = emptyList(), - onCreateAmount = { text, currency -> - AmountResult.Success(amount = Amount.fromString(currency, text)) - }, onSubmit = { _ -> }, - onError = { _ -> }, getCurrencySpec = { null }, ) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt @@ -26,12 +26,14 @@ enum class TemplateType { @SerialName("fixed-order") FixedOrder, + @Suppress("unused") @SerialName("inventory-cart") InventoryCart, @SerialName("paivana") Paivana, + @Suppress("unused") Unknown, } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt @@ -40,7 +40,6 @@ import androidx.compose.ui.unit.dp import net.taler.common.Amount import net.taler.common.CurrencySpecification import net.taler.common.RelativeTime -import net.taler.wallet.main.AmountResult import net.taler.wallet.BottomInsetsSpacer import net.taler.wallet.R import net.taler.wallet.compose.AmountCurrencyField @@ -50,9 +49,7 @@ import net.taler.wallet.compose.TalerSurface fun PayTemplateOrderComposable( usableCurrencies: List<String>, // non-empty intersection between the stored currencies and the ones supported by the merchant templateDetails: WalletTemplateDetails, - onCreateAmount: (String, String) -> AmountResult, getCurrencySpec: (String) -> CurrencySpecification?, - onError: (msg: String) -> Unit, onSubmit: (params: TemplateParams) -> Unit, ) { val defaultSummary = templateDetails.defaultSummary @@ -71,9 +68,6 @@ fun PayTemplateOrderComposable( getCurrencySpec(amount.currency) } - val balanceInsufficientError = stringResource(R.string.payment_balance_insufficient) - val amountInvalidError = stringResource(R.string.amount_invalid) - Column(horizontalAlignment = End) { OutlinedTextField( modifier = Modifier @@ -106,15 +100,10 @@ fun PayTemplateOrderComposable( modifier = Modifier.padding(16.dp), enabled = !templateDetails.isSummaryEditable() || summary.isNotBlank(), onClick = { - when (val res = onCreateAmount(amount.amountStr, amount.currency)) { - is AmountResult.InsufficientBalance -> onError(balanceInsufficientError) - is AmountResult.InvalidAmount -> onError(amountInvalidError) - // NOTE: it is important to nullify non-editable values! - is AmountResult.Success -> onSubmit(TemplateParams( - summary = if (templateDetails.isSummaryEditable()) summary else null, - amount = if(templateDetails.isAmountEditable()) res.amount else null, - )) - } + onSubmit(TemplateParams( + summary = if (templateDetails.isSummaryEditable()) summary else null, + amount = if(templateDetails.isAmountEditable()) amount else null, + )) }, ) { Text(stringResource(R.string.payment_create_order)) @@ -171,11 +160,7 @@ fun PayTemplateDefaultPreview() { PayTemplateOrderComposable( templateDetails = defaultTemplateDetails, usableCurrencies = listOf("KUDOS", "ARS"), - onCreateAmount = { text, currency -> - AmountResult.Success(amount = Amount.fromString(currency, text)) - }, onSubmit = { _ -> }, - onError = { }, getCurrencySpec = { null }, ) } @@ -188,11 +173,7 @@ fun PayTemplateFixedAmountPreview() { PayTemplateOrderComposable( templateDetails = fixedAmountDetails, usableCurrencies = listOf("KUDOS", "ARS"), - onCreateAmount = { text, currency -> - AmountResult.Success(amount = Amount.fromString(currency, text)) - }, onSubmit = { _ -> }, - onError = { }, getCurrencySpec = { null }, ) } @@ -205,11 +186,7 @@ fun PayTemplateBlankSubjectPreview() { PayTemplateOrderComposable( templateDetails = blankSubjectDetails, usableCurrencies = listOf("KUDOS", "ARS"), - onCreateAmount = { text, currency -> - AmountResult.Success(amount = Amount.fromString(currency, text)) - }, onSubmit = { _ -> }, - onError = { }, getCurrencySpec = { null }, ) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateScreen.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateScreen.kt @@ -115,13 +115,9 @@ fun PayTemplateScreen( is BalanceState.Success -> PayTemplateComposable( currencies = state.balances.map { it.currency }, payStatus = payStatus, - onCreateAmount = model::createAmount, onSubmit = { params -> scope.launch { prepareTemplate(uri, params) } }, - onError = { errorMsg -> - onShowError(TalerErrorInfo.makeCustomError(errorMsg)) - }, onRetry = { retryTrigger++ }, getCurrencySpec = exchangeManager::getSpecForCurrency, ) diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -144,7 +144,11 @@ class PaymentManager( res.contractTerms.exchanges.map { ScopeInfo.Exchange(choice.amountRaw.currency, it.url) }, - ) ?: exchangeManager.getSpecForCurrency(choice.amountRaw.currency) + ) ?: res.contractTerms.exchanges.firstOrNull()?.let { + exchangeManager.getSpecForScopeInfo( + ScopeInfo.Exchange(choice.amountRaw.currency, it.url) + ) + } when (choice) { is PaymentPossible -> { diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt @@ -40,6 +40,7 @@ import net.taler.wallet.payment.InsufficientBalanceHint.WalletBalanceMaterialIns @JsonClassDiscriminator("status") sealed class PreparePayResponse { + @Suppress("unused") @Serializable @SerialName("payment-possible") data class PaymentPossibleResponse( @@ -47,6 +48,7 @@ sealed class PreparePayResponse { val contractTerms: ContractTerms, ) : PreparePayResponse() + @Suppress("unused") @Serializable @SerialName("insufficient-balance") data class InsufficientBalanceResponse( @@ -56,6 +58,7 @@ sealed class PreparePayResponse { val balanceDetails: PaymentInsufficientBalanceDetails, ) : PreparePayResponse() + @Suppress("unused") @Serializable @SerialName("already-confirmed") data class AlreadyConfirmedResponse( @@ -69,6 +72,7 @@ sealed class PreparePayResponse { val contractTerms: ContractTerms, ) : PreparePayResponse() + @Suppress("unused") @Serializable @SerialName("choice-selection") data class ChoiceSelection(