taler-ios

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

commit 262d4d194e09f7e1cd72437d13b486928d3e9e1e
parent a49f1c38db7997bb9fb80468b92dae3cba82ba5f
Author: Marc Stibane <marc@taler.net>
Date:   Sun, 29 Oct 2023 15:16:01 +0100

string(_ currencyInfo: CurrencyInfo?)

Diffstat:
MTalerWallet1/Helper/CurrencySpecification.swift | 10++++++++++
MTalerWallet1/Views/Balances/BalanceRowView.swift | 8++++----
MTalerWallet1/Views/Balances/PendingRowView.swift | 10++--------
MTalerWallet1/Views/HelperViews/AmountRowV.swift | 4++--
4 files changed, 18 insertions(+), 14 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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) {