taler-ios

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

commit ed13c1a28ab03969e1cca22cc9ffe9a7e007f639
parent f335830bd76c3be4c55ce38ca56e5d09a1b0a5c8
Author: Marc Stibane <marc@taler.net>
Date:   Sun,  4 Feb 2024 14:47:39 +0100

shouldReloadBalances

Diffstat:
MTalerWallet1/Controllers/PublicConstants.swift | 2++
MTalerWallet1/Views/Balances/BalancesListView.swift | 5++++-
MTalerWallet1/Views/Balances/BalancesSectionView.swift | 24++++++++++++++++--------
MTalerWallet1/Views/Banking/ExchangeSectionView.swift | 9+++++++--
MTalerWallet1/Views/HelperViews/BarGraph.swift | 6++++--
5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -4,6 +4,8 @@ */ import Foundation +public let MAXRECENT = 4 +public let ICONLEADING = CGFloat(-8) public let HSPACING = CGFloat(10) // space between items in HStack public let LAUNCHDURATION: Double = 1.60 diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift b/TalerWallet1/Views/Balances/BalancesListView.swift @@ -95,6 +95,7 @@ struct BalancesListView: View { #endif Content(symLog: symLog, stack: stack.push(), balances: $balances, amountToTransfer: $amountToTransfer, summary: $summary, + shouldReloadBalances: $shouldReloadBalances, reloadBalances: reloadBalances) .navigationTitle(navTitle) .navigationBarItems(trailing: QRButton(action: checkCameraAvailable)) @@ -124,6 +125,7 @@ extension BalancesListView { @Binding var balances: [Balance] @Binding var amountToTransfer: Amount @Binding var summary: String + @Binding var shouldReloadBalances: Int var reloadBalances: (_ stack: CallStack, _ invalidateCache: Bool) async -> Int var body: some View { @@ -141,7 +143,8 @@ extension BalancesListView { balance: balance, // this is the currency to be used sectionCount: count, amountToTransfer: $amountToTransfer, // does still have the wrong currency - summary: $summary) + summary: $summary, + shouldReloadBalances: $shouldReloadBalances) } .onAppear() { DebugViewC.shared.setViewID(VIEW_BALANCES, stack: stack.push("onAppear")) diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift @@ -21,6 +21,7 @@ struct BalancesSectionView { let sectionCount: Int @Binding var amountToTransfer: Amount // does still have the wrong currency @Binding var summary: String + @Binding var shouldReloadBalances: Int @EnvironmentObject private var model: WalletModel @EnvironmentObject private var controller: Controller @@ -59,13 +60,13 @@ extension BalancesSectionView: View { let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif let currency = balance.scopeInfo.currency - let currencyInfo = controller.info(for: currency, controller.currencyTicker) + let currencyInfo = controller.info(for: currency) Section { let showSpendingButton = "KUDOS" == currency && !balance.available.isZero if showSpendingButton { if !iconOnly && showSpendingHint { - Text("You can spend these KUDOS in the Demo Shop, or send them to another wallet.") + Text("You can spend these \(currencyInfo?.scope.currency ?? currency) in the Demo Shop, or send them to another wallet.") .accessibilityFont(.body) .multilineTextAlignment(.leading) .listRowSeparator(.hidden) @@ -96,13 +97,17 @@ extension BalancesSectionView: View { pendingTransactions: $pendingTransactions, reloadPending: reloadPending, reloadOneAction: reloadOneAction) + .padding(.leading, ICONLEADING) } } header: { - BarGraphHeader(stack: stack.push(), currency: currencyInfo.scope.currency) + BarGraphHeader(stack: stack.push(), currency: currency, + currencyName: currencyInfo?.scope.currency ?? currency, + shouldReloadBalances: $shouldReloadBalances) }.id(sectionID) - .task { + .task(id: shouldReloadBalances + 1_000_000) { // if shownSectionID != sectionID { symLog.log(".task for BalancesSectionView - reload Transactions") + // TODO: only load the MAXRECENT most recent transactions let response = await model.transactionsT(stack.push(".task - reload Transactions"), currency: currency) transactions = response pendingTransactions = WalletModel.pendingTransactions(response) @@ -113,19 +118,22 @@ extension BalancesSectionView: View { // } } let transactionCount = completedTransactions.count - /// if there is only one currency, then show recent transactions + /// if there is only one currency, then show MAXRECENT recent transactions if sectionCount == 1 && transactionCount > 0 { Section { - let slice = completedTransactions.prefix(3) // already sorted + let slice = completedTransactions.prefix(MAXRECENT) // already sorted let threeTransactions = Array(slice) TransactionsArraySliceV(symLog: symLog, stack: stack.push(), currency: currency, transactions: threeTransactions, reloadOneAction: reloadOneAction) + .padding(.leading, ICONLEADING) } header: { if !iconOnly { - Text("Recent transactions") + let count = transactionCount > MAXRECENT ? MAXRECENT : transactionCount + Text(count > 1 ? "Recent \(count) transactions" + : "Recent transaction") .accessibilityFont(.callout) // .foregroundColor(colorSchemeContrast == .increased ? .primary : .secondary) } @@ -133,7 +141,7 @@ extension BalancesSectionView: View { } // recent transactions } // body } // BalancesSectionView - +// MARK: - fileprivate struct BalancesPendingRowView: View { let symLog: SymLogV? let stack: CallStack diff --git a/TalerWallet1/Views/Banking/ExchangeSectionView.swift b/TalerWallet1/Views/Banking/ExchangeSectionView.swift @@ -13,18 +13,22 @@ struct ExchangeSectionView: View { let currency: String // this is the currency to be used let exchanges: [Exchange] @Binding var amountToTransfer: Amount // does still have the wrong currency + @EnvironmentObject private var controller: Controller @AppStorage("iconOnly") var iconOnly: Bool = false + @State private var shouldReloadBalances: Int = 0 var body: some View { #if PRINT_CHANGES let _ = Self._printChanges() // let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif + let currencyInfo = controller.info(for: currency) + let currencyName = currencyInfo?.scope.currency ?? currency Section { ForEach(exchanges) { exchange in ExchangeRowView(stack: stack.push(), exchange: exchange, - currency: currency, // TODO: (balance.available) amount.isZero to disable Deposit-button + currency: currencyName, // TODO: (balance.available) amount.isZero to disable Deposit-button amountToTransfer: $amountToTransfer) // does still have the wrong currency .listRowSeparator(.hidden) } @@ -43,7 +47,8 @@ struct ExchangeSectionView: View { .padding(.top) } } header: { - BarGraphHeader(stack: stack.push(), currency: currency) + BarGraphHeader(stack: stack.push(), currency: currency, currencyName: currencyName, + shouldReloadBalances: $shouldReloadBalances) } } } diff --git a/TalerWallet1/Views/HelperViews/BarGraph.swift b/TalerWallet1/Views/HelperViews/BarGraph.swift @@ -11,6 +11,8 @@ struct BarGraphHeader: View { private let symLog = SymLogV(0) let stack: CallStack let currency: String + let currencyName: String + @Binding var shouldReloadBalances: Int @EnvironmentObject private var model: WalletModel @Environment(\.colorSchemeContrast) private var colorSchemeContrast @@ -20,13 +22,13 @@ struct BarGraphHeader: View { var body: some View { HStack (alignment: .center, spacing: 10) { - Text(currency) + Text(currencyName) .accessibilityFont(.title2) // .foregroundColor(colorSchemeContrast == .increased ? .primary : .secondary) BarGraph(transactions: $completedTransactions, maxBars: MAXBARS, barHeight: barHeight) } - .task { + .task(id: shouldReloadBalances + 2_000_000) { symLog.log(".task for BarGraphHeader(\(currency)) - reload Transactions") // TODO: only load the 10 most recent transactions let response = await model.transactionsT(stack.push(".task - reload Transactions for \(currency)"),