commit c4900c03c11e8b6e94cf948639d77345e2b34076
parent 0e0ef73c033989b5d0b46196247e8cfc2071fde7
Author: Iván Ávalos <avalos@disroot.org>
Date: Sun, 15 Sep 2024 13:39:55 +0200
[wallet] address FIXME and fix button label
bug 0009157
Diffstat:
3 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
@@ -93,6 +93,18 @@ data class TalerErrorInfo(
fun getStringExtra(key: String): String? =
extra[key]?.jsonPrimitive?.content
+
+ companion object {
+ fun makeCustomError(
+ message: String,
+ hint: String? = null,
+ code: TalerErrorCode = TalerErrorCode.UNKNOWN,
+ ) = TalerErrorInfo(
+ message = message,
+ hint = hint,
+ code = code,
+ )
+ }
}
class TalerErrorInfoSerializer : KSerializer<TalerErrorInfo> {
diff --git a/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt b/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt
@@ -184,10 +184,10 @@ fun ColumnScope.PeerPullTermsComposable(
) {
Text(
text = if (terms is IncomingTosReview) {
- stringResource(id = data.button)
- } else {
stringResource(id = R.string.exchange_tos_accept)
- },
+ } else {
+ stringResource(id = data.button)
+ }
)
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt b/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt
@@ -35,6 +35,7 @@ import net.taler.wallet.backend.TalerErrorCode.UNKNOWN
import net.taler.wallet.backend.TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE
import net.taler.wallet.backend.TalerErrorInfo
import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.cleanExchange
import net.taler.wallet.exchanges.ExchangeItem
import net.taler.wallet.exchanges.ExchangeManager
import net.taler.wallet.exchanges.ExchangeTosStatus
@@ -237,29 +238,38 @@ class PeerManager(
fun preparePeerPushCredit(talerUri: String) {
_incomingPushState.value = IncomingChecking
- scope.launch(Dispatchers.IO) {
+ scope.launch(Dispatchers.IO) a@ {
api.request("preparePeerPushCredit", PreparePeerPushCreditResponse.serializer()) {
put("talerUri", talerUri)
}.onSuccess { response ->
- scope.launch(Dispatchers.IO) {
- // FIXME: make sure that exchange gets added to wallet! handle null properly!
- exchangeManager.findExchangeByUrl(response.exchangeBaseUrl)?.let { exchange ->
- _incomingPushState.value = if (exchange.tosStatus == ExchangeTosStatus.Accepted) {
- IncomingTerms(
- amountRaw = response.amountRaw,
- amountEffective = response.amountEffective,
- contractTerms = response.contractTerms,
- id = response.transactionId,
- )
- } else {
- IncomingTosReview(
- amountRaw = response.amountRaw,
- amountEffective = response.amountEffective,
- contractTerms = response.contractTerms,
- exchangeBaseUrl = response.exchangeBaseUrl,
- id = response.transactionId,
+ scope.launch(Dispatchers.IO) b@ {
+ val exchange = exchangeManager.findExchangeByUrl(response.exchangeBaseUrl)
+
+ if (exchange == null) {
+ Log.d(TAG, "exchange entry for ${response.exchangeBaseUrl} was not found")
+ _incomingPushState.value = IncomingError(
+ TalerErrorInfo.makeCustomError( // TODO: localize error
+ "No provider with URL ${cleanExchange(response.exchangeBaseUrl)} was found in the wallet",
)
- }
+ )
+ return@b
+ }
+
+ _incomingPushState.value = if (exchange.tosStatus == ExchangeTosStatus.Accepted) {
+ IncomingTerms(
+ amountRaw = response.amountRaw,
+ amountEffective = response.amountEffective,
+ contractTerms = response.contractTerms,
+ id = response.transactionId,
+ )
+ } else {
+ IncomingTosReview(
+ amountRaw = response.amountRaw,
+ amountEffective = response.amountEffective,
+ contractTerms = response.contractTerms,
+ exchangeBaseUrl = response.exchangeBaseUrl,
+ id = response.transactionId,
+ )
}
}
}.onError { error ->