taler-ios

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

commit b9b1d0f8e4e3a9098f89021b9873ca6405d1451c
parent 733f1ff441d1220e153ca183cecce46d1ca4133a
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 23 Aug 2025 09:45:20 +0200

case maxFee = "max_fee", cleanup

Diffstat:
MTalerWallet1/Model/Model+Payment.swift | 10++++++----
MTalerWallet1/Model/WalletModel.swift | 16++++++++--------
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 26++++++++++++++++++--------
MTalerWallet1/Views/Transactions/TransactionSummaryV.swift | 4++--
4 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/TalerWallet1/Model/Model+Payment.swift b/TalerWallet1/Model/Model+Payment.swift @@ -151,7 +151,8 @@ struct ContractChoice: Codable { let outputs: [ContractOutput] enum CodingKeys: String, CodingKey { - case amount, maxFee, description + case amount, description + case maxFee = "max_fee" case descriptionI18n = "description_i18n" case inputs, outputs } @@ -302,12 +303,13 @@ struct PerScopeDetails: Codable { } /// The result from PreparePayForUri struct PreparePayResult: Codable { - let status: PreparePayResultType + let status: PreparePayResultType // InsufficientBalance, AlreadyConfirmed, PaymentPossible, ChoiceSelection let transactionId: String let contractTerms: MerchantContractTerms - let scopes: [ScopeInfo] + let contractTermsHash: String? // not for InsufficientBalance + let scopes: [ScopeInfo]? // not for ChoiceSelection // let detailsPerScope: [ScopeInfo : PreparePayDetails] - let amountRaw: Amount + let amountRaw: Amount // TODO: not for ChoiceSelection let amountEffective: Amount? // only if status != insufficientBalance let paid: Bool? // only if status == alreadyConfirmed diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift @@ -195,10 +195,10 @@ extension WalletModel { fileprivate struct GetTransactionById: WalletBackendFormattedRequest { typealias Response = TalerTransaction func operation() -> String { "getTransactionById" } - func args() -> Args { Args(transactionId: transactionId, includeContractTerms: withTerms) } + func args() -> Args { Args(transactionId: transactionId, includeContractTerms: includeContractTerms) } var transactionId: String - var withTerms: Bool? + var includeContractTerms: Bool? struct Args: Encodable { var transactionId: String @@ -209,10 +209,10 @@ fileprivate struct GetTransactionById: WalletBackendFormattedRequest { fileprivate struct JSONTransactionById: WalletBackendFormattedRequest { typealias Response = String func operation() -> String { "getTransactionById" } - func args() -> Args { Args(transactionId: transactionId, includeContractTerms: withTerms) } + func args() -> Args { Args(transactionId: transactionId, includeContractTerms: includeContractTerms) } var transactionId: String - var withTerms: Bool? + var includeContractTerms: Bool? struct Args: Encodable { var transactionId: String @@ -222,14 +222,14 @@ fileprivate struct JSONTransactionById: WalletBackendFormattedRequest { extension WalletModel { /// get the specified transaction from Wallet-Core. No networking involved - nonisolated func getTransactionById(_ transactionId: String, withTerms: Bool? = nil, viewHandles: Bool = false) + nonisolated func getTransactionById(_ transactionId: String, includeContractTerms: Bool? = nil, viewHandles: Bool = false) async throws -> TalerTransaction { - let request = GetTransactionById(transactionId: transactionId, withTerms: withTerms) + let request = GetTransactionById(transactionId: transactionId, includeContractTerms: includeContractTerms) return try await sendRequest(request, viewHandles: viewHandles) } - nonisolated func jsonTransactionById(_ transactionId: String, withTerms: Bool? = nil, viewHandles: Bool = false) + nonisolated func jsonTransactionById(_ transactionId: String, includeContractTerms: Bool? = nil, viewHandles: Bool = false) async throws -> String { - let request = JSONTransactionById(transactionId: transactionId, withTerms: withTerms) + let request = JSONTransactionById(transactionId: transactionId, includeContractTerms: includeContractTerms) return try await sendRequest(request, viewHandles: viewHandles, asJSON: true) } } diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -91,12 +91,13 @@ struct PaymentView: View, Sendable { @MainActor func checkCurrencyInfo(for result: PreparePayResult) async { - let scopes = result.scopes - if scopes.count > 0 { - for scope in scopes { - controller.checkInfo(for: scope, model: model) + if let scopes = result.scopes { + if scopes.count > 0 { + for scope in scopes { + controller.checkInfo(for: scope, model: model) + } + return } - return } // else fallback to contractTerms.exchanges let exchanges = result.contractTerms.exchanges @@ -148,11 +149,19 @@ struct PaymentView: View, Sendable { return 0 } + func computeFee(raw: Amount?, eff: Amount?) -> Amount? { + if let raw, let eff { + return try! Amount.diff(raw, eff) // TODO: different currencies + } + return nil + } + var body: some View { Group { if let preparePayResult { let status = preparePayResult.status - let firstScope = preparePayResult.scopes.first + let scopes = preparePayResult.scopes // TODO: might be nil + let firstScope = scopes?.first let raw = preparePayResult.amountRaw let currency = raw.currencyStr let effective = preparePayResult.amountEffective @@ -185,7 +194,7 @@ struct PaymentView: View, Sendable { let bottomTitle = paid ? String(localized: "Spent amount:") : String(localized: "Amount to spend:") if let effective { - let fee = try! Amount.diff(raw, effective) // TODO: different currencies + let fee = computeFee(raw: raw, eff: effective) ThreeAmountsSection(stack: stack.push(), scope: firstScope, topTitle: topTitle, @@ -291,7 +300,8 @@ struct PaymentView: View, Sendable { .navigationTitle(navTitle) .task(id: controller.currencyTicker) { let currency = amountToTransfer.currencyStr - if let resultScope = preparePayResult.scopes.first { // TODO: let user choose which currency + let scopes = preparePayResult.scopes // TODO: might be nil + if let resultScope = scopes?.first { // TODO: let user choose which currency currencyInfo = controller.info(for: resultScope, controller.currencyTicker) } else { currencyInfo = controller.info2(for: currency, controller.currencyTicker) diff --git a/TalerWallet1/Views/Transactions/TransactionSummaryV.swift b/TalerWallet1/Views/Transactions/TransactionSummaryV.swift @@ -60,12 +60,12 @@ struct TransactionSummaryV: View { func loadTransaction() async { if let reloadedTransaction = try? await model.getTransactionById(transactionId, - withTerms: true, viewHandles: false) { + includeContractTerms: true, viewHandles: false) { symLog.log("reloaded \(reloadedTransaction.localizedType): \(reloadedTransaction.common.txState.major)") withAnimation { talerTX = reloadedTransaction; viewId = UUID() } // redraw if developerMode { if let json = try? await model.jsonTransactionById(transactionId, - withTerms: true, viewHandles: false) { + includeContractTerms: true, viewHandles: false) { jsonTransaction = json } else { jsonTransaction = ""