taler-ios

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

commit 9c5ca31f3c96263de61a8e9a27f7f96e0dca94e4
parent 48649dd68f942243a837504dceb3b2ccbdb44907
Author: Marc Stibane <marc@taler.net>
Date:   Thu, 11 Dec 2025 22:51:00 +0100

refactor

Diffstat:
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift | 2++
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift | 108++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
3 files changed, 155 insertions(+), 79 deletions(-)

diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift @@ -14,6 +14,7 @@ struct P2pAcceptDone: View { private let symLog = SymLogV(0) let stack: CallStack + let url: URL? let transactionId: String let incoming: Bool @@ -57,6 +58,7 @@ struct P2pAcceptDone: View { struct P2pAcceptDone_Previews: PreviewProvider { static var previews: some View { P2pAcceptDone(stack: CallStack("Preview"), + url: URL("taler://nothing"), transactionId: "some ID", incoming: true) } diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift @@ -20,9 +20,6 @@ struct P2pPayURIView: View { @EnvironmentObject private var model: WalletModel @EnvironmentObject private var controller: Controller - @Environment(\.colorScheme) private var colorScheme - @Environment(\.colorSchemeContrast) private var colorSchemeContrast - @AppStorage("minimalistic") var minimalistic: Bool = false @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @State private var peerPullDebitResponse: PreparePeerPullDebitResponse? @@ -33,7 +30,8 @@ struct P2pPayURIView: View { private func viewDidLoad() async { do { symLog.log(".task") - peerPullDebitResponse = try? await model.preparePeerPullDebit(url.absoluteString) + let response = try? await model.preparePeerPullDebit(url.absoluteString) + peerPullDebitResponse = response } } @@ -41,35 +39,13 @@ struct P2pPayURIView: View { VStack { if let peerPullDebitResponse { List { - let raw = peerPullDebitResponse.amountRaw - let effective = peerPullDebitResponse.amountEffective - let scope = peerPullDebitResponse.scopeInfo - let currency = raw.currencyStr - let fee = try! Amount.diff(raw, effective) - ThreeAmountsSection(stack: stack.push(), - scope: scope, - topTitle: String(localized: "Amount to pay:"), - topAbbrev: String(localized: "Pay:", comment: "mini"), - topAmount: raw, - noFees: nil, // TODO: check baseURL for fees - fee: fee, - bottomTitle: String(localized: "Amount to be spent:"), - bottomAbbrev: String(localized: "Effective:", comment: "mini"), - bottomAmount: effective, - large: false, pending: false, incoming: false, - baseURL: nil, - txStateLcl: nil, - summary: peerPullDebitResponse.contractTerms.summary, - merchant: nil, - products: nil) + PeerPullDebitView(stack: stack.push(), + raw: peerPullDebitResponse.amountRaw, + effective: peerPullDebitResponse.amountEffective, + scope: peerPullDebitResponse.scopeInfo, + summary: peerPullDebitResponse.contractTerms.summary) let expiration = peerPullDebitResponse.contractTerms.purse_expiration - let (dateString, date) = TalerDater.dateString(expiration, minimalistic) - let a11yDate = TalerDater.accessibilityDate(date) ?? dateString - let a11yLabel = String(localized: "Expires: \(a11yDate)", comment: "a11y") - Text("Expires: \(dateString)") - .talerFont(.body) - .accessibilityLabel(a11yLabel) - .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) + ExpiresView(expiration: expiration) } .listStyle(myListStyle.style).anyView .navigationTitle(navTitle) @@ -78,14 +54,14 @@ struct P2pPayURIView: View { // currencyInfo = controller.info2(for: currency, controller.currencyTicker) // } .safeAreaInset(edge: .bottom) { - let destination = P2pAcceptDone(stack: stack.push(), - transactionId: peerPullDebitResponse.transactionId, - incoming: false) - NavigationLink(destination: destination) { - Text("Confirm Payment", comment:"pay P2P request/invoice") // SHEET_PAY_P2P + if peerPullDebitResponse.txState.isConfirmed { + Button("Done") { dismissTop(stack.push()) } + .buttonStyle(TalerButtonStyle(type: .prominent)) + .padding(.horizontal) + } else { + PeerPullDebitConfirm(stack: stack.push(), url: url, + transactionId: peerPullDebitResponse.transactionId) } - .buttonStyle(TalerButtonStyle(type: .prominent)) - .padding(.horizontal) } } else { #if DEBUG @@ -107,3 +83,57 @@ struct P2pPayURIView: View { //#Preview { // P2pPayURIView(url: <#T##URL#>, model: <#T##WalletModel#>) //} +// MARK: - +struct PeerPullDebitConfirm: View { + let stack: CallStack + let url: URL? + let transactionId: String + + var body: some View { + let destination = P2pAcceptDone(stack: stack.push(), + url: url, + transactionId: transactionId, + incoming: false) + NavigationLink(destination: destination) { + Text("Confirm Payment", comment:"pay P2P request/invoice") // SHEET_PAY_P2P + } + .buttonStyle(TalerButtonStyle(type: .prominent)) + .padding(.horizontal) + } +} +// MARK: - +struct PeerPullDebitView: View { + let stack: CallStack +// let peerPullDebitResponse: PreparePeerPullDebitResponse + let raw: Amount + let effective: Amount + let scope: ScopeInfo? + let summary: String + + @Environment(\.colorScheme) private var colorScheme + @Environment(\.colorSchemeContrast) private var colorSchemeContrast + @AppStorage("minimalistic") var minimalistic: Bool = false + var body: some View { +// let raw = peerPullDebitResponse.amountRaw +// let effective = peerPullDebitResponse.amountEffective +// let scope = peerPullDebitResponse.scopeInfo + let currency = raw.currencyStr + let fee = try! Amount.diff(raw, effective) + ThreeAmountsSection(stack: stack.push(), + scope: scope, + topTitle: String(localized: "Amount to pay:"), + topAbbrev: String(localized: "Pay:", comment: "mini"), + topAmount: raw, + noFees: nil, // TODO: check baseURL for fees + fee: fee, + bottomTitle: String(localized: "Amount to be spent:"), + bottomAbbrev: String(localized: "Effective:", comment: "mini"), + bottomAmount: effective, + large: false, pending: false, incoming: false, + baseURL: nil, + txStateLcl: nil, + summary: summary, + merchant: nil, + products: nil) + } +} diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -77,34 +77,12 @@ struct P2pReceiveURIView: View { acceptAction: nil) } List { - let raw = peerPushCreditResponse.amountRaw - let effective = peerPushCreditResponse.amountEffective - let currency = raw.currencyStr - let fee = try! Amount.diff(raw, effective) - ThreeAmountsSection(stack: stack.push(), - scope: peerPushCreditResponse.scopeInfo, - topTitle: String(localized: "Gross Amount to receive:"), - topAbbrev: String(localized: "Receive gross:", comment: "mini"), - topAmount: raw, - noFees: nil, // TODO: check baseURL for fees - fee: fee, - bottomTitle: String(localized: "Net Amount to receive:"), - bottomAbbrev: String(localized: "Receive net:", comment: "mini"), - bottomAmount: effective, - large: false, pending: false, incoming: true, - baseURL: nil, - txStateLcl: nil, - summary: peerPushCreditResponse.contractTerms.summary, - merchant: nil, - products: nil) - let expiration = peerPushCreditResponse.contractTerms.purse_expiration - let (dateString, date) = TalerDater.dateString(expiration, minimalistic) - let a11yDate = TalerDater.accessibilityDate(date) ?? dateString - let a11yLabel = String(localized: "Expires: \(a11yDate)", comment: "a11y") - Text("Expires: \(dateString)") - .talerFont(.body) - .accessibilityLabel(a11yLabel) - .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) + PeerPushCreditView(stack: stack.push(), + raw: peerPushCreditResponse.amountRaw, + effective: peerPushCreditResponse.amountEffective, + scope: peerPushCreditResponse.scopeInfo, + summary: peerPushCreditResponse.contractTerms.summary) + ExpiresView(expiration: peerPushCreditResponse.contractTerms.purse_expiration) } .listStyle(myListStyle.style).anyView .navigationTitle(navTitle) @@ -113,19 +91,16 @@ struct P2pReceiveURIView: View { currencyInfo = controller.info2(for: currency, controller.currencyTicker) } .safeAreaInset(edge: .bottom) { - if tosAccepted { - let destination = P2pAcceptDone(stack: stack.push(), - transactionId: peerPushCreditResponse.transactionId, - incoming: true) - let actions = Group { - NavLink($accept) { destination } + if peerPushCreditResponse.txState.isConfirmed { + Button("Done") { dismissTop(stack.push()) } + .buttonStyle(TalerButtonStyle(type: .prominent)) + .padding(.horizontal) + } else { + if tosAccepted { + PeerPushCreditAccept(stack: stack.push(), url: url, + transactionId: peerPushCreditResponse.transactionId, + accept: $accept) } - Button("Accept and receive") { // SHEET_RCV_P2P_ACCEPT - accept = true - } - .background(actions) - .buttonStyle(TalerButtonStyle(type: .prominent)) - .padding(.horizontal) } } #if OIM && DEBUG @@ -157,3 +132,72 @@ struct P2pReceiveURIView: View { } } } +// MARK: - +struct PeerPushCreditAccept: View { + let stack: CallStack + let url: URL? + let transactionId: String + @Binding var accept: Bool // triggers 'destination' when set true + + var body: some View { + let destination = P2pAcceptDone(stack: stack.push(), + url: url, + transactionId: transactionId, + incoming: true) + let actions = Group { + NavLink($accept) { destination } + } + Button("Accept and receive") { // SHEET_RCV_P2P_ACCEPT + accept = true + } + .background(actions) + .buttonStyle(TalerButtonStyle(type: .prominent)) + .padding(.horizontal) + } +} +// MARK: - +struct PeerPushCreditView: View { + let stack: CallStack + let raw: Amount + let effective: Amount + let scope: ScopeInfo? + let summary: String + + var body: some View { + let currency = raw.currencyStr + let fee = try! Amount.diff(raw, effective) + ThreeAmountsSection(stack: stack.push(), + scope: scope, + topTitle: String(localized: "Gross Amount to receive:"), + topAbbrev: String(localized: "Receive gross:", comment: "mini"), + topAmount: raw, + noFees: nil, // TODO: check baseURL for fees + fee: fee, + bottomTitle: String(localized: "Net Amount to receive:"), + bottomAbbrev: String(localized: "Receive net:", comment: "mini"), + bottomAmount: effective, + large: false, pending: false, incoming: true, + baseURL: nil, + txStateLcl: nil, + summary: summary, + merchant: nil, + products: nil) + } +} +// MARK: - +struct ExpiresView: View { + let expiration: Timestamp + + @Environment(\.colorScheme) private var colorScheme + @Environment(\.colorSchemeContrast) private var colorSchemeContrast + @AppStorage("minimalistic") var minimalistic: Bool = false + var body: some View { + let (dateString, date) = TalerDater.dateString(expiration, minimalistic) + let a11yDate = TalerDater.accessibilityDate(date) ?? dateString + let a11yLabel = String(localized: "Expires: \(a11yDate)", comment: "a11y") + Text("Expires: \(dateString)") + .talerFont(.body) + .accessibilityLabel(a11yLabel) + .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) + } +}