taler-ios

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

commit 35d07ff6d9f3563f3f1617d7c7654d915f03067e
parent 584c084120b89257ff09b383e84dae700527393e
Author: Marc Stibane <marc@taler.net>
Date:   Sat,  4 May 2024 15:42:45 +0200

currencyInfo instead of readableDescription

Diffstat:
MTalerWallet1/Helper/CurrencySpecification.swift | 14+++++++++++---
MTalerWallet1/Helper/TalerStrings.swift | 10++++++++++
MTalerWallet1/Views/HelperViews/AmountV.swift | 9+--------
MTalerWallet1/Views/HelperViews/QRCodeDetailView.swift | 8+-------
MTalerWallet1/Views/Transactions/ManualDetailsV.swift | 7+++----
5 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/TalerWallet1/Helper/CurrencySpecification.swift b/TalerWallet1/Helper/CurrencySpecification.swift @@ -41,6 +41,14 @@ extension Amount { } } + func string(useSymbol: Bool = true) -> String { + let controller = Controller.shared + if let currencyInfo = controller.info(for: self.currencyStr) { + return self.string(currencyInfo, useSymbol: useSymbol) + } + return self.readableDescription + } + func inputDigits(_ currencyInfo: CurrencyInfo) -> UInt { let inputDigits = currencyInfo.specs.fractionalInputDigits if inputDigits < 0 { return 0 } @@ -133,7 +141,7 @@ public struct CurrencyInfo { formatter.setUseSymbol(useSymbol) let (integer, fraction) = valueTuple if let integerStr = formatter.string(for: integer) { - if fraction == 0 { return integerStr } // formatter already added trailing zeroes + if fraction == 0 { return integerStr.nbs() } // formatter already added trailing zeroes if let fractionStr = formatter.string(for: fraction) { if let decimalSeparator = formatter.currencyDecimalSeparator { if let fractionIndex = fractionStr.endIndex(of: decimalSeparator) { @@ -159,7 +167,7 @@ public struct CurrencyInfo { } } // print(resultStr) - return resultStr + return resultStr.nbs() } // if we arrive here then fractionStr doesn't have a decimal separator. Yikes! } @@ -181,7 +189,7 @@ public struct CurrencyInfo { madeUpStr += Locale.current.decimalSeparator ?? "." // currencyDecimalSeparator madeUpStr += String(String(fraction).dropFirst()) // remove the leading 0 // TODO: fractionalNormalDigits, fractionalTrailingZeroDigits - return madeUpStr + return madeUpStr.nbs() } } diff --git a/TalerWallet1/Helper/TalerStrings.swift b/TalerWallet1/Helper/TalerStrings.swift @@ -40,6 +40,16 @@ extension StringProtocol { } extension String { + func replacingOccurrences(of char1: String.Element, with char2: String.Element) -> String { + String(self.map { + $0 == char1 ? char2 : $0 + }) + } + + func nbs() -> String { + self.replacingOccurrences(of: " ", with: "\u{00A0}") + } + func tabbed(oneLine: Bool) -> String { let fragments = self.components(separatedBy: "\t") if fragments.count > 1 { diff --git a/TalerWallet1/Views/HelperViews/AmountV.swift b/TalerWallet1/Views/HelperViews/AmountV.swift @@ -11,15 +11,8 @@ struct AmountV: View { @EnvironmentObject private var controller: Controller - var amountStr: String { - if let currencyInfo = controller.info(for: amount.currencyStr) { - return amount.string(currencyInfo) - } - return amount.readableDescription - } - var body: some View { - Text(amountStr) + Text(amount.string()) .multilineTextAlignment(.center) .talerFont(large ? .title : .title2) // .fontWeight(large ? .medium : .regular) // @available(iOS 16.0, *) diff --git a/TalerWallet1/Views/HelperViews/QRCodeDetailView.swift b/TalerWallet1/Views/HelperViews/QRCodeDetailView.swift @@ -15,13 +15,6 @@ struct QRCodeDetailView: View { @EnvironmentObject private var controller: Controller @AppStorage("minimalistic") var minimalistic: Bool = false - var amountStr: String { - if let currencyInfo = controller.info(for: amount.currencyStr) { - return amount.string(currencyInfo) - } - return amount.readableDescription - } - var body: some View { if talerURI.count > 10 { Section { @@ -58,6 +51,7 @@ struct QRCodeDetailView: View { .accessibilityLabel("QR Code") .listRowSeparator(.hidden) + let amountStr = amount.string() let scanMini = incoming ? String(localized: "Either (payer) Mini 3", defaultValue: "to pay \(amountStr).", comment: "e.g. '5,3 €'") : String(localized: "Either (payee) Mini 3", diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -165,8 +165,8 @@ struct ManualDetailsV: View { if validDetails.count > 0 { let account = validDetails[accountID] if let amount = account.transferAmount { - let amountStr = amount.readableDescription // TODO: formatter? - let obtainStr = common.amountRaw.readableDescription + let amountStr = amount.string() + let obtainStr = common.amountRaw.string() if !minimalistic { Text("The Payment Service Provider is waiting for your wire-transfer.") .bold() @@ -183,7 +183,6 @@ struct ManualDetailsV: View { .listRowSeparator(.hidden) } } else if let amount = account.transferAmount { - let amountStr = amount.readableDescription if let bankName = account.bankLabel { Text(bankName + ": " + amountStr) } else { @@ -193,7 +192,7 @@ struct ManualDetailsV: View { let payto = account.paytoUri let payURL = URL(string: payto) if let queryParameters = payURL?.queryParameters { - let amountStr = queryParameters["amount"] ?? EMPTYSTRING +// let amountStr = queryParameters["amount"] ?? EMPTYSTRING let receiverStr = queryParameters["receiver-name"] ?? EMPTYSTRING let senderStr = queryParameters["sender-name"] ?? EMPTYSTRING let messageStr = queryParameters["message"] ?? EMPTYSTRING