taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit f00e31a43cbedc2cabaf4d82bfbe94e1d540f8b0
parent d0d5a75042078fc71f1c36956ce9344b82d27b74
Author: Marc Stibane <marc@taler.net>
Date:   Fri,  1 Dec 2023 21:34:52 +0100

Preparation for withdraw-exchange

Diffstat:
MTalerWallet1/Controllers/Controller.swift | 17++++++++++-------
MTalerWallet1/Model/Model+Withdraw.swift | 21+++++++++++++++++++--
MTalerWallet1/Views/Exchange/ExchangeRowView.swift | 1+
MTalerWallet1/Views/Exchange/ManualWithdraw.swift | 21++++++++++++++-------
MTalerWallet1/Views/Sheets/URLSheet.swift | 4++++
5 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -20,6 +20,7 @@ enum BackendState { enum UrlCommand { case unknown case withdraw + case withdrawExchange case pay case payPull case payPush @@ -158,20 +159,22 @@ extension Controller { } switch command { case "withdraw": - return UrlCommand.withdraw + return .withdraw + case "withdraw-exchange": + return .withdrawExchange case "pay": - return UrlCommand.pay + return .pay case "pay-pull": - return UrlCommand.payPull + return .payPull case "pay-push": - return UrlCommand.payPush + return .payPush case "pay-template": - return UrlCommand.payTemplate + return .payTemplate case "refund": - return UrlCommand.refund + return .refund default: symLog.log("unknown command taler://\(command)") } - return UrlCommand.unknown + return .unknown } } diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift @@ -7,6 +7,21 @@ import taler_swift import SymLog fileprivate let ASYNCDELAY: UInt = 0 //set e.g to 6 or 9 seconds for debugging +enum AccountRestrictionType: String, Decodable { + case deny + case regex +} +struct AccountRestriction: Decodable { + var type: AccountRestrictionType + var payto_regex: String? + var human_hint: String? + var human_hint_i18n: String? +} +struct WithdrawalExchangeAccountDetails: Decodable { + var paytoUri: String + var transferAmount: Amount + var creditRestrictions: [AccountRestriction]? +} // MARK: - /// The result from getWithdrawalDetailsForUri struct WithdrawUriInfoResponse: Decodable { @@ -31,9 +46,10 @@ struct WithdrawalAmountDetails: Decodable { var tosAccepted: Bool // Did the user accept the current version of the exchange's terms of service? var amountRaw: Amount // Amount that the user will transfer to the exchange var amountEffective: Amount // Amount that will be added to the user's wallet balance - var paytoUris: [String] // Ways to pay the exchange - var ageRestrictionOptions: [Int]? // Array of ages var numCoins: Int? // Number of coins this amountEffective will create + var withdrawalAccountsList: [WithdrawalExchangeAccountDetails]? + var ageRestrictionOptions: [Int]? // Array of ages + var scopeInfo: ScopeInfo } /// A request to get an exchange's withdrawal details. fileprivate struct GetWithdrawalDetailsForAmount: WalletBackendFormattedRequest { @@ -117,6 +133,7 @@ fileprivate struct AcceptBankIntegratedWithdrawal: WalletBackendFormattedRequest struct AcceptManualWithdrawalResult: Decodable { var reservePub: String var exchangePaytoUris: [String] + var withdrawalAccountsList: [WithdrawalExchangeAccountDetails] var transactionId: String } /// A request to accept a manual withdrawl. diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Exchange/ExchangeRowView.swift @@ -49,6 +49,7 @@ struct ExchangeRowView: View { ) { EmptyView() }.frame(width: 0).opacity(0) NavigationLink(destination: LazyView { ManualWithdraw(stack: stack.push(), +// url: nil, exchange: exchange, amountToTransfer: $amountToTransfer) }, tag: 2, selection: $buttonSelected diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift b/TalerWallet1/Views/Exchange/ManualWithdraw.swift @@ -11,6 +11,8 @@ struct ManualWithdraw: View { private let symLog = SymLogV(0) let stack: CallStack +// let url: URL? +// let exchange: Exchange? let exchange: Exchange @Binding var amountToTransfer: Amount @@ -102,13 +104,9 @@ struct ManualWithdraw: View { struct ManualWithdraw_Previews: PreviewProvider { struct StateContainer : View { @State private var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 510) - @State private var details = WithdrawalAmountDetails(tosAccepted: false, - amountRaw: Amount(currency: LONGCURRENCY, cent: 510), - amountEffective: Amount(currency: LONGCURRENCY, cent: 500), - paytoUris: [], - ageRestrictionOptions: [], - numCoins: 6) - var body: some View { + + var body: some View { + let scopeInfo = ScopeInfo(type: ScopeInfo.ScopeInfoType.exchange, url: DEMOEXCHANGE, currency: LONGCURRENCY) let exchange = Exchange(exchangeBaseUrl: DEMOEXCHANGE, currency: LONGCURRENCY, paytoUris: [], @@ -116,7 +114,16 @@ struct ManualWithdraw_Previews: PreviewProvider { exchangeEntryStatus: .preset, exchangeUpdateStatus: .initial, ageRestrictionOptions: []) + let details = WithdrawalAmountDetails(tosAccepted: false, + amountRaw: Amount(currency: LONGCURRENCY, cent: 510), + amountEffective: Amount(currency: LONGCURRENCY, cent: 500), + numCoins: 6, +// paytoUris: [], + withdrawalAccountsList: [], + ageRestrictionOptions: [], + scopeInfo: scopeInfo) ManualWithdraw(stack: CallStack("Preview"), +// url: nil, exchange: exchange, amountToTransfer: $amountToTransfer, withdrawalAmountDetails: details) diff --git a/TalerWallet1/Views/Sheets/URLSheet.swift b/TalerWallet1/Views/Sheets/URLSheet.swift @@ -3,6 +3,7 @@ * See LICENSE.md */ import SwiftUI +import taler_swift import SymLog struct URLSheet: View { @@ -12,6 +13,7 @@ struct URLSheet: View { var urlToOpen: URL @EnvironmentObject private var controller: Controller + @State private var amountToTransfer = Amount.zero(currency: "") var body: some View { #if DEBUG @@ -24,6 +26,8 @@ struct URLSheet: View { switch urlCommand { case .withdraw: WithdrawURIView(stack: stack.push(), url: urlToOpen) +// case .withdrawExchange: +// ManualWithdraw(stack: stack.push(), url: urlToOpen, exchange: nil, amountToTransfer: $amountToTransfer) case .pay: PaymentView(stack: stack.push(), url: urlToOpen) case .payPull: