commit 2c06fde3c719fa2644e7c5a4e8b542942b55ee21
parent a34da741382631477457ee005fce97ae46544be5
Author: Marc Stibane <marc@taler.net>
Date: Thu, 25 Jul 2024 13:59:19 +0200
Pass in currencyInfo
Diffstat:
5 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/TalerWallet1/Views/Balances/BalanceCellV.swift b/TalerWallet1/Views/Balances/BalanceCellV.swift
@@ -24,7 +24,11 @@ struct BalanceCellV: 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(stack: stack?.push("AmountV"), amount: amount, isNegative: false, large: true)
+ let amountV = AmountV(stack: stack?.push("AmountV"),
+ currencyInfo: currencyInfo,
+ 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
@@ -37,7 +37,7 @@ struct PendingRowView: View {
let outTitle = minimalistic ? outTitle0 : outTitle1
let pendingTitle = incoming ? inTitle : outTitle
- let amountText = AmountV(amount, isNegative: !incoming)
+ let amountText = AmountV(currencyInfo, amount, isNegative: !incoming)
.foregroundColor(pendingColor)
// this is the default view for iOS 15
diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift
@@ -11,6 +11,7 @@ import taler_swift
// Title and Amount
struct AmountRowV: View {
let stack: CallStack?
+ let currencyInfo: CurrencyInfo
let title: String
let amount: Amount
let isNegative: Bool // if true, show a "-" before the amount
@@ -21,7 +22,11 @@ struct AmountRowV: View {
let titleV = Text(title)
.multilineTextAlignment(.leading)
.talerFont(.body)
- let amountV = AmountV(stack: stack?.push(), amount: amount, isNegative: isNegative, large: large)
+ let amountV = AmountV(stack: stack?.push(),
+ currencyInfo: currencyInfo,
+ amount: amount,
+ isNegative: isNegative,
+ large: large)
.foregroundColor(color)
let verticalV = VStack(alignment: .leading) {
titleV
@@ -57,8 +62,9 @@ struct AmountRowV: View {
}
}
extension AmountRowV {
- init(title: String, amount: Amount, isNegative: Bool, color: Color) {
+ init(_ currencyInfo: CurrencyInfo, title: String, amount: Amount, isNegative: Bool, color: Color) {
self.stack = nil
+ self.currencyInfo = currencyInfo
self.title = title
self.amount = amount
self.isNegative = isNegative
@@ -79,10 +85,11 @@ fileprivate func talerFromStr(_ from: String) -> Amount {
#Preview {
List {
let fee = Amount(currency: "Taler", cent: 20)
- AmountRowV(stack: nil, title: "Fee", amount: fee, isNegative: true, color: Color("Outgoing"), large: false)
+ let currencyInfo = CurrencyInfo.zero("Taler")
+ AmountRowV(stack: nil, currencyInfo: currencyInfo, title: "Fee", amount: fee, isNegative: true, color: Color("Outgoing"), large: false)
let cents = Amount(currency: "Taler", cent: 480)
- AmountRowV(title: "Cents", amount: cents, isNegative: false, color: Color("Incoming"))
+ AmountRowV(currencyInfo, title: "Cents", amount: cents, isNegative: false, color: Color("Incoming"))
let amount = talerFromStr("Taler:4.80")
- AmountRowV(title: "Chosen amount to withdraw", amount: amount, isNegative: false, color: Color("Incoming"))
+ AmountRowV(currencyInfo, title: "Chosen amount to withdraw", amount: amount, isNegative: false, color: Color("Incoming"))
}
}
diff --git a/TalerWallet1/Views/Overview/OverviewRowV.swift b/TalerWallet1/Views/Overview/OverviewRowV.swift
@@ -10,6 +10,7 @@ import taler_swift
struct CurrenciesCell: View {
let stack: CallStack
+ let currencyInfo: CurrencyInfo
let amount: Amount
let sizeCategory: ContentSizeCategory
let rowAction: () -> Void
@@ -22,7 +23,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(stack: stack.push(), amount: amount, isNegative: false, large: true)
+ let amountV = AmountV(stack: stack.push(), currencyInfo: currencyInfo, amount: amount, isNegative: false, large: true)
.foregroundColor(.primary)
let hLayout = amountV
.frame(maxWidth: .infinity, alignment: .trailing)
@@ -64,6 +65,7 @@ struct CurrenciesCell: View {
/// [Send Money] [Request Payment]
struct OverviewRowV: View {
let stack: CallStack
+ let currencyInfo: CurrencyInfo
let amount: Amount
let sendAction: () -> Void
let recvAction: () -> Void
@@ -78,6 +80,7 @@ struct OverviewRowV: View {
var body: some View {
VStack (alignment: .trailing, spacing: 6) {
CurrenciesCell(stack: stack.push(),
+ currencyInfo: currencyInfo,
amount: amount,
sizeCategory: sizeCategory,
rowAction: rowAction,
@@ -97,10 +100,12 @@ struct OverviewRowV_Previews: PreviewProvider {
List {
Section {
- OverviewRowV(stack: CallStack("Preview"), amount: demo,
+ let currencyInfo = CurrencyInfo.zero(DEMOCURRENCY)
+ OverviewRowV(stack: CallStack("Preview"), currencyInfo: currencyInfo, amount: demo,
sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil)
}
- OverviewRowV(stack: CallStack("Preview"), amount: test,
+ let currencyInfo = CurrencyInfo.zero(TESTCURRENCY)
+ OverviewRowV(stack: CallStack("Preview"), currencyInfo: currencyInfo, amount: test,
sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil)
}
}
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -9,6 +9,7 @@ import SwiftUI
import taler_swift
struct TransactionRowView: View {
+ let currencyInfo: CurrencyInfo
let transaction : Transaction
@Environment(\.sizeCategory) var sizeCategory
@@ -54,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, isNegative: !incoming)
+ let amountV = AmountV(currencyInfo, common.amountEffective, isNegative: !incoming)
.foregroundColor(foreColor)
let topString = topString()
@@ -179,8 +180,8 @@ struct TransactionRow_Previews: PreviewProvider {
time: Timestamp(from: 1_666_666_000_000))
static var previews: some View {
List {
- TransactionRowView(transaction: withdrawal)
- TransactionRowView(transaction: payment)
+ TransactionRowView(currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), transaction: withdrawal)
+ TransactionRowView(currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), transaction: payment)
}
}
}