taler-ios

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

commit f9de329fadf8c9f7a7627a16329884120bcdb280
parent 33e19c250c3615480d09b492975461d9125c1361
Author: Marc Stibane <marc@taler.net>
Date:   Sun, 14 Jul 2024 10:24:01 +0200

Show negative amounts with "-"

Diffstat:
MTalerWallet1/Helper/CurrencySpecification.swift | 26+++++++++++++++-----------
MTalerWallet1/Views/Balances/BalanceRowView.swift | 2+-
MTalerWallet1/Views/Balances/PendingRowView.swift | 7+++++--
MTalerWallet1/Views/Banking/DepositAmountV.swift | 10+++++-----
MTalerWallet1/Views/Banking/DepositIbanV.swift | 9++++++---
MTalerWallet1/Views/Banking/QuiteSomeCoins.swift | 7+++++--
MTalerWallet1/Views/HelperViews/AmountInputV.swift | 2+-
MTalerWallet1/Views/HelperViews/AmountRowV.swift | 17+++++++++++------
MTalerWallet1/Views/HelperViews/AmountV.swift | 13+++++++++----
MTalerWallet1/Views/HelperViews/CurrencyField.swift | 5++++-
MTalerWallet1/Views/HelperViews/CurrencyInputView.swift | 7+++++--
MTalerWallet1/Views/HelperViews/QRCodeDetailView.swift | 7+++++--
MTalerWallet1/Views/HelperViews/SubjectInputV.swift | 4++--
MTalerWallet1/Views/Overview/OverviewRowV.swift | 7+++++--
MTalerWallet1/Views/Peer2peer/P2PSubjectV.swift | 11+++++++----
MTalerWallet1/Views/Peer2peer/SendAmount.swift | 6+++---
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 4++--
MTalerWallet1/Views/Transactions/ManualDetailsV.swift | 13++++++++-----
MTalerWallet1/Views/Transactions/ThreeAmountsV.swift | 17++++++++++++-----
MTalerWallet1/Views/Transactions/TransactionRowView.swift | 2+-
MTalerWallet1/Views/Transactions/TransactionSummaryV.swift | 2++
21 files changed, 114 insertions(+), 64 deletions(-)

