commit 854145e912418b24831b1ea5ffaac4b98aa39012
parent 7e3a4be8bee8e8b7cc0313be7046166d5da62fc2
Author: Marc Stibane <marc@taler.net>
Date: Wed, 18 Nov 2026 12:10:14 +0100
use cached exchanges
Diffstat:
9 files changed, 128 insertions(+), 83 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift
@@ -155,19 +155,7 @@ struct ManualWithdrawContent: View {
@State private var loadError: Error? = nil
// @State private var ageMenuList: [Int] = []
// @State private var selectedAge = 0
- @State private var tosAccepted = false
-
- @MainActor
- private func reloadExchange(_ baseURL: String) async {
- symLog.log("getExchangeByUrl(\(baseURL))")
- let exchange = try? await model.getExchangeByUrl(url: baseURL)
- if let tosStatus = exchange?.tosStatus {
- tosAccepted = (tosStatus == .accepted)
- || (tosStatus == .missingTos)
- } else {
- tosAccepted = false
- }
- }
+ @State private var tosAccepted: Bool? = nil
@MainActor
private func getWithdrawalDetailsForAmount(_ amount: Amount, _ reload: Bool = false) async {
@@ -177,7 +165,7 @@ struct ManualWithdrawContent: View {
scope: scope,
viewHandles: true)
if reload {
- await reloadExchange(details.exchangeBaseUrl)
+ tosAccepted = await controller.checkToS(for: details.exchangeBaseUrl)
}
detailsForAmount = details
loadError = nil
@@ -252,7 +240,7 @@ struct ManualWithdrawContent: View {
// restrictAge: restrictAge)
let disabled = amountToTransfer.isZero || coinData.invalid || coinData.tooMany
- if tosAccepted { // Von der Bank abzuhebender Betrag
+ if tosAccepted == true { // Von der Bank abzuhebender Betrag
let a11yLabel = String(localized: "Amount to withdraw from bank", comment: "a11y, no abbreviations")
let title = String(localized: "Amount to withdraw from bank:")
let amountLabel = minimalistic ? String(localized: "Amount:")
@@ -284,9 +272,9 @@ struct ManualWithdrawContent: View {
} else {
ToSButtonView(stack: stack.push(),
exchangeBaseUrl: scope.url ?? baseURL,
- viewID: VIEW_WITHDRAW_TOS, // 31 WithdrawTOSView TODO: might be withdraw-exchange
- p2p: false,
- acceptAction: nil)
+ viewID: VIEW_WITHDRAW_TOS, // 31 WithdrawTOSView TODO: might be withdraw-exchange
+ shouldDismiss: true, // pop back to here
+ p2p: false)
.padding(.top)
}
} // ScrollView
@@ -297,7 +285,7 @@ struct ManualWithdrawContent: View {
}
.onChange(of: controller.exchanges) { _ in
Task {
- await reloadExchange(detailsForAmount.exchangeBaseUrl)
+ tosAccepted = await controller.checkToS(for: detailsForAmount.exchangeBaseUrl)
}
}
} else if let loadError {
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
@@ -201,7 +201,7 @@ struct RequestPaymentContent: View {
}
if exchange == nil {
if let url = balance.scopeInfo.url {
- exchange = try? await model.getExchangeByUrl(url: url)
+ exchange = await controller.exchange(for: url)
}
}
do {
@@ -246,8 +246,7 @@ struct RequestPaymentContent: View {
exchange?.exchangeBaseUrl != baseURL ||
exchange?.tosStatus != .accepted
{
- symLog.log("getExchangeByUrl(\(baseURL))")
- exchange = try? await model.getExchangeByUrl(url: baseURL)
+ exchange = await controller.exchange(for: baseURL)
}
}
@@ -337,9 +336,9 @@ struct RequestPaymentContent: View {
balance.scopeInfo.url
ToSButtonView(stack: stack.push(),
exchangeBaseUrl: baseURL,
- viewID: VIEW_P2P_TOS, // 31 WithdrawTOSView TODO: YIKES might be withdraw-exchange
- p2p: false,
- acceptAction: nil)
+ viewID: VIEW_P2P_TOS, // 31 WithdrawTOSView TODO: might be withdraw-exchange
+ shouldDismiss: true, // pop back to here
+ p2p: false)
.padding(.top)
}
}
diff --git a/TalerWallet1/Views/HelperViews/ToSButtonView.swift b/TalerWallet1/Views/HelperViews/ToSButtonView.swift
@@ -11,8 +11,8 @@ struct ToSButtonView: View {
let stack: CallStack
let exchangeBaseUrl: String?
let viewID: Int // either VIEW_WITHDRAW_TOS or SHEET_WITHDRAW_TOS
+ let shouldDismiss: Bool
let p2p: Bool
- let acceptAction: (() async -> Void)?
@EnvironmentObject private var model: WalletModel
@AppStorage("minimalistic") var minimalistic: Bool = false
@@ -31,8 +31,8 @@ struct ToSButtonView: View {
}
let destination = WithdrawTOSView(stack: stack.push(),
exchangeBaseUrl: exchangeBaseUrl,
- viewID: viewID,
- acceptAction: acceptAction) // pop back to here
+ shouldDismiss: shouldDismiss,
+ viewID: viewID)
NavigationLink(destination: destination) {
Text("Terms of Service") // VIEW_WITHDRAW_TOS
}.buttonStyle(TalerButtonStyle(type: .prominent))
@@ -50,5 +50,5 @@ struct ToSButtonView: View {
}
#Preview {
- ToSButtonView(stack: CallStack("Preview"), exchangeBaseUrl: nil, viewID: 0, p2p: false, acceptAction: nil)
+ ToSButtonView(stack: CallStack("Preview"), exchangeBaseUrl: nil, viewID: 0, shouldDismiss: false, p2p: false)
}
diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Settings/Exchange/ExchangeRowView.swift
@@ -56,8 +56,8 @@ struct ExchangeRowView: View {
}
let showToS = WithdrawTOSView(stack: stack.push(),
exchangeBaseUrl: baseURL,
- viewID: VIEW_WITHDRAW_TOS,
- acceptAction: nil) // pop back to here
+ shouldDismiss: true, // pop back to here
+ viewID: VIEW_WITHDRAW_TOS)
let details = ExchangeDetailView(stack: stack.push(),
exchange: exchange)
let actions = Group {
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
@@ -75,8 +75,8 @@ struct P2pReceiveURIView: View {
ToSButtonView(stack: stack.push(),
exchangeBaseUrl: peerPushCreditResponse.exchangeBaseUrl,
viewID: SHEET_RCV_P2P_TOS,
- p2p: true,
- acceptAction: nil)
+ shouldDismiss: true,
+ p2p: true)
}
List {
PeerPushCreditView(stack: stack.push(),
diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift
@@ -28,15 +28,6 @@ struct WithdrawAcceptView: View {
@State private var withdrawalDetails: WithdrawalDetailsForAmount? = nil
@MainActor
- func reloadExchange() async -> Void { // TODO: throws?
- if let exchange {
- if let someExchange = try? await model.getExchangeByUrl(url: exchange.exchangeBaseUrl) {
- self.exchange = someExchange
- }
- }
- }
-
- @MainActor
private func viewDidLoad() async {
symLog.log(".task \(exchange?.id ?? "nil")")
if !amountToTransfer.isZero, let exchange {
@@ -66,8 +57,8 @@ struct WithdrawAcceptView: View {
ToSButtonView(stack: stack.push(),
exchangeBaseUrl: exchange2.exchangeBaseUrl,
viewID: SHEET_WITHDRAW_TOS,
- p2p: false,
- acceptAction: reloadExchange)
+ shouldDismiss: false, // pop back to here
+ p2p: false)
}
List {
if let withdrawalDetails {
@@ -115,6 +106,13 @@ struct WithdrawAcceptView: View {
}
}
.listStyle(myListStyle.style).anyView
+ .onChange(of: controller.exchanges) { _ in
+ Task {
+ if let someExchange = await controller.exchange(for: exchange2.exchangeBaseUrl) {
+ self.exchange = someExchange
+ }
+ }
+ }
.navigationTitle(navTitle)
.safeAreaInset(edge: .bottom) {
if tosAccepted {
diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift
@@ -13,10 +13,11 @@ struct WithdrawTOSView: View {
private let symLog = SymLogV(0)
let stack: CallStack
let exchangeBaseUrl: String?
+ let shouldDismiss: Bool
let viewID: Int // either VIEW_WITHDRAW_TOS or SHEET_WITHDRAW_TOS
- let acceptAction: (() async -> Void)?
@Environment(\.dismiss) var dismiss // pop back once
+ @EnvironmentObject private var controller: Controller
@EnvironmentObject private var model: WalletModel
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
@@ -39,12 +40,10 @@ struct WithdrawTOSView: View {
}
@MainActor
- func viewDidLoad() async {
- if let exchangeTOS, let exchangeBaseUrl {
- _ = try? await model.setExchangeTOSAccepted(exchangeBaseUrl)
- if acceptAction != nil {
- await acceptAction!()
- } else { // just go back - caller will reload
+ func acceptToS() async {
+ if exchangeTOS != nil, let exchangeBaseUrl {
+ _ = await controller.setTosAccepted(for: exchangeBaseUrl)
+ if shouldDismiss { // just go back - caller will reload
dismiss()
}
} else {
@@ -61,7 +60,7 @@ struct WithdrawTOSView: View {
myListStyle: $myListStyle,
language: languageCode,
languageAction: loadToS) {
- Task { await viewDidLoad() }
+ Task { await acceptToS() }
}
.navigationTitle(navTitle)
.refreshable {
diff --git a/TalerWallet1/Views/Transactions/TransactionSummaryList.swift b/TalerWallet1/Views/Transactions/TransactionSummaryList.swift
@@ -62,6 +62,8 @@ struct TransactionSummaryList: View {
@State private var isFinished: Bool? = false
@State private var payNow: Bool = false
@State private var isWorking: Bool = false
+ @State private var tosAccepted: Bool? = nil
+ @State private var tosBaseUrl: String = EMPTYSTRING
@Namespace var topID
func loadTransaction() async {
@@ -281,6 +283,13 @@ struct TransactionSummaryList: View {
} // Delete button
}
+ @ViewBuilder
+ func cancelButton() -> some View {
+ Button("Cancel") { dismissTop(stack.push()) }
+ .buttonStyle(TalerButtonStyle(type: .bordered))
+ .padding(Bool.iOS26 ? .horizontal : .all)
+ }
+
var possibleStr: String {
if let possible = paymentPossible {
return possible ? String(localized: "Confirm Payment", comment:"pay merchant navTitle")
@@ -310,7 +319,8 @@ struct TransactionSummaryList: View {
let common = talerTX.common
// let scope = common.scopes.first // might be nil if scopes == []
let locale = TalerDater.shared.locale
- let isPayDialog = talerTX.isPayment && talerTX.isDialog
+ let isPayment = talerTX.isPayment
+ let isPayDialog = isPayment && talerTX.isDialog
Group {
if common.type != .dummy && transactionId == common.transactionId {
let list = List {
@@ -335,42 +345,87 @@ struct TransactionSummaryList: View {
if !controller.stalledConnection {
TransactionTypeDetail(stack: stack.push(),
transaction: $talerTX,
+ tosAccepted: tosAccepted, // only for ToSButtonView above List
+ tosBaseUrl: $tosBaseUrl,
payNow: $payNow,
selectedChoice: $selectedChoice,
scope: $scope,
effective: $effective, // return amount for "Pay <amount> now"
possible: $paymentPossible,
hasDone: hasDone)
+ .onChange(of: tosBaseUrl) { newBaseUrl in
+ print(" 🫆 onChange of tosBaseUrl: \(newBaseUrl)")
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
+ Task {
+ tosAccepted = await controller.checkToS(for: newBaseUrl)
+ }
+ }
+ }
if withActions { abortFailDelete(common) }
}
}.id(viewId) // change viewId to enforce a draw update
.listStyle(myListStyle.style).anyView
+
+ VStack {
+ if tosAccepted == false {
+ ToSButtonView(stack: stack.push(),
+ exchangeBaseUrl: tosBaseUrl,
+ viewID: SHEET_RCV_P2P_TOS, // TODO
+ shouldDismiss: false, // pop back to here
+ p2p: true) // TODO
+ }
+ if #available(iOS 17.0, *) {
+ list
+ .scrollContentBackground(preferredColorScheme == 3 ? .hidden : .visible)
+ .toolbarTitleDisplayMode(.inlineLarge)
+ } else {
+ list
+ }
+ }
.background(FullBackground())
.navigationBarBackButtonHidden(hasDone)
.interactiveDismissDisabled(hasDone && !isPayDialog) // can only use "Done" button to dismiss
.safeAreaInset(edge: .bottom) {
- let cancelButton = Button("Cancel") { dismissTop(stack.push()) }
- .buttonStyle(TalerButtonStyle(type: .bordered))
- .padding(Bool.iOS26 ? .horizontal : .all)
+ let cancelButton = cancelButton()
let bottomButton = ZStack {
- if isPayDialog, case .payment(let paymentTransaction) = talerTX {
- let details = paymentTransaction.details
- if let effective, let terms = details.contractTerms, isFinished == false {
- let formatted = effective.formatted(currencyInfo)
- PaySafeArea(symLog: symLog,
- stack: stack.push(),
- terms: terms,
- amountString: formatted.0,
- amountA11y: formatted.1,
- isFinished: $isFinished,
- payNow: $payNow)
+ let major = common.txState.major.rawValue
+ let minor = common.txState.minor
+ if isPayDialog {
+ if case .payment(let paymentTransaction) = talerTX {
+ let details = paymentTransaction.details
+ if let terms = details.contractTerms, isFinished == false {
+ if let effective {
+ let formatted = effective.formatted(currencyInfo)
+// let _ = print("💰 PaySafeArea")
+ PaySafeArea(symLog: symLog,
+ stack: stack.push(),
+ terms: terms,
+ amountString: formatted.0,
+ amountA11y: formatted.1,
+ isFinished: $isFinished,
+ payNow: $payNow)
+ } else {
+// let _ = print("💰 no Cancel")
+ } // wait for $effective - don't show Cancel
+ } else {
+ let eff = effective != nil ? "effective" : "-"
+ let ter = details.contractTerms != nil ? "terms" : "-"
+ let fin = isFinished == false ? "not finished" : "-"
+// let _ = print("💰 Cancel \(eff), \(ter), \(fin)")
+ cancelButton
+ } // Cancel
} else {
- cancelButton
- } // Cancel
+#if DEBUG
+ let _ = print("😂 should never happen")
+#endif
+ } // don't show any bottom button
} else if let showDone {
- Button("Done") { dismissTop(stack.push()) }
- .buttonStyle(TalerButtonStyle(type: showDone))
- .padding(Bool.iOS26 ? .horizontal : .all)
+ if !isPayment || (minor != .claimProposal && minor != .submitPayment) {
+// let _ = print("\(isPayment ? "💰" : "😂") Done \(major).\(minor?.rawValue ?? "")")
+ Button("Done") { dismissTop(stack.push()) }
+ .buttonStyle(TalerButtonStyle(type: showDone))
+ .padding(Bool.iOS26 ? .horizontal : .all)
+ }
}
}
if controller.stalledConnection {
@@ -398,6 +453,13 @@ struct TransactionSummaryList: View {
controller.choicesTuple = (nil, nil)
}
}
+ .onChange(of: controller.exchanges) { _ in
+ if !tosBaseUrl.isEmpty {
+ Task {
+ tosAccepted = await controller.checkToS(for: tosBaseUrl)
+ }
+ }
+ }
.onChange(of: payNow) { payNow2 in
if payNow2 {
Task {
@@ -426,14 +488,6 @@ struct TransactionSummaryList: View {
checkReload(stack.push("TransactionStateTransition"), notification, "some transition ==> reload")
}
}
-
- if #available(iOS 17.0, *) {
- list
- .scrollContentBackground(preferredColorScheme == 3 ? .hidden : .visible)
- .toolbarTitleDisplayMode(.inlineLarge)
- } else {
- list
- }
} else {
Color.clear
.frame(maxWidth: .infinity, maxHeight: .infinity)
diff --git a/TalerWallet1/Views/Transactions/TransactionTypeDetail.swift b/TalerWallet1/Views/Transactions/TransactionTypeDetail.swift
@@ -14,6 +14,8 @@ struct TransactionTypeDetail: View {
private let symLog = SymLogV(0)
let stack: CallStack
@Binding var transaction: TalerTransaction
+ let tosAccepted: Bool?
+ @Binding var tosBaseUrl: String // might be empty
@Binding var payNow: Bool
@Binding var selectedChoice: Int?
@Binding var scope: ScopeInfo?
@@ -243,9 +245,14 @@ struct TransactionTypeDetail: View {
isDone: common.isDone,
scope: scope,
summary: details.info.summary)
- PeerPushCreditAccept(stack: stack.push(), url: nil,
- transactionId: common.transactionId,
- accept: $ignoreAccept)
+ .task { // tell caller which exchange to check for ToS-accepted
+ tosBaseUrl = details.exchangeBaseUrl
+ }
+ if tosAccepted == true {
+ PeerPushCreditAccept(stack: stack.push(), url: nil,
+ transactionId: common.transactionId,
+ accept: $ignoreAccept)
+ }
} else if transaction.isPayInvoice && common.isDialog {
PeerPullDebitView(stack: stack.push(),
raw: common.amountRaw,