commit f61c3b14357a52d1d61e626daed370565d98ebe2 parent a6c69cd54c5810025884bd7a689ba0bd47d97712 Author: Marc Stibane <marc@taler.net> Date: Sat, 12 Oct 2024 17:15:51 +0200 amountLastUsed Diffstat:
11 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -13,9 +13,8 @@ struct RequestPayment: View { let balances: [Balance] @Binding var selectedBalance: Balance? - @Binding var amountToTransfer: Amount + @Binding var amountLastUsed: Amount @Binding var summary: String - let scopeInfo: ScopeInfo @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @@ -27,12 +26,14 @@ struct RequestPayment: View { @State private var feeStr: String = EMPTYSTRING @State private var buttonSelected = false @State private var shortcutSelected = false + @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountZero = Amount.zero(currency: EMPTYSTRING) // needed for isZero @State private var exchange: Exchange? = nil // wg. noFees @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) @State private var currencyName: String = UNKNOWN @State private var currencySymbol: String = UNKNOWN + @State private var scopeInfo: ScopeInfo = ScopeInfo.zero() private func shortcutAction(_ shortcut: Amount) { amountShortcut = shortcut @@ -143,6 +144,7 @@ struct RequestPayment: View { amountAvailable: $amountZero, amountLabel: amountLabel, amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed, wireFee: nil, summary: $summary, shortcutAction: shortcutAction, diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift @@ -15,7 +15,7 @@ struct SendAmountV: View { let stack: CallStack let balances: [Balance] @Binding var selectedBalance: Balance? // selected balance when the action button is tapped in Transactions - @Binding var amountToTransfer: Amount + @Binding var amountLastUsed: Amount @Binding var summary: String @State private var balanceIndex = 0 @@ -48,7 +48,7 @@ struct SendAmountV: View { SendAmountContent(stack: stack.push(), balance: $balance, balanceIndex: $balanceIndex, - amountToTransfer: $amountToTransfer, + amountLastUsed: $amountLastUsed, summary: $summary) } // ScrollView .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) @@ -83,7 +83,7 @@ struct SendAmountContent: View { let stack: CallStack @Binding var balance: Balance? @Binding var balanceIndex: Int - @Binding var amountToTransfer: Amount + @Binding var amountLastUsed: Amount @Binding var summary: String // TODO: call getMaxPeerPushDebitAmountM @@ -101,6 +101,7 @@ struct SendAmountContent: View { @State private var feeStr: String = EMPTYSTRING @State private var buttonSelected = false @State private var shortcutSelected = false + @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // GetMaxPeerPushAmount @State private var exchange: Exchange? = nil // wg. noFees @@ -225,6 +226,7 @@ struct SendAmountContent: View { amountAvailable: $amountAvailable, amountLabel: amountLabel, amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed, wireFee: nil, summary: $summary, shortcutAction: shortcutAction, @@ -344,7 +346,7 @@ fileprivate struct Preview_Content: View { SendAmountV(stack: CallStack("Preview"), balances: [balance], selectedBalance: $noBalance, - amountToTransfer: $amountToPreview, + amountLastUsed: $amountToPreview, summary: $summary) } } diff --git a/TalerWallet1/Views/Banking/DepositAmountV.swift b/TalerWallet1/Views/Banking/DepositAmountV.swift @@ -21,6 +21,7 @@ struct DepositAmountV: View { // @Binding var depositIBAN: String // @Binding var accountHolder: String @Binding var amountToTransfer: Amount + let amountLastUsed: Amount // let scopeInfo: ScopeInfo @EnvironmentObject private var controller: Controller @@ -109,6 +110,7 @@ struct DepositAmountV: View { .padding(.bottom, 2) CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, + amountLastUsed: amountLastUsed, available: nil, // amountAvailable, title: minimalistic ? String(localized: "Amount:") : String(localized: "Amount to deposit:"), diff --git a/TalerWallet1/Views/Banking/DepositIbanV.swift b/TalerWallet1/Views/Banking/DepositIbanV.swift @@ -21,7 +21,7 @@ struct DepositIbanV: View { // let amountAvailable: Amount? // @Binding var depositIBAN: String // @Binding var accountHolder: String - @Binding var amountToTransfer: Amount + @Binding var amountLastUsed: Amount @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @@ -39,6 +39,7 @@ struct DepositIbanV: View { @State private var currencyName: String = UNKNOWN @State private var currencySymbol: String = UNKNOWN @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // Update currency when used + @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used private func buttonTitle(_ amount: Amount) -> String { let amountWithCurrency = amount.formatted(currencyInfo, isNegative: true, useISO: true) @@ -69,7 +70,8 @@ struct DepositIbanV: View { amountAvailable: amountAvailable, // depositIBAN: $depositIBAN, // accountHolder: $accountHolder, - amountToTransfer: $amountToTransfer) + amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed) } ScrollView { VStack (alignment: .leading, spacing: 6) { if let feeIsNotZero { // don't show fee if nil diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -22,6 +22,7 @@ struct ManualWithdraw: View { let scopeInfo: ScopeInfo? @Binding var exchange: Exchange? @Binding var amountToTransfer: Amount + @Binding var amountLastUsed: Amount @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @@ -79,6 +80,7 @@ struct ManualWithdraw: View { if tosAccepted { CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, + amountLastUsed: amountLastUsed, available: nil, title: minimalistic ? String(localized: "Amount:") : String(localized: "Amount to withdraw:"), diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift @@ -33,10 +33,10 @@ struct AmountInputV: View { private let symLog = SymLogV(0) let stack: CallStack @Binding var currencyInfo: CurrencyInfo - @Binding var amountAvailable: Amount let amountLabel: String @Binding var amountToTransfer: Amount + let amountLastUsed: Amount let wireFee: Amount? @Binding var summary: String // @Binding var insufficient: Bool @@ -97,6 +97,7 @@ struct AmountInputV: View { // } CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, + amountLastUsed: amountLastUsed, available: amountAvailable, title: amountLabel, shortcutAction: shortcutAction) diff --git a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift @@ -62,6 +62,7 @@ struct ShortcutButton: View { struct CurrencyInputView: View { @Binding var currencyInfo: CurrencyInfo @Binding var amount: Amount // the `value´ + let amountLastUsed: Amount let available: Amount? let title: String let shortcutAction: ((_ amount: Amount) -> Void)? @@ -179,11 +180,13 @@ struct CurrencyInputView: View { fileprivate struct Previews: PreviewProvider { @MainActor struct StateContainer: View { - @State var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 0) + @State var amountToPreview = Amount(currency: LONGCURRENCY, cent: 0) + @State var amountLastUsed = Amount(currency: LONGCURRENCY, cent: 170) @State private var currencyInfoL: CurrencyInfo = CurrencyInfo.zero(LONGCURRENCY) var body: some View { CurrencyInputView(currencyInfo: $currencyInfoL, - amount: $amountToTransfer, + amount: $amountToPreview, + amountLastUsed: amountLastUsed, available: Amount(currency: LONGCURRENCY, cent: 2000), title: "Amount to withdraw:", shortcutAction: nil) diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -256,7 +256,8 @@ extension MainView { @State private var showActionSheet = false @State private var sheetHeight: CGFloat = .zero - @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used + @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used + @State private var amountLastUsed = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var summary: String = EMPTYSTRING @State private var showSpendingHint = true @State private var myExchange: Exchange? = nil @@ -341,15 +342,14 @@ extension MainView { let sendDest = SendAmountV(stack: stack.push("\(Self.className())()"), balances: balances, selectedBalance: $selectedBalance, // if nil shows currency picker - amountToTransfer: $amountToTransfer, // currency needs to be updated! + amountLastUsed: $amountLastUsed, // currency needs to be updated! summary: $summary) let requestDest = RequestPayment(stack: stack.push("\(Self.className())()"), balances: balances, selectedBalance: $selectedBalance, - amountToTransfer: $amountToTransfer, // currency needs to be updated! - summary: $summary, - scopeInfo: scope) + amountLastUsed: $amountLastUsed, // currency needs to be updated! + summary: $summary) let depositDest = DepositIbanV(stack: stack.push(), balances: balances, @@ -358,7 +358,7 @@ extension MainView { feeIsNotZero: nil, // depositIBAN: $depositIBAN, // accountHolder: $accountHolder, - amountToTransfer: $amountToTransfer) + amountLastUsed: $amountLastUsed) let manualWithdrawDest = ManualWithdraw(stack: stack.push(), balances: balances, @@ -366,7 +366,8 @@ extension MainView { isSheet: false, scopeInfo: scope, exchange: $myExchange, - amountToTransfer: $amountToTransfer) + amountToTransfer: $amountToTransfer, + amountLastUsed: $amountLastUsed) ZStack(alignment: .bottom) { TabView(selection: tabSelection()) { diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -33,6 +33,7 @@ struct PayTemplateV: View { @State private var amountIsEditable = false @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used + @State private var amountLastUsed = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // TODO: set correct available amount (like in SendAmountV) @State private var shortcutSelected = false @State private var buttonSelected1 = false @@ -138,6 +139,7 @@ struct PayTemplateV: View { amountAvailable: $amountAvailable, amountLabel: amountLabel, amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed, wireFee: nil, summary: $summary, shortcutAction: shortcutAction, diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -29,6 +29,7 @@ struct WithdrawURIView: View { @State private var amountIsEditable = false @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used + @State private var amountLastUsed = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var amountZero = Amount.zero(currency: EMPTYSTRING) // needed for isZero @State private var buttonSelected = false @State private var shortcutSelected = false @@ -147,6 +148,7 @@ struct WithdrawURIView: View { amountAvailable: $amountZero, amountLabel: amountLabel, amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed, wireFee: wireFee, summary: $summary, shortcutAction: shortcutAction, diff --git a/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift b/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift @@ -22,6 +22,7 @@ struct WithdrawExchangeV: View { @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) @State private var exchange: Exchange? = nil @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) + @State private var amountLastUsed = Amount.zero(currency: EMPTYSTRING) let navTitle = String(localized: "Checking Link") @@ -40,7 +41,8 @@ struct WithdrawExchangeV: View { isSheet: true, scopeInfo: exchange.scopeInfo, exchange: $exchange, - amountToTransfer: $amountToTransfer) + amountToTransfer: $amountToTransfer, + amountLastUsed: $amountLastUsed) } .task(id: controller.currencyTicker) { currencyInfo = controller.info(for: currency, controller.currencyTicker)