From d9a578ad4a0b64f87c81d825d784ce14ce5778b2 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 6 Mar 2020 12:56:55 -0300 Subject: Show error screen when withdrawal fails --- .../main/java/net/taler/wallet/withdraw/WithdrawManager.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt') diff --git a/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt index 8179d8d..e3af757 100644 --- a/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -24,7 +24,6 @@ import net.taler.wallet.backend.WalletBackendApi import org.json.JSONObject sealed class WithdrawStatus { - object None : WithdrawStatus() data class Loading(val talerWithdrawUri: String) : WithdrawStatus() data class TermsOfServiceReviewRequired( val talerWithdrawUri: String, @@ -35,7 +34,6 @@ sealed class WithdrawStatus { val suggestedExchange: String ) : WithdrawStatus() - object Success : WithdrawStatus() data class ReceivedDetails( val talerWithdrawUri: String, val amount: Amount, @@ -43,11 +41,14 @@ sealed class WithdrawStatus { ) : WithdrawStatus() data class Withdrawing(val talerWithdrawUri: String) : WithdrawStatus() + + object Success : WithdrawStatus() + data class Error(val message: String?) : WithdrawStatus() } class WithdrawManager(private val walletBackendApi: WalletBackendApi) { - val withdrawStatus = MutableLiveData(WithdrawStatus.None) + val withdrawStatus = MutableLiveData() val testWithdrawalInProgress = MutableLiveData(false) private var currentWithdrawRequestId = 0 @@ -72,6 +73,8 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result -> if (isError) { Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}") + val message = if (result.has("message")) result.getString("message") else null + withdrawStatus.postValue(WithdrawStatus.Error(message)) return@sendRequest } if (myWithdrawRequestId != this.currentWithdrawRequestId) { @@ -104,6 +107,8 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result -> if (isError) { Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}") + val message = if (result.has("message")) result.getString("message") else null + withdrawStatus.postValue(WithdrawStatus.Error(message)) return@sendRequest } if (myWithdrawRequestId != this.currentWithdrawRequestId) { @@ -198,7 +203,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { fun cancelCurrentWithdraw() { currentWithdrawRequestId++ - withdrawStatus.value = WithdrawStatus.None + withdrawStatus.value = null } } -- cgit v1.2.3