taler-ios

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

commit 1719c9f1523039f86e3ec189ae2dde384b15dbb9
parent 215bfa29f2919044d01b5b817bec2c22f7a8f6c1
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 14 Sep 2024 15:42:09 +0200

Repurchase

Diffstat:
MTalerWallet1/Model/Model+Payment.swift | 8++++----
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 33+++++++++++++++++++++++++--------
2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/TalerWallet1/Model/Model+Payment.swift b/TalerWallet1/Model/Model+Payment.swift @@ -141,13 +141,13 @@ struct ExchangeFeeGapEstimate: Codable { struct PreparePayResult: Codable { let status: PreparePayResultType let transactionId: String - let contractTerms: MerchantContractTerms - let contractTermsHash: String? // only if status != insufficientBalance let amountRaw: Amount let amountEffective: Amount? // only if status != insufficientBalance - let balanceDetails: PayMerchantInsufficientBalanceDetails? // only if status == insufficientBalance let paid: Bool? // only if status == alreadyConfirmed -// let talerUri: String? + let talerUri: String? + let balanceDetails: PayMerchantInsufficientBalanceDetails? // only if status == insufficientBalance + let contractTermsHash: String? // only if status != insufficientBalance + let contractTerms: MerchantContractTerms } /// A request to get an exchange's payment contract terms. fileprivate struct PreparePayForUri: WalletBackendFormattedRequest { diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -86,7 +86,6 @@ struct PaymentView: View { @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) @State var preparePayResult: PreparePayResult? = nil - let navTitle = String(localized: "Confirm Payment", comment:"pay merchant") func checkCurrencyInfo(for result: PreparePayResult) async { let exchanges = result.contractTerms.exchanges @@ -105,18 +104,36 @@ struct PaymentView: View { var body: some View { Group { if let preparePayResult { + let status = preparePayResult.status let raw = preparePayResult.amountRaw + let currency = raw.currencyStr let effective = preparePayResult.amountEffective let terms = preparePayResult.contractTerms + let baseURL = terms.exchanges.first?.url + let paid = status == .alreadyConfirmed + let navTitle = paid ? String(localized: "Already paid", comment:"pay merchant navTitle") + : String(localized: "Confirm Payment", comment:"pay merchant navTitle") List { + if paid { + Text("You already paid for this article.") + .talerFont(.headline) + if let fulfillmentUrl = terms.fulfillmentURL { + if let destination = URL(string: fulfillmentUrl) { + let buttonTitle = terms.fulfillmentMessage ?? String(localized: "Open merchant website") + Link(buttonTitle, destination: destination) + .buttonStyle(TalerButtonStyle(type: .bordered)) + .accessibilityHint(String(localized: "Will go to the merchant website.")) + } + } + } // TODO: show balanceDetails.balanceAvailable - let baseURL = preparePayResult.contractTerms.exchanges.first?.url - let status = preparePayResult.status - let currency = raw.currencyStr - let topTitle = String(localized: "Amount to pay:") - let topAbbrev = String(localized: "Pay:", comment: "mini") + let topTitle = paid ? String(localized: "Paid amount:") + : String(localized: "Amount to pay:") + let topAbbrev = paid ? String(localized: "Paid:", comment: "mini") + : String(localized: "Pay:", comment: "mini") + let bottomTitle = paid ? String(localized: "Spent amount:") + : String(localized: "Amount to spend:") if let effective { - // TODO: already paid let fee = try! Amount.diff(raw, effective) // TODO: different currencies ThreeAmountsSection(stack: stack.push(), currencyInfo: $currencyInfo, @@ -125,7 +142,7 @@ struct PaymentView: View { topAmount: raw, noFees: nil, // TODO: check baseURL for fees fee: fee, - bottomTitle: String(localized: "Amount to spend:"), + bottomTitle: bottomTitle, bottomAbbrev: String(localized: "Effective:", comment: "mini"), bottomAmount: effective, large: false,