taler-ios

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

commit 4b7fc67004dc39fca926ded4b317b0cb133f74f8
parent 74a1cc732eda6281354f8ded0c1bd440513b24c6
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 19 Oct 2024 18:15:46 +0200

cleanup

Diffstat:
MTalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift | 158++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 85 insertions(+), 73 deletions(-)

diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -21,11 +21,33 @@ struct RequestPayment: View { @State private var balanceIndex = 0 @State private var balance: Balance? = nil // nil only when balances == [] + @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) + + private func viewDidLoad() async { + if let selectedBalance { + balance = selectedBalance + balanceIndex = controller.balances.firstIndex(of: selectedBalance) ?? 0 + } else { + balanceIndex = 0 + balance = (controller.balances.count > 0) ? controller.balances[0] : nil + } + } + private func navTitle(_ currency: String, _ condition: Bool = false) -> String { + condition ? String(localized: "NavTitle_Request_Currency)", + defaultValue: "Request \(currency)", + comment: "NavTitle: Request 'currency'") + : String(localized: "NavTitle_Request", + defaultValue: "Request", + comment: "NavTitle: Request") + } var body: some View { #if PRINT_CHANGES let _ = Self._printChanges() #endif + let currencySymbol = currencyInfo.symbol + let navA11y = navTitle(currencyInfo.name) + let navTitle = navTitle(currencySymbol, currencyInfo.hasSymbol) let count = controller.balances.count let _ = symLog.log("count = \(count)") let scrollView = ScrollView { @@ -39,21 +61,23 @@ struct RequestPayment: View { .padding(.bottom, 4) } RequestPaymentContent(stack: stack.push(), + currencyInfo: $currencyInfo, balance: $balance, balanceIndex: $balanceIndex, amountLastUsed: $amountLastUsed, summary: $summary) } // ScrollView + .navigationTitle(navTitle) + .frame(maxWidth: .infinity, alignment: .leading) .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) - .task { - if let selectedBalance { - balance = selectedBalance - balanceIndex = controller.balances.firstIndex(of: selectedBalance) ?? 0 - } else { - balanceIndex = 0 - balance = (count > 0) ? controller.balances[0] : nil - } + .onAppear { + DebugViewC.shared.setViewID(VIEW_P2P_REQUEST, stack: stack.push()) + symLog.log("❗️ \(navTitle) onAppear") } + .onDisappear { + symLog.log("❗️ \(navTitle) onDisappear") + } + .task { await viewDidLoad() } if #available(iOS 16.0, *) { if #available(iOS 16.4, *) { @@ -71,6 +95,7 @@ struct RequestPayment: View { struct RequestPaymentContent: View { private let symLog = SymLogV() let stack: CallStack + @Binding var currencyInfo: CurrencyInfo @Binding var balance: Balance? @Binding var balanceIndex: Int @Binding var amountLastUsed: Amount @@ -91,9 +116,6 @@ struct RequestPaymentContent: View { @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) { @@ -173,74 +195,64 @@ struct RequestPaymentContent: View { let _ = Self._printChanges() let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif - let currency = amountToTransfer.currencyStr -// let currencyInfo = controller.info(for: currency, controller.currencyTicker) - let currencySymbol = currencyInfo.altUnitSymbol ?? currency - let navTitle = String(localized: "NavTitle_Request_Currency", - defaultValue: "Request \(currencySymbol)", - comment: "NavTitle: Request 'currencySymbol'") let coinData = CoinData(details: peerPullCheck) - let _ = symLog.log("currency: \(currency)") - let amountVoiceOver = amountToTransfer.formatted(currencyInfo, isNegative: false) - - let inputDestination = P2PSubjectV(stack: stack.push(), - scope: scopeInfo, - currencyInfo: $currencyInfo, - feeLabel: coinData.feeLabel(currencyInfo, - feeZero: String(localized: "No payment fee"), - isNegative: false), - feeIsNotZero: feeIsNotZero(), - outgoing: false, - amountToTransfer: $amountToTransfer, - summary: $summary, - expireDays: $expireDays) - let shortcutDestination = P2PSubjectV(stack: stack.push(), - scope: scopeInfo, - currencyInfo: $currencyInfo, - feeLabel: nil, - feeIsNotZero: feeIsNotZero(), - outgoing: false, - amountToTransfer: $amountShortcut, - summary: $summary, - expireDays: $expireDays) Group { - let amountLabel = minimalistic ? String(localized: "Amount:") - : String(localized: "Amount to request:") - AmountInputV(stack: stack.push(), - currencyInfo: $currencyInfo, - amountAvailable: $amountZero, - amountLabel: amountLabel, - amountToTransfer: $amountToTransfer, - amountLastUsed: amountLastUsed, - wireFee: nil, - summary: $summary, - shortcutAction: shortcutAction, - buttonAction: buttonAction, - feeIsNegative: true, - computeFee: computeFeeRequest) - .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // shortcutDestination - .background(NavigationLink(destination: inputDestination, isActive: $buttonSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // inputDestination + if let balance { + let scopeInfo = balance.scopeInfo +// let availableStr = amountAvailable.formatted(currencyInfo, isNegative: false) +// let amountVoiceOver = amountToTransfer.formatted(currencyInfo, isNegative: false) + let feeLabel = coinData.feeLabel(currencyInfo, + feeZero: String(localized: "No payment fee"), + isNegative: false) + let inputDestination = P2PSubjectV(stack: stack.push(), + scope: scopeInfo, + currencyInfo: $currencyInfo, + feeLabel: feeLabel, + feeIsNotZero: feeIsNotZero(), + outgoing: false, + amountToTransfer: $amountToTransfer, + summary: $summary, + expireDays: $expireDays) + let shortcutDestination = P2PSubjectV(stack: stack.push(), + scope: scopeInfo, + currencyInfo: $currencyInfo, + feeLabel: nil, + feeIsNotZero: feeIsNotZero(), + outgoing: false, + amountToTransfer: $amountShortcut, + summary: $summary, + expireDays: $expireDays) + let amountLabel = minimalistic ? String(localized: "Amount:") + : String(localized: "Amount to request:") + AmountInputV(stack: stack.push(), + currencyInfo: $currencyInfo, + amountAvailable: $amountZero, // incoming needs no available + amountLabel: amountLabel, + amountToTransfer: $amountToTransfer, + amountLastUsed: amountLastUsed, + wireFee: nil, + summary: $summary, + shortcutAction: shortcutAction, + buttonAction: buttonAction, + feeIsNegative: true, + computeFee: computeFeeRequest) + .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) + { EmptyView() }.frame(width: 0).opacity(0).hidden() + ) // shortcutDestination + .background(NavigationLink(destination: inputDestination, isActive: $buttonSelected) + { EmptyView() }.frame(width: 0).opacity(0).hidden() + ) // inputDestination + } else { // no balance - Yikes + Text("No balance. There seems to be a problem with the database...") + } } // Group - .frame(maxWidth: .infinity, alignment: .leading) - .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) - .navigationTitle(navTitle) - .onAppear { - DebugViewC.shared.setViewID(VIEW_P2P_REQUEST, stack: stack.push()) - symLog.log("❗️ \(navTitle) onAppear") - } - .onDisappear { - symLog.log("❗️ \(navTitle) onDisappear") - } .task(id: balanceIndex + (1000 * controller.currencyTicker)) { + // runs whenever the user changes the exchange via ScopePicker, or on new currencyInfo + symLog.log("❗️ task \(balanceIndex)") if let balance { scopeInfo = balance.scopeInfo - let currency = scopeInfo.currency - amountToTransfer.setCurrency(currency) - currencyInfo = controller.info2(for: currency, controller.currencyTicker) + amountToTransfer.setCurrency(scopeInfo.currency) + currencyInfo = controller.info(for: scopeInfo, controller.currencyTicker) } } // .task(id: amountToTransfer.value) {