commit af60c805ec996892639bb5e15a76319c220333bc
parent 2580ff59ed93dabd8660c30f57186a9c07362f10
Author: Marc Stibane <marc@taler.net>
Date: Thu, 18 Jun 2026 19:06:59 +0200
use transferOptions
Diffstat:
3 files changed, 54 insertions(+), 71 deletions(-)
diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift
@@ -31,6 +31,11 @@ enum TransferType: String, Codable {
case chQrBill = "ch-qr-bill"
}
+struct QrCodeSpec: Codable, Hashable {
+ var type: String
+ var qrContent: String
+}
+
struct TransferOption: Codable, Hashable {
var type: TransferType
var paytoUri: String? // only if type == payto
@@ -219,26 +224,6 @@ fileprivate struct AcceptManualWithdrawal: WalletBackendFormattedRequest {
}
}
// MARK: -
-struct QrCodeSpec: Codable, Hashable {
- var type: String
- var qrContent: String
-}
-/// A request to accept a manual withdrawl.
-fileprivate struct GetQrCodesForPayto: WalletBackendFormattedRequest {
- func operation() -> String { "getQrCodesForPayto" }
- func args() -> Args { Args(paytoUri: paytoUri) }
-
- var paytoUri: String
-
- struct Response: Decodable, Sendable { // list of QrCodeSpecs
- var codes: [QrCodeSpec]
- }
-
- struct Args: Encodable {
- var paytoUri: String
- }
-}
-// MARK: -
extension WalletModel {
/// load withdraw-exchange details. Networking involved
nonisolated func prepareWithdrawExchange(_ talerUri: String,
@@ -309,12 +294,4 @@ extension WalletModel {
let response = try await sendRequest(request, viewHandles: viewHandles)
return response
}
-
- nonisolated func getQrCodesForPayto(_ paytoUri: String,
- viewHandles: Bool = false)
- async throws -> [QrCodeSpec]? {
- let request = GetQrCodesForPayto(paytoUri: paytoUri)
- let response = try await sendRequest(request, viewHandles: viewHandles)
- return response.codes
- }
}
diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift
@@ -23,7 +23,6 @@ struct ManualDetailsV: View {
@AppStorage("minimalistic") var minimalistic: Bool = false
@State private var accountID = 0
@State private var listID = UUID()
- @State private var qrCodeSpecs: [QrCodeSpec] = []
func redraw(_ newAccount: Int) -> Void {
if newAccount != accountID {
@@ -37,15 +36,21 @@ struct ManualDetailsV: View {
}
}
- @MainActor
- private func viewDidLoad(_ paytoUri: String) async {
- if let specs = try? await model.getQrCodesForPayto(paytoUri) {
- qrCodeSpecs = specs
- return
+ @ViewBuilder func qrCodesRow(_ transferOptions: [TransferOption],
+ receiverStr: String,
+ amountStr: String,
+ messageStr: String?) -> some View {
+ let qrCodesForPayto = QRcodesForPayto(stack: stack.push(),
+ transferOptions: transferOptions,
+ receiverStr: receiverStr,
+ amountStr: amountStr,
+ messageStr: messageStr)
+ NavigationLink(destination: qrCodesForPayto) {
+ Text(minimalistic ? "QR"
+ : "Wire transfer QR codes")
+ .talerFont(.title3)
}
- qrCodeSpecs = []
}
-
var body: some View {
if let accountDetails = details.exchangeCreditAccountDetails {
let validDetails = validDetails(accountDetails)
@@ -76,13 +81,11 @@ struct ManualDetailsV: View {
SegmentControl(value: $accountID, accountDetails: validDetails, action: redraw)
.listRowSeparator(.hidden)
}
- } else if let amount = account.transferAmount {
- if let bankName = account.bankLabel {
- Text(bankName + ": " + amountStr.0)
- .accessibilityLabel(bankName + ": " + amountStr.1)
-// } else {
-// Text(amountStr)
- }
+ } else if let bankName = account.bankLabel {
+ Text(bankName + ": " + amountStr.0)
+ .accessibilityLabel(bankName + ": " + amountStr.1)
+// } else {
+// Text(amountStr)
}
let payto = PayTo(account.paytoUri)
if let receiverStr = payto.receiver {
@@ -106,24 +109,25 @@ struct ManualDetailsV: View {
.talerFont(.title3)
}
- let count = qrCodeSpecs.count
- if count > 1 {
- let qrCodesForPayto = QRcodesForPayto(stack: stack.push(),
- qrCodeSpecs: $qrCodeSpecs,
- receiverStr: receiverStr,
- amountStr: amountStr.0,
- messageStr: payto.messageStr
- )
- NavigationLink(destination: qrCodesForPayto) {
- Text(minimalistic ? "QR"
- : "Wire transfer QR codes")
- .talerFont(.title3)
+ if let transferOptions = account.transferOptions {
+ let countA = transferOptions.count
+ let countB = transferOptions.first?.qrCodes?.count ?? 0
+ if countA > 1 || countB > 1 {
+ qrCodesRow(transferOptions,
+ receiverStr: receiverStr,
+ amountStr: amountStr.0,
+ messageStr: payto.messageStr)
+ } else if countA > 0 { // show the single QR directly
+ if let qrCodeSpecs = transferOptions.first?.qrCodes {
+ if let qrCode = qrCodeSpecs.first {
+ let message = payto.messageStr ?? EMPTYSTRING
+ let textToShare = String(receiverStr + "\n" + amountStr.0 + "\n" + message)
+ QRcodeCopyShare(spec: qrCode,
+ textToShare: textToShare)
+ .listRowSeparator(.automatic)
+ }
+ }
}
- } else if count > 0 {
- let message = payto.messageStr ?? EMPTYSTRING
- let textToShare = String(receiverStr + "\n" + amountStr.0 + "\n" + message)
- QRcodeCopyShare(spec: qrCodeSpecs.first!, textToShare: textToShare)
- .listRowSeparator(.automatic)
}
#if DEBUG
if developerMode {
@@ -147,7 +151,6 @@ struct ManualDetailsV: View {
#endif
}.id(listID)
.talerFont(.body)
- .task { await viewDidLoad(account.paytoUri) }
} else {
// TODO: Error No payto URL
}
diff --git a/TalerWallet1/Views/Transactions/QRcodesForPayto.swift b/TalerWallet1/Views/Transactions/QRcodesForPayto.swift
@@ -34,7 +34,7 @@ struct QRcodeCopyShare: View {
struct QRcodesForPayto: View {
let stack: CallStack
- @Binding var qrCodeSpecs: [QrCodeSpec]
+ var transferOptions: [TransferOption]
let receiverStr: String
let amountStr: String
let messageStr: String?
@@ -46,20 +46,23 @@ struct QRcodesForPayto: View {
var body: some View {
let message = messageStr ?? EMPTYSTRING
let textToShare = String(receiverStr + "\n" + amountStr + "\n" + message)
- let count = qrCodeSpecs.count
List {
if !minimalistic {
- if count > 1 {
+// if count > 1 {
Text("If your banking software runs on another device, you can scan one of these QR codes:")
.listRowSeparator(.hidden)
- } else {
- Text("If your banking software runs on another device, you can scan this QR code:")
- .listRowSeparator(.hidden)
- }
+// } else {
+// Text("If your banking software runs on another device, you can scan this QR code:")
+// .listRowSeparator(.hidden)
+// }
}
- ForEach(qrCodeSpecs, id: \.self) { spec in
- QRcodeCopyShare(spec: spec, textToShare: textToShare)
- .listRowSeparator(.automatic)
+ ForEach(transferOptions, id: \.self) { option in
+ if let qrCodes = option.qrCodes {
+ ForEach(qrCodes, id: \.self) { spec in
+ QRcodeCopyShare(spec: spec, textToShare: textToShare)
+ .listRowSeparator(.automatic)
+ }
+ }
}
}
.navigationTitle(navTitle)