taler-ios

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

commit 544a13a17b2bcfc2115fd729cf1da8b6171adfa8
parent 45a022075abf369dff9a74a8932a507ade571727
Author: Marc Stibane <marc@taler.net>
Date:   Sun,  9 Jun 2024 18:21:20 +0200

acceptAction

Diffstat:
MTalerWallet1/Views/Banking/ManualWithdraw.swift | 11+++++++----
MTalerWallet1/Views/HelperViews/ToSButtonView.swift | 5+++--
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift | 3++-
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift | 18++++++++++++++----
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift | 4++--
5 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -28,6 +28,8 @@ struct ManualWithdraw: View { // @State var ageMenuList: [Int] = [] // @State var selectedAge = 0 + fileprivate let sheetID = SHEET_WITHDRAW_EXCHANGE // 135 WithdrawExchangeV + fileprivate let viewID = VIEW_WITHDRAWAL // 30 WithdrawAmount var body: some View { #if PRINT_CHANGES let _ = Self._printChanges() @@ -88,8 +90,9 @@ struct ManualWithdraw: View { } else { ToSButtonView(stack: stack.push(), exchangeBaseUrl: exchange.exchangeBaseUrl, - viewID: VIEW_WITHDRAW_TOS, // TODO: YIKES might be withdraw-exchange - p2p: false) + viewID: VIEW_WITHDRAW_TOS, // 31 WithdrawTOSView TODO: YIKES might be withdraw-exchange + p2p: false, + acceptAction: nil) .padding(.top) } }.padding(.horizontal) } // ScrollVStack @@ -99,9 +102,9 @@ struct ManualWithdraw: View { .navigationTitle(navTitle) .onAppear { if isSheet { - DebugViewC.shared.setSheetID(SHEET_WITHDRAW_EXCHANGE) + DebugViewC.shared.setSheetID(sheetID) } else { - DebugViewC.shared.setViewID(VIEW_WITHDRAWAL, stack: stack.push()) + DebugViewC.shared.setViewID(viewID, stack: stack.push()) } symLog.log("❗️ \(navTitle) onAppear") } diff --git a/TalerWallet1/Views/HelperViews/ToSButtonView.swift b/TalerWallet1/Views/HelperViews/ToSButtonView.swift @@ -13,6 +13,7 @@ struct ToSButtonView: View { let exchangeBaseUrl: String? let viewID: Int // either VIEW_WITHDRAW_TOS or SHEET_WITHDRAW_TOS let p2p: Bool + let acceptAction: (() async -> Void)? @AppStorage("minimalistic") var minimalistic: Bool = false @@ -28,7 +29,7 @@ struct ToSButtonView: View { WithdrawTOSView(stack: stack.push(), exchangeBaseUrl: exchangeBaseUrl, viewID: viewID, - acceptAction: nil) // pop back to here + acceptAction: acceptAction) // pop back to here }) { Text("Terms of Service") // VIEW_WITHDRAW_TOS }.buttonStyle(TalerButtonStyle(type: .prominent)) @@ -37,5 +38,5 @@ struct ToSButtonView: View { } #Preview { - ToSButtonView(stack: CallStack("Preview"), exchangeBaseUrl: nil, viewID: 0, p2p: false) + ToSButtonView(stack: CallStack("Preview"), exchangeBaseUrl: nil, viewID: 0, p2p: false, acceptAction: nil) } diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -33,7 +33,8 @@ struct P2pReceiveURIView: View { ToSButtonView(stack: stack.push(), exchangeBaseUrl: peerPushCreditResponse.exchangeBaseUrl, viewID: SHEET_RCV_P2P_TOS, - p2p: true) + p2p: true, + acceptAction: nil) } List { let raw = peerPushCreditResponse.amountRaw diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift @@ -25,6 +25,15 @@ struct WithdrawAcceptView: View { @State private var withdrawalAmountDetails: WithdrawalAmountDetails? = nil + func reloadExchange() async -> Void { // TODO: throws? + if let exchange { + if let someExchange = try? await model.getExchangeByUrl(url: exchange.exchangeBaseUrl) { + self.exchange = someExchange + } + } + } + + fileprivate let sheetID = SHEET_WITHDRAW_ACCEPT // 132 WithdrawAcceptView var body: some View { if let exchange, let withdrawalAmountDetails { VStack { @@ -33,7 +42,8 @@ struct WithdrawAcceptView: View { ToSButtonView(stack: stack.push(), exchangeBaseUrl: exchange.exchangeBaseUrl, viewID: SHEET_WITHDRAW_TOS, - p2p: false) + p2p: false, + acceptAction: reloadExchange) } List { let raw = withdrawalAmountDetails.amountRaw @@ -80,7 +90,7 @@ struct WithdrawAcceptView: View { } .onAppear() { symLog.log("onAppear") - DebugViewC.shared.setSheetID(SHEET_WITHDRAW_ACCEPT) + DebugViewC.shared.setSheetID(sheetID) } } else { // no details or no exchange #if DEBUG @@ -89,8 +99,8 @@ struct WithdrawAcceptView: View { let message: String? = nil #endif LoadingView(scopeInfo: nil, message: message) - .task(id: exchange) { - symLog.log(".task") + .task(id: exchange?.id) { + symLog.log(".task \(exchange?.id ?? "nil")") if let exchange { if let details = try? await model.getWithdrawalDetailsForAmountM(exchange.exchangeBaseUrl, amount: amountToTransfer) { diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift @@ -14,7 +14,7 @@ struct WithdrawTOSView: View { let exchangeBaseUrl: String? let viewID: Int // either VIEW_WITHDRAW_TOS or SHEET_WITHDRAW_TOS - let acceptAction: (() -> Void)? + let acceptAction: (() async -> Void)? @Environment(\.presentationMode) var presentationMode @EnvironmentObject private var model: WalletModel @@ -45,7 +45,7 @@ struct WithdrawTOSView: View { if let exchangeBaseUrl { _ = try? await model.setExchangeTOSAcceptedM(exchangeBaseUrl, etag: exchangeTOS.currentEtag) if acceptAction != nil { - acceptAction!() + await acceptAction!() } else { // just go back - caller will reload self.presentationMode.wrappedValue.dismiss() }