taler-ios

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

commit 8edd36d8c090ebb67c7ec72988d8fe65228cd6c4
parent ec19b36555d4f9fb3e138020c82f27e9c4745f5f
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 27 Jun 2023 14:20:34 +0200

balance-change

Diffstat:
MTalerWallet1/Backend/WalletCore.swift | 3++-
MTalerWallet1/Controllers/PublicConstants.swift | 1+
MTalerWallet1/Views/Balances/BalancesListView.swift | 17+++++++++++++----
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift @@ -202,6 +202,8 @@ print("\n❗️ \(pendingOp): \(id)\n") // this is a new pendingOp I have try handleStateTransition(jsonData) case Notification.Name.PendingOperationProcessed.rawValue: try handlePendingProcessed(payload) + case Notification.Name.BalanceChange.rawValue: + postNotification(.BalanceChange) case Notification.Name.ExchangeAdded.rawValue: postNotification(.ExchangeAdded) case Notification.Name.ReserveNotYetFound.rawValue: @@ -224,7 +226,6 @@ print("\n❗️ \(pendingOp): \(id)\n") // this is a new pendingOp I have // "pay-operation-success", // "withdrawal-group-bank-confirmed", // replaced by transaction-state-transition // "withdrawal-group-reserve-ready", -// "coin-withdrawn", // totally useless since wallet-core handles coins in bulk // "waiting-for-retry", // Bla Bla Bla case "refresh-started", "refresh-melted", "refresh-revealed", "refresh-unwarranted": diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -28,6 +28,7 @@ public let TALERURI = "talerUri" public let TRANSACTIONTRANSITION = "transactionTransition" extension Notification.Name { + static let BalanceChange = Notification.Name("balance-change") static let TransactionStateTransition = Notification.Name(TransactionTransition.TransitionType.transition.rawValue) static let ExchangeAdded = Notification.Name("exchange-added") static let PendingOperationProcessed = Notification.Name("pending-operation-processed") diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift b/TalerWallet1/Views/Balances/BalancesListView.swift @@ -110,6 +110,7 @@ extension BalancesListView { @Binding var summary: String var reloadAction: () async -> Void + @State private var shouldLoad = false var body: some View { #if DEBUG let _ = Self._printChanges() @@ -124,14 +125,22 @@ extension BalancesListView { .refreshable { symLog?.log("refreshing") await reloadAction() // this closure is already async, no need for a Task + // TODO: reload transactions } .listStyle(myListStyle.style).anyView } - // automatically fetch balances after receiving transaction-state-transition ... - .onNotification(.TransactionStateTransition) { notification in + .onAppear { + if shouldLoad { + shouldLoad = false + symLog?.log(".onAppear: shouldLoad ==> reloading balances") + Task { await reloadAction() } + } + } + // automatically reload balances after receiving BalanceChange notification ... + .onNotification(.BalanceChange) { notification in // doesn't need to be received on main thread because we just reload in the background anyway - symLog?.log(".onNotification(.TransactionStateTransition) ==> reloading balances") - Task { await reloadAction() } + symLog?.log(".onNotification(.BalanceChange) ==> shouldLoad = true") + shouldLoad = true } } // body } // Content