taler-ios

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

commit 342c19f23582f54a289921466839a3f3b464255b
parent beba5a136653bfad17031f4e531d06988a7c84bb
Author: Marc Stibane <marc@taler.net>
Date:   Thu, 25 Jul 2024 14:25:19 +0200

Pass in currencyInfo

Diffstat:
MTalerWallet1/Views/Banking/ManualWithdraw.swift | 1+
MTalerWallet1/Views/Banking/ManualWithdrawDone.swift | 24++++++++++++++----------
MTalerWallet1/Views/HelperViews/SubjectInputV.swift | 2+-
MTalerWallet1/Views/Peer2peer/P2PReadyV.swift | 2++
MTalerWallet1/Views/Peer2peer/P2PSubjectV.swift | 1+
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift | 5++++-
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift | 5++++-
MTalerWallet1/Views/Sheets/Payment/PayTemplateV.swift | 20+++++++++++---------
MTalerWallet1/Views/Sheets/Payment/PaymentDone.swift | 2++
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 7++++++-
MTalerWallet1/Views/Sheets/Refund/RefundURIView.swift | 28++++++++++++++++++----------
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift | 24++++++++++++++----------
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift | 3+++
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift | 8++++++--
14 files changed, 87 insertions(+), 45 deletions(-)

diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -61,6 +61,7 @@ struct ManualWithdraw: View { // let _ = print(selectedAge, restrictAge) let destination = LazyView { ManualWithdrawDone(stack: stack.push(), + currencyInfo: currencyInfo, exchange: exchange, amountToTransfer: amountToTransfer) // restrictAge: restrictAge) diff --git a/TalerWallet1/Views/Banking/ManualWithdrawDone.swift b/TalerWallet1/Views/Banking/ManualWithdrawDone.swift @@ -12,7 +12,7 @@ import SymLog struct ManualWithdrawDone: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle = String(localized: "Wire Transfer") + let currencyInfo: CurrencyInfo let exchange: Exchange let amountToTransfer: Amount @@ -23,6 +23,8 @@ struct ManualWithdrawDone: View { @State private var acceptManualWithdrawalResult: AcceptManualWithdrawalResult? @State private var transactionId: String? + let navTitle = String(localized: "Wire Transfer") + func reloadOneAction(_ transactionId: String, viewHandles: Bool) async throws -> Transaction { return try await model.getTransactionByIdT(transactionId, viewHandles: viewHandles) } @@ -35,15 +37,16 @@ struct ManualWithdrawDone: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), - transactionId: transactionId, - reloadAction: reloadOneAction, - navTitle: navTitle, - hasDone: true, - abortAction: nil, - deleteAction: nil, - failAction: nil, - suspendAction: nil, - resumeAction: nil) + currencyInfo: currencyInfo, + transactionId: transactionId, + reloadAction: reloadOneAction, + navTitle: navTitle, + hasDone: true, + abortAction: nil, + deleteAction: nil, + failAction: nil, + suspendAction: nil, + resumeAction: nil) .navigationBarBackButtonHidden(true) .interactiveDismissDisabled() // can only use "Done" button to dismiss // .navigationTitle(navTitle) @@ -85,6 +88,7 @@ struct ManualWithdrawDone_Container : View { exchangeUpdateStatus: .initial, ageRestrictionOptions: []) ManualWithdrawDone(stack: CallStack("Preview"), + currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), exchange: exchange, amountToTransfer: amountToTransfer) } diff --git a/TalerWallet1/Views/HelperViews/SubjectInputV.swift b/TalerWallet1/Views/HelperViews/SubjectInputV.swift @@ -12,6 +12,7 @@ import SymLog struct SubjectInputV<TargetView: View>: View { private let symLog = SymLogV(0) let stack: CallStack + let currencyInfo: CurrencyInfo // the scanned URL let url: URL? let amountAvailable: Amount? // TODO: GetMaxPeerPushAmount @@ -21,7 +22,6 @@ struct SubjectInputV<TargetView: View>: View { // @Binding var insufficient: Bool // @Binding var feeAmount: Amount? let feeIsNotZero: Bool? // nil = no fees at all, false = no fee for this tx - let currencyInfo: CurrencyInfo var targetView: TargetView diff --git a/TalerWallet1/Views/Peer2peer/P2PReadyV.swift b/TalerWallet1/Views/Peer2peer/P2PReadyV.swift @@ -13,6 +13,7 @@ import SymLog struct P2PReadyV: View { private let symLog = SymLogV(0) let stack: CallStack + let currencyInfo: CurrencyInfo let summary: String let expireDays: UInt let amountToSend: Bool @@ -42,6 +43,7 @@ struct P2PReadyV: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), + currencyInfo: currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, diff --git a/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift @@ -113,6 +113,7 @@ struct P2PSubjectV: View { let disabled = (expireDays == 0) || (summary.count < 1) // TODO: check amountAvailable NavigationLink(destination: LazyView { P2PReadyV(stack: stack.push(), + currencyInfo: currencyInfo, summary: summary, expireDays: expireDays, amountToSend: amountToSend, diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift @@ -11,7 +11,7 @@ import SymLog struct P2pPayURIView: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle = String(localized: "Pay P2P", comment: "Nav Title") + let currencyInfo: CurrencyInfo // the scanned URL let url: URL @@ -23,6 +23,8 @@ struct P2pPayURIView: View { @State private var peerPullDebitResponse: PreparePeerPullDebitResponse? + let navTitle = String(localized: "Pay P2P", comment: "Nav Title") + var body: some View { VStack { if let peerPullDebitResponse { @@ -32,6 +34,7 @@ struct P2pPayURIView: View { let currency = raw.currencyStr let fee = try! Amount.diff(raw, effective) ThreeAmountsSection(stack: stack.push(), + currencyInfo: currencyInfo, topTitle: String(localized: "Amount to pay:"), topAbbrev: String(localized: "Pay:", comment: "mini"), topAmount: raw, fee: fee, diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -11,7 +11,7 @@ import SymLog struct P2pReceiveURIView: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle = String(localized: "P2P Receive") + let currencyInfo: CurrencyInfo // the scanned URL let url: URL @@ -25,6 +25,8 @@ struct P2pReceiveURIView: View { @State private var peerPushCreditResponse: PreparePeerPushCreditResponse? = nil @State private var exchange: Exchange? = nil + let navTitle = String(localized: "P2P Receive") + var body: some View { VStack { if let peerPushCreditResponse { @@ -42,6 +44,7 @@ struct P2pReceiveURIView: View { let currency = raw.currencyStr let fee = try! Amount.diff(raw, effective) ThreeAmountsSection(stack: stack.push(), + currencyInfo: currencyInfo, topTitle: String(localized: "Gross Amount to receive:"), topAbbrev: String(localized: "Receive gross:", comment: "mini"), topAmount: raw, fee: fee, diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -80,15 +80,13 @@ struct PayTemplateV: View { var body: some View { if let templateContract { // preparePayResult -// let effective = preparePayResult.amountEffective -// let baseURL = preparePayResult.contractTerms.exchanges.first?.url -// let raw = preparePayResult.amountRaw -// let currency = raw.currencyStr - let currencyInfo = controller.info(for: currencyName, controller.currencyTicker) + let currency = templateContract.currency ?? templateContract.amount?.currencyStr ?? "UNKNOWN" + let currencyInfo = controller.info(for: currency, controller.currencyTicker) let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to pay:") let finalDestinationI = LazyView { PaymentView(stack: stack.push(), + currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountToTransfer, @@ -98,6 +96,7 @@ struct PayTemplateV: View { } // final destination with amountToTransfer, after user input of amount let finalDestinationS = LazyView { PaymentView(stack: stack.push(), + currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountShortcut, @@ -107,7 +106,9 @@ struct PayTemplateV: View { } // final destination with amountShortcut, when user tapped a shortcut let inputDestination = LazyView { - SubjectInputV(stack: stack.push(), url: url, + SubjectInputV(stack: stack.push(), + currencyInfo: currencyInfo, + url: url, amountAvailable: nil, amountToTransfer: $amountToTransfer, amountLabel: amountLabel, @@ -115,11 +116,12 @@ struct PayTemplateV: View { // insufficient: $insufficient, // feeAmount: $feeAmount, feeIsNotZero: true, // TODO: feeIsNotZero() - currencyInfo: currencyInfo, targetView: finalDestinationI) } // destination to subject input let shortcutDestination = LazyView { - SubjectInputV(stack: stack.push(), url: url, + SubjectInputV(stack: stack.push(), + currencyInfo: currencyInfo, + url: url, amountAvailable: nil, amountToTransfer: $amountShortcut, amountLabel: amountLabel, @@ -127,7 +129,6 @@ struct PayTemplateV: View { // insufficient: $insufficient, // feeAmount: $feeAmount, feeIsNotZero: true, // TODO: feeIsNotZero() - currencyInfo: currencyInfo, targetView: finalDestinationS) }// destination to subject input, when user tapped an amount shortcut Group { @@ -172,6 +173,7 @@ struct PayTemplateV: View { } else { // both template contract amount and summary are fixed => directly show the payment // Attention: contains a List, thus mustn't be included in a ScrollView PaymentView(stack: stack.push(), + currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountToTransfer, diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift b/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift @@ -11,6 +11,7 @@ import SymLog struct PaymentDone: View { private let symLog = SymLogV(0) let stack: CallStack + let currencyInfo: CurrencyInfo let transactionId: String @EnvironmentObject private var controller: Controller @@ -31,6 +32,7 @@ struct PaymentDone: View { if paymentDone { let navTitle = String(localized: "Paid", comment: "Title, short") TransactionSummaryV(stack: stack.push(), + currencyInfo: currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -70,7 +70,7 @@ func templateFee(ppCheck: PreparePayResult?) -> Amount? { struct PaymentView: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle = String(localized: "Confirm Payment", comment:"pay merchant") + let currencyInfo: CurrencyInfo // the scanned URL let url: URL @@ -86,6 +86,8 @@ struct PaymentView: View { @State var preparePayResult: PreparePayResult? = nil + let navTitle = String(localized: "Confirm Payment", comment:"pay merchant") + var body: some View { Group { if let preparePayResult { @@ -103,6 +105,7 @@ struct PaymentView: View { // TODO: already paid let fee = try! Amount.diff(raw, effective) // TODO: different currencies ThreeAmountsSection(stack: stack.push(), + currencyInfo: currencyInfo, topTitle: topTitle, topAbbrev: topAbbrev, topAmount: raw, fee: fee, @@ -122,6 +125,7 @@ struct PaymentView: View { Text("You don't have enough \(currency).") .talerFont(.headline) ThreeAmountsSection(stack: stack.push(), + currencyInfo: currencyInfo, topTitle: topTitle, topAbbrev: topAbbrev, topAmount: raw, fee: nil, @@ -147,6 +151,7 @@ struct PaymentView: View { if let effective { NavigationLink(destination: LazyView { PaymentDone(stack: stack.push(), + currencyInfo: currencyInfo, transactionId: preparePayResult.transactionId) }) { Text(navTitle) // Confirm Payment diff --git a/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift @@ -15,27 +15,34 @@ struct RefundURIView: View { let url: URL @EnvironmentObject private var model: WalletModel + @EnvironmentObject private var controller: Controller // let navTitle = String(localized: "Refund", comment:"receive refund") @State var refundTransactionId: String? = nil + @State var transaction: Transaction? func reloadOneAction(_ transactionId: String, viewHandles: Bool) async throws -> Transaction { return try await model.getTransactionByIdT(transactionId, viewHandles: viewHandles) } var body: some View { - if let refundTransactionId { + if let refundTransactionId, let transaction { + let common = transaction.common + let raw = common.amountRaw + let currency = raw.currencyStr + let currencyInfo = controller.info(for: currency, controller.currencyTicker) TransactionSummaryV(stack: stack.push(), - transactionId: refundTransactionId, - reloadAction: reloadOneAction, - navTitle: nil, // navTitle, - hasDone: true, - abortAction: model.abortTransaction, - deleteAction: model.deleteTransaction, - failAction: model.failTransaction, - suspendAction: model.suspendTransaction, - resumeAction: model.resumeTransaction) + currencyInfo: currencyInfo, + transactionId: refundTransactionId, + reloadAction: reloadOneAction, + navTitle: nil, // navTitle, + hasDone: true, + abortAction: model.abortTransaction, + deleteAction: model.deleteTransaction, + failAction: model.failTransaction, + suspendAction: model.suspendTransaction, + resumeAction: model.resumeTransaction) .safeAreaInset(edge: .bottom) { Button("Done", action: { dismissTop(stack.push()) } ) // ViewState.shared.popToRootView ? .buttonStyle(TalerButtonStyle(type: .prominent)) @@ -47,6 +54,7 @@ struct RefundURIView: View { symLog.log(".task") if let result = try? await model.startRefundForUriM(url: url.absoluteString) { refundTransactionId = result + transaction = try? await model.getTransactionByIdM(result) } } } diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift @@ -12,7 +12,7 @@ import SymLog struct WithdrawAcceptDone: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle = String(localized: "Authorize with Bank", comment: "Nav title") + let currencyInfo: CurrencyInfo let exchangeBaseUrl: String? let url: URL @@ -24,6 +24,8 @@ struct WithdrawAcceptDone: View { @State private var transactionId: String? = nil @State private var transaction: Transaction? = nil + let navTitle = String(localized: "Authorize with Bank", comment: "Nav title") + func reloadOneAction(_ transactionId: String, viewHandles: Bool) async throws -> Transaction { let response = try await model.getTransactionByIdT(transactionId, viewHandles: viewHandles) transaction = response @@ -38,15 +40,16 @@ struct WithdrawAcceptDone: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), - transactionId: transactionId, - reloadAction: reloadOneAction, - navTitle: navTitle, - hasDone: true, - abortAction: nil, - deleteAction: nil, - failAction: nil, - suspendAction: nil, - resumeAction: nil) + currencyInfo: currencyInfo, + transactionId: transactionId, + reloadAction: reloadOneAction, + navTitle: navTitle, + hasDone: true, + abortAction: nil, + deleteAction: nil, + failAction: nil, + suspendAction: nil, + resumeAction: nil) .navigationBarBackButtonHidden(true) .interactiveDismissDisabled() // can only use "Done" button to dismiss .navigationTitle(navTitle) @@ -85,6 +88,7 @@ struct WithdrawAcceptDone: View { struct WithdrawAcceptDone_Previews: PreviewProvider { static var previews: some View { WithdrawAcceptDone(stack: CallStack("Preview"), + currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), exchangeBaseUrl: DEMOEXCHANGE, url: URL(string: DEMOSHOP)!, amountToTransfer: nil) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift @@ -12,6 +12,7 @@ import SymLog struct WithdrawAcceptView: View { private let symLog = SymLogV() let stack: CallStack + let currencyInfo: CurrencyInfo let navTitle = String(localized: "Withdrawal") // the URL from the bank website @@ -55,6 +56,7 @@ struct WithdrawAcceptView: View { let inColor = WalletColors().transactionColor(true) ThreeAmountsSection(stack: stack.push(), + currencyInfo: currencyInfo, topTitle: String(localized: "Chosen amount to withdraw:"), topAbbrev: String(localized: "Chosen:", comment: "mini"), topAmount: raw, fee: fee, @@ -79,6 +81,7 @@ struct WithdrawAcceptView: View { if tosAccepted { NavigationLink(destination: LazyView { WithdrawAcceptDone(stack: stack.push(), + currencyInfo: currencyInfo, exchangeBaseUrl: exchange.exchangeBaseUrl, url: url, amountToTransfer: amountToTransfer) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -99,13 +99,17 @@ struct WithdrawURIView: View { await loadExchange(defaultBaseUrl) } } // load defaultBaseUrl - let acceptDestination = WithdrawAcceptView(stack: stack.push(), url: url, + let acceptDestination = WithdrawAcceptView(stack: stack.push(), + currencyInfo: currencyInfo, + url: url, amountToTransfer: $amountToTransfer, exchange: $exchange) if amountIsEditable { ScrollView { let shortcutDestination = LazyView { - WithdrawAcceptView(stack: stack.push(), url: url, + WithdrawAcceptView(stack: stack.push(), + currencyInfo: currencyInfo, + url: url, amountToTransfer: $amountShortcut, exchange: $exchange) }