taler-ios

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

commit 93bdf944d63ad9c26c05ddded2feecb62c02c218
parent e0dc7958786cae4af9aefacde793be301f0ed0de
Author: Marc Stibane <marc@taler.net>
Date:   Sun, 12 Nov 2023 08:53:31 +0100

Amount(currency:cent:)

Diffstat:
MTalerWallet1/Views/Balances/BalanceRowView.swift | 4++--
MTalerWallet1/Views/Balances/BalancesSectionView.swift | 2+-
MTalerWallet1/Views/Balances/PendingRowView.swift | 4++--
MTalerWallet1/Views/Exchange/ExchangeRowView.swift | 2+-
MTalerWallet1/Views/Exchange/ExchangeSectionView.swift | 2+-
MTalerWallet1/Views/Exchange/ManualWithdraw.swift | 4++--
MTalerWallet1/Views/HelperViews/AmountRowV.swift | 4++--
MTalerWallet1/Views/Peer2peer/SendDoneV.swift | 2+-
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 10+++++-----
MTalerWallet1/Views/Transactions/ManualDetailsV.swift | 4++--
MTalerWallet1/Views/Transactions/ThreeAmountsV.swift | 4++--
MTalerWallet1/Views/Transactions/TransactionDetailView.swift | 2+-
MTalerWallet1/Views/Transactions/TransactionRowView.swift | 17+++++------------
13 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift b/TalerWallet1/Views/Balances/BalanceRowView.swift @@ -103,8 +103,8 @@ struct SomeBalanceRows: View { var body: some View { let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0) let demoInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 2) - let test = try! Amount(fromString: TESTCURRENCY + ":1.23") - let demo = try! Amount(fromString: DEMOCURRENCY + ":123.12") + let test = Amount(currency: TESTCURRENCY, cent: 123) + let demo = Amount(currency: DEMOCURRENCY, cent: 123456) // let testStr = test.string(testInfo) // let demoStr = demo.string(demoInfo) diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift @@ -292,7 +292,7 @@ fileprivate struct BindingViewContainer: View { var body: some View { let scopeInfo = ScopeInfo(type: ScopeInfo.ScopeInfoType.exchange, url: DEMOEXCHANGE, currency: LONGCURRENCY) - let balance = Balance(available: try! Amount(fromString: LONGCURRENCY + ":0.1"), + let balance = Balance(available: Amount(currency: LONGCURRENCY, cent:1), scopeInfo: scopeInfo, requiresUserInput: false, hasPendingTransactions: true) diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift b/TalerWallet1/Views/Balances/PendingRowView.swift @@ -127,8 +127,8 @@ struct PendingRowView_Previews: PreviewProvider { static var previews: some View { let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0) let demoInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 2) - let test = try! Amount(fromString: TESTCURRENCY + ":1.23") - let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.56") + let test = Amount(currency: TESTCURRENCY, cent: 123) + let demo = Amount(currency: DEMOCURRENCY, cent: 123456) List { PendingRowView(amount: test, currencyInfo: testInfo, incoming: true) PendingRowView(amount: demo, currencyInfo: demoInfo, incoming: false) diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Exchange/ExchangeRowView.swift @@ -107,7 +107,7 @@ struct ExchangeRowView: View { fileprivate struct ExchangeRow_Container : View { @State private var centsToTransfer: UInt64 = 100 -// let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") +// let amount = Amount(currency: LONGCURRENCY, cent: 123456) var body: some View { let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE, currency: LONGCURRENCY, diff --git a/TalerWallet1/Views/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Exchange/ExchangeSectionView.swift @@ -38,7 +38,7 @@ struct ExchangeSectionView: View { fileprivate struct ExchangeRow_Container : View { @State private var centsToTransfer: UInt64 = 100 -// let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") +// let amount = Amount(currency: LONGCURRENCY, cent: 123456) var body: some View { let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE, currency: LONGCURRENCY, diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift b/TalerWallet1/Views/Exchange/ManualWithdraw.swift @@ -99,8 +99,8 @@ struct ManualWithdraw: View { struct ManualWithdraw_Container : View { @State private var centsToTransfer: UInt64 = 510 @State private var details = WithdrawalAmountDetails(tosAccepted: false, - amountRaw: try! Amount(fromString: LONGCURRENCY + ":5.1"), - amountEffective: try! Amount(fromString: LONGCURRENCY + ":5.0"), + amountRaw: Amount(currency: LONGCURRENCY, cent: 510), + amountEffective: Amount(currency: LONGCURRENCY, cent: 500), paytoUris: [], ageRestrictionOptions: [], numCoins: 6) diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift @@ -54,8 +54,8 @@ struct SectionWithAmountRow: View { var body: some View { let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0) let demoInfo = PreviewCurrencyInfo(DEMOCURRENCY, digits: 2) - let test = try! Amount(fromString: TESTCURRENCY + ":1.23") - let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.12") + let test = Amount(currency: TESTCURRENCY, cent: 123) + let demo = Amount(currency: DEMOCURRENCY, cent: 123456) let testStr = test.string(testInfo) let demoStr = demo.string(demoInfo) List { diff --git a/TalerWallet1/Views/Peer2peer/SendDoneV.swift b/TalerWallet1/Views/Peer2peer/SendDoneV.swift @@ -97,7 +97,7 @@ struct SendDoneV: View { // static var previews: some View { // Group { // SendDoneV(stack: CallStack("Preview"), -// amountToSend: try! Amount(fromString: LONGCURRENCY + ":4.8"), +// amountToSend: Amount(currency: LONGCURRENCY, cent: 480), // amountToReceive: nil, // summary: "some subject/purpose", // expireDays: 0) diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -123,9 +123,9 @@ struct PaymentURIView_Previews: PreviewProvider { summary: "summary", summaryI18n: nil, nonce: "nonce", - amount: try! Amount(fromString: LONGCURRENCY + ":2.2"), + amount: Amount(currency: LONGCURRENCY, cent: 220), payDeadline: Timestamp.tomorrow(), - maxFee: try! Amount(fromString: LONGCURRENCY + ":0.2"), + maxFee: Amount(currency: LONGCURRENCY, cent: 20), merchant: merchant, merchantPub: "merchantPub", deliveryDate: nil, @@ -142,7 +142,7 @@ struct PaymentURIView_Previews: PreviewProvider { fulfillmentMessage: nil, fulfillmentMessageI18n: nil, wireFeeAmortization: 0, - maxWireFee: try! Amount(fromString: LONGCURRENCY + ":0.2"), + maxWireFee: Amount(currency: LONGCURRENCY, cent: 20), minimumAge: nil // extra: extra, // auditors: [], @@ -152,8 +152,8 @@ struct PaymentURIView_Previews: PreviewProvider { transactionId: "txn:payment:012345", contractTerms: terms, contractTermsHash: "termsHash", - amountRaw: try! Amount(fromString: LONGCURRENCY + ":2.2"), - amountEffective: try! Amount(fromString: LONGCURRENCY + ":2.4"), + amountRaw: Amount(currency: LONGCURRENCY, cent: 220), + amountEffective: Amount(currency: LONGCURRENCY, cent: 240), balanceDetails: nil, paid: nil // , talerUri: "talerURI" diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -85,8 +85,8 @@ struct ManualDetails_Previews: PreviewProvider { static var previews: some View { let common = TransactionCommon(type: .withdrawal, txState: TransactionState(major: .done), - amountEffective: try! Amount(fromString: LONGCURRENCY + ":1.1"), - amountRaw: try! Amount(fromString: LONGCURRENCY + ":2.2"), + amountEffective: Amount(currency: LONGCURRENCY, cent: 110), + amountRaw: Amount(currency: LONGCURRENCY, cent: 220), transactionId: "someTxID", timestamp: Timestamp(from: 1_666_666_000_000), txActions: []) diff --git a/TalerWallet1/Views/Transactions/ThreeAmountsV.swift b/TalerWallet1/Views/Transactions/ThreeAmountsV.swift @@ -114,8 +114,8 @@ struct ThreeAmounts_Previews: PreviewProvider { static var previews: some View { let common = TransactionCommon(type: .withdrawal, txState: TransactionState(major: .done), - amountEffective: try! Amount(fromString: LONGCURRENCY + ":0.1"), - amountRaw: try! Amount(fromString: LONGCURRENCY + ":0.2"), + amountEffective: Amount(currency: LONGCURRENCY, cent: 10), + amountRaw: Amount(currency: LONGCURRENCY, cent: 20), transactionId: "someTxID", timestamp: Timestamp(from: 1_666_666_000_000), txActions: []) diff --git a/TalerWallet1/Views/Transactions/TransactionDetailView.swift b/TalerWallet1/Views/Transactions/TransactionDetailView.swift @@ -8,7 +8,7 @@ import SymLog extension Transaction { // for Dummys init(dummyCurrency: String) { - let amount = try! Amount(fromString: "\(dummyCurrency):0") + let amount = Amount.zero(currency: dummyCurrency) let now = Timestamp.now() let common = TransactionCommon(type: .dummy, txState: TransactionState(major: .pending), diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift b/TalerWallet1/Views/Transactions/TransactionRowView.swift @@ -116,8 +116,6 @@ struct TransactionRow_Previews: PreviewProvider { static var previews: some View { let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0) let demoInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 2) - let test = try! Amount(fromString: TESTCURRENCY + ":1.23") - let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.56") List { TransactionRowView(transaction: withdrawal, currencyInfo: testInfo) TransactionRowView(transaction: payment, currencyInfo: demoInfo) @@ -127,17 +125,12 @@ struct TransactionRow_Previews: PreviewProvider { // MARK: - extension Transaction { // for PreViews init(incoming: Bool, pending: Bool, id: String, time: Timestamp) { - let currency = LONGCURRENCY - let raw = currency + ":5" - let effective = currency + (incoming ? ":4.8" - : ":5.2") - let refRaw = currency + ":3" - let refEff = currency + ":2.8" + let effective = incoming ? 480 : 520 let common = TransactionCommon(type: incoming ? .withdrawal : .payment, txState: TransactionState(major: pending ? TransactionMajorState.pending : TransactionMajorState.done), - amountEffective: try! Amount(fromString: effective), - amountRaw: try! Amount(fromString: raw), + amountEffective: Amount(currency: LONGCURRENCY, cent: UInt64(effective)), + amountRaw: Amount(currency: LONGCURRENCY, cent: 5), transactionId: id, timestamp: time, txActions: [.abort]) @@ -159,8 +152,8 @@ extension Transaction { // for PreViews summary: "some product summary", products: []) let pDetails = PaymentTransactionDetails(proposalId: "some proposal ID", - totalRefundRaw: try! Amount(fromString: refRaw), - totalRefundEffective: try! Amount(fromString: refEff), + totalRefundRaw: Amount(currency: LONGCURRENCY, cent: 300), + totalRefundEffective: Amount(currency: LONGCURRENCY, cent: 280), info: info) self = .payment(PaymentTransaction(common: common, details: pDetails)) }