taler-ios

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

commit df4716589cbc355329ac918933d18d322b7dd3c7
parent 47ca50cda25c2a721810eba165f07d4670750e06
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 13 Jul 2024 00:12:14 +0200

qrCodesForPayto WIP

Diffstat:
MTalerWallet1/Model/Model+Withdraw.swift | 27+++++++++++++++++++++++++++
MTalerWallet1/Views/Transactions/ManualDetailsV.swift | 23++++++++++++++++++++++-
2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift @@ -209,6 +209,26 @@ fileprivate struct AcceptManualWithdrawal: WalletBackendFormattedRequest { } } // MARK: - +struct QrCodeSpec: Decodable, 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 @MainActor // M for MainActor @@ -267,4 +287,11 @@ extension WalletModel { let response = try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles) return response } + @MainActor // M for MainActor + func getQrCodesForPaytoM(_ paytoUri: String, viewHandles: Bool = false) + async throws -> [QrCodeSpec]? { + let request = GetQrCodesForPayto(paytoUri: paytoUri) + let response = try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles) + return response.codes + } } diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -148,9 +148,11 @@ struct ManualDetailsV: View { var common : TransactionCommon var details : WithdrawalDetails + @EnvironmentObject private var model: WalletModel @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 { @@ -181,7 +183,7 @@ struct ManualDetailsV: View { .listRowSeparator(.hidden) } if validDetails.count > 1 { - if validDetails.count > 3 { + if validDetails.count > 3 { // too many for SegmentControl AccountPicker(title: String(localized: "Bank"), value: accountID, accountDetails: validDetails, action: redraw) .listRowSeparator(.hidden) @@ -197,6 +199,19 @@ struct ManualDetailsV: View { } } let payto = account.paytoUri + let qrCodesForPayto = Group { + ForEach(qrCodeSpecs, id: \.self) { spec in + let specDetails = String("❗️\(spec.type)❗️\(spec.qrContent)❗️") + QRGeneratorView(text: spec.qrContent) + .frame(maxWidth: .infinity, alignment: .center) + .accessibilityLabel("QR Code") + .listRowSeparator(.hidden) + +// Text(specDetails) +// .listRowSeparator(.automatic) + } + } + let payURL = URL(string: payto) if let queryParameters = payURL?.queryParameters { let receiverStr = (queryParameters["receiver-name"] ?? EMPTYSTRING).replacingOccurrences(of: "+", with: " ") @@ -316,8 +331,14 @@ struct ManualDetailsV: View { .disabled(false) // Spacer() } .listRowSeparator(.automatic) + qrCodesForPayto }.id(listID) .talerFont(.body) + .task { + if let specs = try? await model.getQrCodesForPaytoM(payto) { + qrCodeSpecs = specs ?? [] + } + } } else { // TODO: Error No payto URL }