summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-10-29 15:16:01 +0100
committerMarc Stibane <marc@taler.net>2023-10-29 15:16:01 +0100
commit262d4d194e09f7e1cd72437d13b486928d3e9e1e (patch)
tree84d574775036766a35533af1950a3a0b7ad533c1
parenta49f1c38db7997bb9fb80468b92dae3cba82ba5f (diff)
downloadtaler-ios-262d4d194e09f7e1cd72437d13b486928d3e9e1e.tar.gz
taler-ios-262d4d194e09f7e1cd72437d13b486928d3e9e1e.tar.bz2
taler-ios-262d4d194e09f7e1cd72437d13b486928d3e9e1e.zip
string(_ currencyInfo: CurrencyInfo?)
-rw-r--r--TalerWallet1/Helper/CurrencySpecification.swift10
-rw-r--r--TalerWallet1/Views/Balances/BalanceRowView.swift8
-rw-r--r--TalerWallet1/Views/Balances/PendingRowView.swift10
-rw-r--r--TalerWallet1/Views/HelperViews/AmountRowV.swift4
4 files changed, 18 insertions, 14 deletions
diff --git a/TalerWallet1/Helper/CurrencySpecification.swift b/TalerWallet1/Helper/CurrencySpecification.swift
index 9adff4b..63988e3 100644
--- a/TalerWallet1/Helper/CurrencySpecification.swift
+++ b/TalerWallet1/Helper/CurrencySpecification.swift
@@ -5,6 +5,16 @@
import Foundation
import taler_swift
+extension Amount {
+ func string(_ currencyInfo: CurrencyInfo?) -> String {
+ if let currencyInfo {
+ return currencyInfo.string(for: valueAsTuple)
+ } else {
+ return valueStr
+ }
+ }
+}
+
public struct CurrencyInfo {
let scope: ScopeInfo
let specs: CurrencySpecification
diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift b/TalerWallet1/Views/Balances/BalanceRowView.swift
index a1d2425..9c36bbd 100644
--- a/TalerWallet1/Views/Balances/BalanceRowView.swift
+++ b/TalerWallet1/Views/Balances/BalanceRowView.swift
@@ -57,8 +57,8 @@ struct BalanceRowView: View {
let correctForSize = Self.correctForSize(sizeCategory)
SingleAxisGeometryReader { width in
VStack (alignment: .trailing) {
- let amountStr = currencyInfo?.string(for: amount.valueAsTuple)
- BalanceButton(amountStr: amountStr ?? amount.valueStr,
+ let amountStr = amount.string(currencyInfo)
+ BalanceButton(amountStr: amountStr,
sizeCategory: sizeCategory,
rowAction: rowAction)
let uiFont = TalerFont.uiFont(.title3)
@@ -88,8 +88,8 @@ struct SomeBalanceRows: View {
let demoInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 2)
let test = try! Amount(fromString: TESTCURRENCY + ":1.23")
let demo = try! Amount(fromString: DEMOCURRENCY + ":123.12")
- let testStr = testInfo.string(for: test.valueAsTuple)
- let demoStr = demoInfo.string(for: demo.valueAsTuple)
+// let testStr = test.string(testInfo)
+// let demoStr = demo.string(demoInfo)
List {
Section {
diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift b/TalerWallet1/Views/Balances/PendingRowView.swift
index 111fea2..b73f85d 100644
--- a/TalerWallet1/Views/Balances/PendingRowView.swift
+++ b/TalerWallet1/Views/Balances/PendingRowView.swift
@@ -45,14 +45,8 @@ struct PendingAmountView: View {
let currencyInfo: CurrencyInfo?
let incoming: Bool
- public static func amountStr(amount: Amount, currencyInfo: CurrencyInfo?, incoming: Bool) -> String {
-// let sign = incoming ? "+ " : "- "
- let amountStr = currencyInfo?.string(for: amount.valueAsTuple)
- return /*sign +*/ (amountStr ?? amount.valueStr)
- }
-
public static func width(amount: Amount, currencyInfo: CurrencyInfo?, incoming: Bool) -> CGFloat {
- let valueStr = Self.amountStr(amount: amount, currencyInfo: currencyInfo, incoming: incoming)
+ let valueStr = amount.string(currencyInfo)
let uiFont = TalerFont.uiFont(.title)
let width = valueStr.widthOfString(usingUIFont: uiFont)
// print("Amount width: ", width)
@@ -61,7 +55,7 @@ struct PendingAmountView: View {
var body: some View {
let pendingColor = WalletColors().pendingColor(incoming)
- let valueStr = Self.amountStr(amount: amount, currencyInfo: currencyInfo, incoming: incoming)
+ let valueStr = amount.string(currencyInfo)
Text(valueStr)
.foregroundColor(pendingColor)
.accessibilityFont(.title)
diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift
index 36ae4e0..f3307af 100644
--- a/TalerWallet1/Views/HelperViews/AmountRowV.swift
+++ b/TalerWallet1/Views/HelperViews/AmountRowV.swift
@@ -49,8 +49,8 @@ struct SectionWithAmountRow: View {
let demoInfo = PreviewCurrencyInfo(DEMOCURRENCY, digits: 2)
let test = try! Amount(fromString: TESTCURRENCY + ":1.23")
let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.12")
- let testStr = testInfo.string(for: test.valueAsTuple)
- let demoStr = demoInfo.string(for: demo.valueAsTuple)
+ let testStr = test.string(testInfo)
+ let demoStr = demo.string(demoInfo)
List {
Section {
AmountRowV(amountStr: demoStr, largeAmountFont: true, fitsHorizontal: true) {