diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-11-28 23:29:28 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-11-28 23:29:28 -0600 |
commit | a8af9f5f49d47511f4777ccbb8d63aad7c362de9 (patch) | |
tree | cc4c595b8f670946b416d0252132e1738e36f57c | |
parent | fa1c39de679f43529551ebabb1d68b61289751d2 (diff) | |
download | taler-android-a8af9f5f49d47511f4777ccbb8d63aad7c362de9.tar.gz taler-android-a8af9f5f49d47511f4777ccbb8d63aad7c362de9.tar.bz2 taler-android-a8af9f5f49d47511f4777ccbb8d63aad7c362de9.zip |
[wallet] DD36: replace paytoUri with new WithdrawalExchangeAccountDetails
4 files changed, 80 insertions, 14 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt index 0cd6d60..6dc079f 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt @@ -78,11 +78,11 @@ class TransactionWithdrawalFragment : TransactionDetailFragment(), ActionListene if (tx !is TransactionWithdrawal) return if (tx.withdrawalDetails !is ManualTransfer) return // TODO what if there's more than one or no URI? - if (tx.withdrawalDetails.exchangePaytoUris.isEmpty()) return + if (tx.withdrawalDetails.exchangeCreditAccounts?.isEmpty() != false) return val status = createManualTransferRequired( amount = tx.amountRaw, exchangeBaseUrl = tx.exchangeBaseUrl, - uriStr = tx.withdrawalDetails.exchangePaytoUris[0], + uriStr = tx.withdrawalDetails.exchangeCreditAccounts[0].paytoUri, transactionId = tx.transactionId, ) withdrawManager.viewManualWithdrawal(status) diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt index e7f17c0..6cd5602 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt @@ -182,12 +182,8 @@ sealed class WithdrawalDetails { @Serializable @SerialName("manual-transfer") class ManualTransfer( - /** - * Payto URIs that the exchange supports. - * - * Already contains the amount and message. - */ - val exchangePaytoUris: List<String>, + // TODO: rename to exchangeCreditAccountDetails in next wallet-core release + val exchangeCreditAccounts: List<WithdrawalExchangeAccountDetails>? = null, ) : WithdrawalDetails() @Serializable @@ -209,6 +205,61 @@ sealed class WithdrawalDetails { } @Serializable +data class WithdrawalExchangeAccountDetails ( + /** + * Payto URI to credit the exchange. + * + * Depending on whether the (manual!) withdrawal is accepted or just + * being checked, this already includes the subject with the + * reserve public key. + */ + val paytoUri: String, + + /** + * Transfer amount. Might be in a different currency than the requested + * amount for withdrawal. + * + * Redundant with the amount in paytoUri, just included to avoid parsing. + */ + val transferAmount: Amount? = null, + + /** + * Further restrictions for sending money to the + * exchange. + */ + val creditRestrictions: List<AccountRestriction>? = null, +) + +@Serializable +sealed class AccountRestriction { + @Serializable + @SerialName("deny") + data object DenyAllAccount: AccountRestriction() + + @Serializable + @SerialName("regex") + data class RegexAccount( + // Regular expression that the payto://-URI of the + // partner account must follow. The regular expression + // should follow posix-egrep, but without support for character + // classes, GNU extensions, back-references or intervals. See + // https://www.gnu.org/software/findutils/manual/html_node/find_html/posix_002degrep-regular-expression-syntax.html + // for a description of the posix-egrep syntax. Applications + // may support regexes with additional features, but exchanges + // must not use such regexes. + val paytoRegex: String, + + // Hint for a human to understand the restriction + // (that is hopefully easier to comprehend than the regex itself). + val humanHint: String, + + // Map from IETF BCP 47 language tags to localized + // human hints. + val humanHintI18n: Map<String, String>? = null, + ): AccountRestriction() +} + +@Serializable @SerialName("payment") class TransactionPayment( override val transactionId: String, diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt index 378e283..aab22d3 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/TransactionWithdrawalComposable.kt @@ -114,7 +114,7 @@ fun TransactionWithdrawalComposablePreview() { txState = TransactionState(Pending), txActions = listOf(Retry, Suspend, Abort), exchangeBaseUrl = "https://exchange.demo.taler.net/", - withdrawalDetails = ManualTransfer(exchangePaytoUris = emptyList()), + withdrawalDetails = ManualTransfer(exchangeCreditAccounts = emptyList()), amountRaw = Amount.fromString("TESTKUDOS", "42.23"), amountEffective = Amount.fromString("TESTKUDOS", "42.1337"), error = TalerErrorInfo(code = TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED), 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 90b8570..e18ab1a 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -33,6 +33,7 @@ import net.taler.wallet.backend.TalerErrorInfo import net.taler.wallet.backend.WalletBackendApi import net.taler.wallet.exchanges.ExchangeFees import net.taler.wallet.exchanges.ExchangeItem +import net.taler.wallet.transactions.WithdrawalExchangeAccountDetails import net.taler.wallet.withdraw.WithdrawStatus.ReceivedDetails sealed class WithdrawStatus { @@ -44,6 +45,8 @@ sealed class WithdrawStatus { val exchangeBaseUrl: String, val amountRaw: Amount, val amountEffective: Amount, + val numCoins: Int, + val withdrawalAccountList: List<WithdrawalExchangeAccountDetails>, val ageRestrictionOptions: List<Int>? = null, val tosText: String, val tosEtag: String, @@ -55,6 +58,8 @@ sealed class WithdrawStatus { val exchangeBaseUrl: String, val amountRaw: Amount, val amountEffective: Amount, + val numCoins: Int, + val withdrawalAccountList: List<WithdrawalExchangeAccountDetails>, val ageRestrictionOptions: List<Int>? = null, ) : WithdrawStatus() @@ -101,10 +106,12 @@ data class WithdrawalDetailsForUri( ) @Serializable -data class WithdrawalDetails( +data class ManualWithdrawalDetails( val tosAccepted: Boolean, val amountRaw: Amount, val amountEffective: Amount, + val numCoins: Int, + val withdrawalAccountList: List<WithdrawalExchangeAccountDetails>, val ageRestrictionOptions: List<Int>? = null, ) @@ -115,7 +122,9 @@ data class AcceptWithdrawalResponse( @Serializable data class AcceptManualWithdrawalResponse( - val exchangePaytoUris: List<String>, + val reservePub: String, + val withdrawalAccountsList: List<WithdrawalExchangeAccountDetails>, + val transactionId: String, ) data class ExchangeSelection( @@ -176,7 +185,7 @@ class WithdrawManager( uri: String? = null, ) = scope.launch { withdrawStatus.value = WithdrawStatus.Loading(uri) - api.request("getWithdrawalDetailsForAmount", WithdrawalDetails.serializer()) { + api.request("getWithdrawalDetailsForAmount", ManualWithdrawalDetails.serializer()) { put("exchangeBaseUrl", exchangeBaseUrl) put("amount", amount.toJSONString()) }.onError { error -> @@ -188,6 +197,8 @@ class WithdrawManager( exchangeBaseUrl = exchangeBaseUrl, amountRaw = details.amountRaw, amountEffective = details.amountEffective, + numCoins = details.numCoins, + withdrawalAccountList = details.withdrawalAccountList, ageRestrictionOptions = details.ageRestrictionOptions, ) } else getExchangeTos(exchangeBaseUrl, details, showTosImmediately, uri) @@ -196,7 +207,7 @@ class WithdrawManager( private fun getExchangeTos( exchangeBaseUrl: String, - details: WithdrawalDetails, + details: ManualWithdrawalDetails, showImmediately: Boolean, uri: String?, ) = scope.launch { @@ -210,6 +221,8 @@ class WithdrawManager( exchangeBaseUrl = exchangeBaseUrl, amountRaw = details.amountRaw, amountEffective = details.amountEffective, + numCoins = details.numCoins, + withdrawalAccountList = details.withdrawalAccountList, ageRestrictionOptions = details.ageRestrictionOptions, tosText = it.content, tosEtag = it.currentEtag, @@ -234,6 +247,8 @@ class WithdrawManager( exchangeBaseUrl = s.exchangeBaseUrl, amountRaw = s.amountRaw, amountEffective = s.amountEffective, + numCoins = s.numCoins, + withdrawalAccountList = s.withdrawalAccountList, ageRestrictionOptions = s.ageRestrictionOptions, ) } @@ -278,7 +293,7 @@ class WithdrawManager( amount = status.amountRaw, exchangeBaseUrl = status.exchangeBaseUrl, // TODO what if there's more than one or no URI? - uriStr = response.exchangePaytoUris[0], + uriStr = response.withdrawalAccountsList[0].paytoUri, ) } } |