diff --git a/TalerWallet1/Helper/CurrencySpecification.swift b/TalerWallet1/Helper/CurrencySpecification.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import Foundation import taler_swift @@ -33,30 +36,30 @@ extension Locale { } extension Amount { - func formatted(_ currencyInfo: CurrencyInfo?, useISO: Bool = false) -> String { + func formatted(_ currencyInfo: CurrencyInfo?, isNegative: Bool, useISO: Bool = false) -> String { if let currencyInfo { - return currencyInfo.string(for: valueAsFloatTuple, useISO: useISO) + return currencyInfo.string(for: valueAsFloatTuple, isNegative: isNegative, useISO: useISO) } else { return valueStr } } - func formatted(useISO: Bool = false) -> String { + func formatted(isNegative: Bool, useISO: Bool = false) -> String { let controller = Controller.shared if let currencyInfo = controller.info(for: self.currencyStr) { - return self.formatted(currencyInfo, useISO: useISO) + return self.formatted(currencyInfo, isNegative: isNegative, useISO: useISO) } return self.readableDescription } - func formatted(specs: CurrencySpecification?, scope: ScopeInfo? = nil, useISO: Bool = false) -> String { + func formatted(specs: CurrencySpecification?, isNegative: Bool, scope: ScopeInfo? = nil, useISO: Bool = false) -> String { if let specs { let myScope = scope ?? ScopeInfo(type: .madeUp, currency: currencyStr) let formatter = CurrencyFormatter.formatter(scope: myScope, specs: specs) let currencyInfo = CurrencyInfo(scope: myScope, specs: specs, formatter: formatter) - return formatted(currencyInfo, useISO: useISO) + return formatted(currencyInfo, isNegative: isNegative, useISO: useISO) } - return formatted(useISO: useISO) + return formatted(isNegative: isNegative, useISO: useISO) } func inputDigits(_ currencyInfo: CurrencyInfo) -> UInt { @@ -169,10 +172,10 @@ public struct CurrencyInfo { } // TODO: use valueAsDecimalTuple instead of valueAsFloatTuple - func string(for valueTuple: (Double, Double), useISO: Bool = false) -> String { + func string(for valueTuple: (Double, Double), isNegative: Bool, useISO: Bool = false) -> String { formatter.setUseISO(useISO) let (integer, fraction) = valueTuple - if let integerStr = formatter.string(for: integer) { + if let integerStr = formatter.string(for: isNegative ? -integer : integer) { let integerSpaced = integerStr.spaced if fraction == 0 { return currencyString(integerSpaced, useISO: useISO) // formatter already added trailing zeroes @@ -220,7 +223,8 @@ public struct CurrencyInfo { currencyName = altUnitName0 } } - var madeUpStr = currencyName + " " + String(integer) + var madeUpStr = currencyName + (isNegative ? " -" + String(integer) + : " " + String(integer)) // let homeCurrency = Locale.current.currency //'currency' is only available in iOS 16 or newer madeUpStr += formatter.currencyDecimalSeparator ?? Locale.current.decimalSeparator ?? "." madeUpStr += String(String(fraction).dropFirst()) // remove the leading 0 diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift b/TalerWallet1/Views/Balances/BalanceRowView.swift @@ -21,7 +21,7 @@ struct BalanceCell: View { /// Renders the Balance button. "Balance" leading, amountStr trailing. If it doesn't fit in one row then /// amount (trailing) goes underneath "Balance" (leading). var body: some View { - let amountV = AmountV(amount: amount, large: true) + let amountV = AmountV(amount: amount, isNegative: false, large: true) .foregroundColor(.primary) let hLayout = amountV .frame(maxWidth: .infinity, alignment: .trailing) diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift b/TalerWallet1/Views/Balances/PendingRowView.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift @@ -33,7 +36,7 @@ struct PendingRowView: View { let outTitle = minimalistic ? outTitle0 : outTitle1 let pendingTitle = incoming ? inTitle : outTitle - let amountText = AmountV(amount) + let amountText = AmountV(amount, isNegative: !incoming) .foregroundColor(pendingColor) // this is the default view for iOS 15 diff --git a/TalerWallet1/Views/Banking/DepositAmountV.swift b/TalerWallet1/Views/Banking/DepositAmountV.swift @@ -59,12 +59,12 @@ struct DepositAmountV: View { } private func buttonTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountWithCurrency = amount.formatted(currencyInfo, useISO: true) + let amountWithCurrency = amount.formatted(currencyInfo, isNegative: false, useISO: true) return String(localized: "Deposit \(amountWithCurrency)", comment: "amount with currency") } private func subjectTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountStr = amount.formatted(currencyInfo) + let amountStr = amount.formatted(currencyInfo, isNegative: false) return String(localized: "NavTitle_Deposit_AmountStr", defaultValue: "Deposit", comment: "NavTitle: Deposit") // defaultValue: "Deposit \(amountStr)", comment: "NavTitle: Deposit 'amountStr'") @@ -89,10 +89,10 @@ struct DepositAmountV: View { let navTitle = String(localized: "NavTitle_Deposit_Currency", defaultValue: "Deposit \(currencySymbol)", comment: "NavTitle: Deposit 'currencySymbol'") - let available = amountAvailable?.formatted(currencyInfo) ?? "an unknown amount" + let available = amountAvailable?.formatted(currencyInfo, isNegative: false) ?? "an unknown amount" let _ = print("available: \(available)") let _ = symLog.log("currency: \(currency), available: \(available)") - let amountVoiceOver = amountToTransfer.formatted(currencyInfo) + let amountVoiceOver = amountToTransfer.formatted(currencyInfo, isNegative: false) let insufficientLabel = String(localized: "You don't have enough \(currency).") let insufficientLabel2 = String(localized: "but you only have \(available) to deposit.") @@ -169,7 +169,7 @@ struct DepositAmountV: View { } else if let paytoUri { if let ppCheck = try? await model.prepareDepositM(paytoUri, amount: amountToTransfer) { if let feeAmount = fee(ppCheck: ppCheck) { - feeStr = feeAmount.formatted(currencyInfo) + feeStr = feeAmount.formatted(currencyInfo, isNegative: false) let feeLabel = feeLabel(feeStr) announce("\(amountVoiceOver), \(feeLabel)") } else { diff --git a/TalerWallet1/Views/Banking/DepositIbanV.swift b/TalerWallet1/Views/Banking/DepositIbanV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift import SymLog @@ -31,13 +34,13 @@ struct DepositIbanV: View { @FocusState private var isFocused: Bool private func buttonTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountWithCurrency = amount.formatted(currencyInfo, useISO: true) + let amountWithCurrency = amount.formatted(currencyInfo, isNegative: true, useISO: true) return String(localized: "Next", comment: "advance Deposit to Amount") return String(localized: "Deposit \(amountWithCurrency)", comment: "amount with currency") } private func subjectTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountStr = amount.formatted(currencyInfo) + let amountStr = amount.formatted(currencyInfo, isNegative: true) return String(localized: "NavTitle_Deposit_AmountStr", defaultValue: "Deposit", comment: "NavTitle: Deposit") // defaultValue: "Deposit \(amountStr)", comment: "NavTitle: Deposit 'amountStr'") diff --git a/TalerWallet1/Views/Banking/QuiteSomeCoins.swift b/TalerWallet1/Views/Banking/QuiteSomeCoins.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift import SymLog @@ -20,7 +23,7 @@ struct SomeCoins { invalid ? String(localized: "Amount too small!") : tooMany ? String(localized: "Amount too big for a single withdrawal!") : fee.isZero ? String(localized: "No withdrawal fee") - : String(localized: "- \(fee.formatted(currencyInfo)) fee") + : String(localized: "- \(fee.formatted(currencyInfo, isNegative: false)) fee") } else { EMPTYSTRING } diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift @@ -55,7 +55,7 @@ struct AmountInputV: View { let currency = amountToTransfer.currencyStr let currencyInfo = controller.info(for: currency, controller.currencyTicker) let insufficientLabel = String(localized: "You don't have enough \(currency).") - let available = amountAvailable?.formatted(currencyInfo) ?? nil + let available = amountAvailable?.formatted(currencyInfo, isNegative: false) ?? nil let flags = checkAvailable(amount: amountToTransfer) VStack(alignment: .trailing) { if summary.count > 0 { diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift @@ -9,6 +12,7 @@ import taler_swift struct AmountRowV: View { let title: String let amount: Amount + let isNegative: Bool // if true, show a "-" before the amount let color: Color let large: Bool // set to false for QR or IBAN @@ -16,7 +20,7 @@ struct AmountRowV: View { let titleV = Text(title) .multilineTextAlignment(.leading) .talerFont(.body) - let amountV = AmountV(amount: amount, large: large) + let amountV = AmountV(amount: amount, isNegative: isNegative, large: large) .foregroundColor(color) let verticalV = VStack(alignment: .leading) { titleV @@ -52,9 +56,10 @@ struct AmountRowV: View { } } extension AmountRowV { - init(title: String, amount: Amount, color: Color) { + init(title: String, amount: Amount, isNegative: Bool, color: Color) { self.title = title self.amount = amount + self.isNegative = isNegative self.color = color self.large = true } @@ -72,10 +77,10 @@ fileprivate func talerFromStr(_ from: String) -> Amount { #Preview { List { let fee = Amount(currency: "Taler", cent: 20) - AmountRowV(title: "Fee", amount: fee, color: Color("Outgoing"), large: false) + AmountRowV(title: "Fee", amount: fee, isNegative: true, color: Color("Outgoing"), large: false) let cents = Amount(currency: "Taler", cent: 480) - AmountRowV(title: "Cents", amount: cents, color: Color("Incoming")) + AmountRowV(title: "Cents", amount: cents, isNegative: false, color: Color("Incoming")) let amount = talerFromStr("Taler:4.80") - AmountRowV(title: "Chosen amount to withdraw", amount: amount, color: Color("Incoming")) + AmountRowV(title: "Chosen amount to withdraw", amount: amount, isNegative: false, color: Color("Incoming")) } } diff --git a/TalerWallet1/Views/HelperViews/AmountV.swift b/TalerWallet1/Views/HelperViews/AmountV.swift @@ -1,18 +1,22 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift struct AmountV: View { let amount: Amount - let large: Bool // set to false for QR or IBAN + let isNegative: Bool // if true, show a "-" before the amount + let large: Bool // set to false for QR or IBAN @EnvironmentObject private var controller: Controller var body: some View { - Text(amount.formatted()) + Text(amount.formatted(isNegative: isNegative)) .multilineTextAlignment(.center) .talerFont(large ? .title : .title2) // .fontWeight(large ? .medium : .regular) // @available(iOS 16.0, *) @@ -21,8 +25,9 @@ struct AmountV: View { } } extension AmountV { - init(_ amount: Amount) { + init(_ amount: Amount, isNegative: Bool) { self.amount = amount + self.isNegative = isNegative self.large = false } } diff --git a/TalerWallet1/Views/HelperViews/CurrencyField.swift b/TalerWallet1/Views/HelperViews/CurrencyField.swift @@ -19,6 +19,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +/** + * @author Marc Stibane + */ import SwiftUI import UIKit import taler_swift @@ -59,7 +62,7 @@ struct CurrencyField: View { ZStack { // Text view to display the formatted currency // Set as priority so CurrencyInputField size doesn't affect parent - Text(amount.formatted(currencyInfo)) + Text(amount.formatted(currencyInfo, isNegative: false)) .layoutPriority(1) // make the textfield use the whole width for tapping inside to become active .frame(maxWidth: .infinity, alignment: .trailing) diff --git a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift @@ -37,7 +40,7 @@ struct ShortcutButton: View { var body: some View { let shortie = Amount(currency: currency, cent: UInt64(shortcut)) // TODO: adapt for ¥ - let title = shortie.formatted(currencyInfo) + let title = shortie.formatted(currencyInfo, isNegative: false) let shortcutLabel = String(localized: "Shortcut", comment: "VoiceOver: $50,$25,$10,$5 shortcut buttons") Button(action: { action(shortcut, currencyField)} ) { Text(title) diff --git a/TalerWallet1/Views/HelperViews/QRCodeDetailView.swift b/TalerWallet1/Views/HelperViews/QRCodeDetailView.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift import AVFoundation @@ -51,7 +54,7 @@ struct QRCodeDetailView: View { .accessibilityLabel("QR Code") .listRowSeparator(.hidden) - let amountStr = amount.formatted() + let amountStr = amount.formatted(isNegative: false) 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/HelperViews/SubjectInputV.swift b/TalerWallet1/Views/HelperViews/SubjectInputV.swift @@ -44,7 +44,7 @@ struct SubjectInputV<TargetView: View>: View { // let insufficientLabel = String(localized: "You don't have enough \(currency).") // let feeLabel = insufficient ? insufficientLabel // : feeLabel(feeStr) - let available = amountAvailable?.formatted(currencyInfo) ?? nil + let available = amountAvailable?.formatted(currencyInfo, isNegative: false) ?? nil // let disabled = insufficient || summary.count == 0 let disabled = summary.count == 0 ScrollView { VStack(alignment: .leading) { @@ -85,7 +85,7 @@ struct SubjectInputV<TargetView: View>: View { } } HStack { - Text(amountToTransfer.formatted(currencyInfo)) + Text(amountToTransfer.formatted(currencyInfo, isNegative: false)) // TODO: hasFees? // Text(feeLabel) } diff --git a/TalerWallet1/Views/Overview/OverviewRowV.swift b/TalerWallet1/Views/Overview/OverviewRowV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift @@ -18,7 +21,7 @@ struct CurrenciesCell: View { /// Renders the Balance button. "Balance" leading, amountStr trailing. If it doesn't fit in one row then /// amount (trailing) goes underneath "Balance" (leading). var body: some View { - let amountV = AmountV(amount: amount, large: true) + let amountV = AmountV(amount: amount, isNegative: false, large: true) .foregroundColor(.primary) let hLayout = amountV .frame(maxWidth: .infinity, alignment: .trailing) diff --git a/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift import SymLog @@ -36,7 +39,7 @@ struct P2PSubjectV: View { @FocusState private var isFocused: Bool private func buttonTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountWithCurrency = amount.formatted(currencyInfo, useISO: true) + let amountWithCurrency = amount.formatted(currencyInfo, isNegative: false, useISO: true) return amountToSend ? String(localized: "Send \(amountWithCurrency) now", comment: "amount with currency") : String(localized: "Request \(amountWithCurrency)", @@ -44,7 +47,7 @@ struct P2PSubjectV: View { } private func subjectTitle(_ amount: Amount, _ currencyInfo: CurrencyInfo) -> String { - let amountStr = amount.formatted(currencyInfo) + let amountStr = amount.formatted(currencyInfo, isNegative: false) return amountToSend ? String(localized: "NavTitle_Send_AmountStr", defaultValue: "Send \(amountStr)", comment: "NavTitle: Send 'amountStr'") @@ -136,7 +139,7 @@ struct P2PSubjectV: View { if amountToSend && feeLabel == nil { if let ppCheck = try? await model.checkPeerPushDebitM(amountToTransfer) { if let feeAmount = p2pFee(ppCheck: ppCheck) { - let feeStr = feeAmount.formatted(currencyInfo) + let feeStr = feeAmount.formatted(currencyInfo, isNegative: false) myFeeLabel = String(localized: "+ \(feeStr) fee") } else { myFeeLabel = EMPTYSTRING } } diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift @@ -76,10 +76,10 @@ struct SendAmount: View { let navTitle = String(localized: "NavTitle_Send_Currency", defaultValue: "Send \(currencySymbol)", comment: "NavTitle: Send 'currencySymbol'") - let available = amountAvailable.formatted(currencyInfo) + let available = amountAvailable.formatted(currencyInfo, isNegative: false) // let _ = print("available: \(available)") let _ = symLog.log("currency: \(currency), available: \(available)") - let amountVoiceOver = amountToTransfer.formatted(currencyInfo) + let amountVoiceOver = amountToTransfer.formatted(currencyInfo, isNegative: false) let insufficientLabel2 = String(localized: "but you only have \(available) to send.") let inputDestination = LazyView { @@ -158,7 +158,7 @@ struct SendAmount: View { // TODO: set from exchange // agePicker.setAges(ages: peerPushCheck?.ageRestrictionOptions) if let feeAmount = fee(ppCheck: ppCheck) { - feeStr = feeAmount.formatted(currencyInfo) + feeStr = feeAmount.formatted(currencyInfo, isNegative: false) let feeLabel = feeLabel(feeStr) announce("\(amountVoiceOver), \(feeLabel)") } else { diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -47,10 +47,10 @@ func preparePayForTemplate(model: WalletModel, let amountRaw = ppCheck.amountRaw let currency = amountRaw.currencyStr let currencyInfo = controller.info(for: currency, controller.currencyTicker) - let amountVoiceOver = amountRaw.formatted(currencyInfo) + let amountVoiceOver = amountRaw.formatted(currencyInfo, isNegative: false) let insufficient = ppCheck.status == .insufficientBalance if let feeAmount = templateFee(ppCheck: ppCheck) { - let feeStr = feeAmount.formatted(currencyInfo) + let feeStr = feeAmount.formatted(currencyInfo, isNegative: false) let feeLabel = feeLabel(feeStr) announce("\(amountVoiceOver), \(feeLabel)") return PayForTemplateResult(ppCheck: ppCheck, insufficient: insufficient, diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import OrderedCollections import taler_swift @@ -35,7 +38,7 @@ struct SegmentControl: View { let detail = accountDetails[index] let specs = detail.currencySpecification let amount = detail.transferAmount - let amountStr = amount?.formatted(specs: specs, useISO: false) ?? "" + let amountStr = amount?.formatted(specs: specs, isNegative: false, useISO: false) ?? "" let bankName = detail.bankLabel let a11yLabel = bankName != nil ? (bankName! + " " + amountStr) : amountStr // let _ = print(amountStr) @@ -85,7 +88,7 @@ struct AccountPicker: View { ForEach(0..<accountDetails.count, id: \.self, content: { index in let detail = accountDetails[index] if let amount = detail.transferAmount { - let amountStr = amount.formatted(useISO: false) + let amountStr = amount.formatted(isNegative: false, useISO: false) // let _ = print(amountStr) if let bankName = detail.bankLabel { Text(bankName + ": " + amountStr) @@ -173,8 +176,8 @@ struct ManualDetailsV: View { let account = validDetails[accountID] if let amount = account.transferAmount { let specs = account.currencySpecification - let amountStr = amount.formatted(specs: specs) - let obtainStr = common.amountRaw.formatted() + let amountStr = amount.formatted(specs: specs, isNegative: false) + let obtainStr = common.amountRaw.formatted(isNegative: false) // let _ = print(amountStr, " | ", obtainStr) if !minimalistic { Text("The Payment Service Provider is waiting for your wire-transfer.") diff --git a/TalerWallet1/Views/Transactions/ThreeAmountsV.swift b/TalerWallet1/Views/Transactions/ThreeAmountsV.swift @@ -1,7 +1,10 @@ /* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. * See LICENSE.md */ +/** + * @author Marc Stibane + */ import SwiftUI import taler_swift @@ -101,21 +104,25 @@ struct ThreeAmountsV: View { } AmountRowV(title: minimalistic ? topAbbrev : topTitle, amount: topAmount, + isNegative: !incoming, color: labelColor, large: false) .padding(.bottom, 4) if hasNoFees == false { if let fee { - AmountRowV(title: minimalistic ? String(localized: "Fee (short):", defaultValue:"Fee:", comment:"short version") - : String(localized: "Fee (long):", defaultValue:"Fee:", comment:"long version"), - amount: fee, + let title = minimalistic ? String(localized: "Exchange fee (short):", defaultValue: "Fee:", comment: "short version") + : String(localized: "Exchange fee (long):", defaultValue: "Fee:", comment: "long version") + AmountRowV(title: title, + amount: fee, + isNegative: !incoming, color: labelColor, large: false) .padding(.bottom, 4) } if let bottomAmount { AmountRowV(title: minimalistic ? bottomAbbrev : bottomTitle, - amount: bottomAmount, + amount: bottomAmount, + isNegative: !incoming, color: foreColor, large: large) } diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift b/TalerWallet1/Views/Transactions/TransactionRowView.swift @@ -55,7 +55,7 @@ struct TransactionRowView: View { let iconBadge = TransactionIconBadge(type: common.type, foreColor: foreColor, done: done, incoming: incoming, shouldConfirm: shouldConfirm, needsKYC: needsKYC) - let amountV = AmountV(common.amountEffective) + let amountV = AmountV(common.amountEffective, isNegative: !incoming) .foregroundColor(foreColor) let topString = topString() diff --git a/TalerWallet1/Views/Transactions/TransactionSummaryV.swift b/TalerWallet1/Views/Transactions/TransactionSummaryV.swift @@ -349,11 +349,13 @@ struct TransactionSummaryV: View { let input = details.refreshInputAmount AmountRowV(title: minimalistic ? "Refreshed:" : "Refreshed amount:", amount: input, + isNegative: false, color: labelColor, large: true) if let fee = refreshFee(input: input, output: details.refreshOutputAmount) { AmountRowV(title: minimalistic ? "Fee:" : "Refreshed fee:", amount: fee, + isNegative: !fee.isZero, color: labelColor, large: true) }