From 874b52c6d5c0d8043f3250e2b80f5091c159ded1 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 8 Apr 2020 14:21:11 -0300 Subject: [wallet] add option to see exchange's fee structure --- .../net/taler/wallet/withdraw/WithdrawManager.kt | 42 +++++++--------------- 1 file changed, 13 insertions(+), 29 deletions(-) (limited to 'wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt') diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt index 26515a5..6bcd013 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -28,19 +28,18 @@ sealed class WithdrawStatus { data class Loading(val talerWithdrawUri: String) : WithdrawStatus() data class TermsOfServiceReviewRequired( val talerWithdrawUri: String, - val exchangeBaseUrl: String, + val exchange: String, val tosText: String, val tosEtag: String, val amount: Amount, - val fee: Amount, - val suggestedExchange: String + val fee: Amount ) : WithdrawStatus() data class ReceivedDetails( val talerWithdrawUri: String, + val exchange: String, val amount: Amount, - val fee: Amount, - val suggestedExchange: String + val fee: Amount ) : WithdrawStatus() data class Withdrawing(val talerWithdrawUri: String) : WithdrawStatus() @@ -54,7 +53,8 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { val withdrawStatus = MutableLiveData() val testWithdrawalInProgress = MutableLiveData(false) - private var currentWithdrawRequestId = 0 + var exchangeFees: ExchangeFees? = null + private set fun withdrawTestkudos() { testWithdrawalInProgress.value = true @@ -70,9 +70,6 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { } withdrawStatus.value = WithdrawStatus.Loading(talerWithdrawUri) - this.currentWithdrawRequestId++ - val myWithdrawRequestId = this.currentWithdrawRequestId - walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result -> if (isError) { Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}") @@ -80,11 +77,6 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { withdrawStatus.postValue(WithdrawStatus.Error(message)) return@sendRequest } - if (myWithdrawRequestId != this.currentWithdrawRequestId) { - val mismatch = "$myWithdrawRequestId != ${this.currentWithdrawRequestId}" - Log.w(TAG, "Got withdraw result for different request id $mismatch") - return@sendRequest - } Log.v(TAG, "got getWithdrawDetailsForUri result") val status = withdrawStatus.value if (status !is WithdrawStatus.Loading) { @@ -105,9 +97,6 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { put("selectedExchange", selectedExchange) } - currentWithdrawRequestId++ - val myWithdrawRequestId = currentWithdrawRequestId - walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result -> if (isError) { Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}") @@ -115,11 +104,6 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { withdrawStatus.postValue(WithdrawStatus.Error(message)) return@sendRequest } - if (myWithdrawRequestId != currentWithdrawRequestId) { - val mismatch = "$myWithdrawRequestId != $currentWithdrawRequestId" - Log.w(TAG, "Got withdraw result for different request id $mismatch") - return@sendRequest - } Log.v(TAG, "got getWithdrawDetailsForUri result (with exchange details)") val status = withdrawStatus.value if (status !is WithdrawStatus.Loading) { @@ -127,12 +111,13 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { return@sendRequest } val wi = result.getJSONObject("bankWithdrawDetails") - val suggestedExchange = wi.getString("suggestedExchange") val amount = Amount.fromJsonObject(wi.getJSONObject("amount")) val ei = result.getJSONObject("exchangeWithdrawDetails") val termsOfServiceAccepted = ei.getBoolean("termsOfServiceAccepted") + exchangeFees = ExchangeFees.fromExchangeWithdrawDetailsJson(ei) + val withdrawFee = Amount.fromJsonObject(ei.getJSONObject("withdrawFee")) val overhead = Amount.fromJsonObject(ei.getJSONObject("overhead")) val fee = withdrawFee + overhead @@ -145,16 +130,15 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { WithdrawStatus.TermsOfServiceReviewRequired( status.talerWithdrawUri, selectedExchange, tosText, tosEtag, - amount, fee, - suggestedExchange + amount, fee ) ) } else { withdrawStatus.postValue( ReceivedDetails( status.talerWithdrawUri, - amount, fee, - suggestedExchange + selectedExchange, amount, + fee ) ) } @@ -191,7 +175,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { check(s is WithdrawStatus.TermsOfServiceReviewRequired) val args = JSONObject().apply { - put("exchangeBaseUrl", s.exchangeBaseUrl) + put("exchangeBaseUrl", s.exchange) put("etag", s.tosEtag) } walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) { isError, result -> @@ -199,7 +183,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { Log.e(TAG, "Error acceptExchangeTermsOfService ${result.toString(4)}") return@sendRequest } - val status = ReceivedDetails(s.talerWithdrawUri, s.amount, s.fee, s.suggestedExchange) + val status = ReceivedDetails(s.talerWithdrawUri, s.exchange, s.amount, s.fee) withdrawStatus.postValue(status) } } -- cgit v1.2.3