[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 02/29: currencyInfo instead of readableDescription
From: |
gnunet |
Subject: |
[taler-taler-ios] 02/29: currencyInfo instead of readableDescription |
Date: |
Tue, 28 May 2024 09:05:45 +0200 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 35d07ff6d9f3563f3f1617d7c7654d915f03067e
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sat May 4 15:42:45 2024 +0200
currencyInfo instead of readableDescription
---
TalerWallet1/Helper/CurrencySpecification.swift | 14 +++++++++++---
TalerWallet1/Helper/TalerStrings.swift | 10 ++++++++++
TalerWallet1/Views/HelperViews/AmountV.swift | 9 +--------
TalerWallet1/Views/HelperViews/QRCodeDetailView.swift | 8 +-------
TalerWallet1/Views/Transactions/ManualDetailsV.swift | 7 +++----
5 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/TalerWallet1/Helper/CurrencySpecification.swift
b/TalerWallet1/Helper/CurrencySpecification.swift
index 96a32ca..d04194f 100644
--- 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
index 10d4257..49204a8 100644
--- 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
index f2bd5be..1e29c64 100644
--- 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
index 44796f2..fa46b83 100644
--- 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
index ea25e11..7f1f780 100644
--- 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
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] branch master updated (18d895c -> c4761b4), gnunet, 2024/05/28
- [taler-taler-ios] 04/29: cleanup, gnunet, 2024/05/28
- [taler-taler-ios] 03/29: checkInternetConnection, gnunet, 2024/05/28
- [taler-taler-ios] 07/29: crash fix 8780, gnunet, 2024/05/28
- [taler-taler-ios] 05/29: CurrencyFormatter for manual withdrawals, gnunet, 2024/05/28
- [taler-taler-ios] 02/29: currencyInfo instead of readableDescription,
gnunet <=
- [taler-taler-ios] 06/29: non-breaking space, gnunet, 2024/05/28
- [taler-taler-ios] 01/29: Bank links, gnunet, 2024/05/28
- [taler-taler-ios] 13/29: addingPercentEncoding, gnunet, 2024/05/28
- [taler-taler-ios] 24/29: Logging, gnunet, 2024/05/28
- [taler-taler-ios] 29/29: Bump version to 0.11.0 (0.11.1), gnunet, 2024/05/28
- [taler-taler-ios] 19/29: checkPayForTemplate preparation, gnunet, 2024/05/28
- [taler-taler-ios] 15/29: Decode payee, gnunet, 2024/05/28
- [taler-taler-ios] 14/29: merge-kyc translation, gnunet, 2024/05/28
- [taler-taler-ios] 23/29: escape "\t", gnunet, 2024/05/28
- [taler-taler-ios] 26/29: German localization, gnunet, 2024/05/28