commit 1979eb64dbf46d5a7ae4e94b2a58a690dd33b8ce
parent 95ed69a443590c5d3c2edc103b8e2b4b47092eaa
Author: Marc Stibane <marc@taler.net>
Date: Wed, 8 May 2024 22:30:20 +0200
prepare pending tx reload on errors
Diffstat:
4 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift
@@ -196,16 +196,15 @@ extension WalletCore {
@MainActor private func handleStateTransition(_ jsonData: Data) throws {
do {
let decoded = try JSONDecoder().decode(TransactionTransition.self, from: jsonData)
+ if let errorInfo = decoded.errorInfo {
+ // reload pending transaction list to add error badge
+ postNotification(.TransactionError, userInfo: [NOTIFICATIONERROR: WalletBackendError.walletCoreError(errorInfo)])
+ }
guard decoded.newTxState != decoded.oldTxState else {
- // TODO: Same state usually means that an error is transmitted
logger.info("No State change: \(decoded.transactionId, privacy: .private(mask: .hash))")
return
}
- if decoded.errorInfo == nil {
- postNotification(.Error, userInfo: [NOTIFICATIONERROR: decoded.errorInfo])
- }
-
let components = decoded.transactionId.components(separatedBy: ":")
if components.count >= 3 { // txn:$txtype:$uid
if let type = TransactionType(rawValue: components[1]) {
diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift
@@ -84,7 +84,9 @@ extension Notification.Name {
static let ProposalDownloaded = Notification.Name("proposal-downloaded")
static let TaskObservabilityEvent = Notification.Name("task-observability-event")
static let RequestObservabilityEvent = Notification.Name("request-observability-event")
+
static let Error = Notification.Name("error")
+ static let TransactionError = Notification.Name("txError")
}
/// Notifications for internal synchronization
diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift b/TalerWallet1/Views/Balances/BalancesListView.swift
@@ -13,6 +13,7 @@ struct BalancesListView: View {
let stack: CallStack
let navTitle: String
@Binding var balances: [Balance]
+// @Binding var shouldReloadPending: Int
@Binding var shouldReloadBalances: Int
@EnvironmentObject private var model: WalletModel
@@ -100,6 +101,7 @@ struct BalancesListView: View {
#endif
Content(symLog: symLog, stack: stack.push(), balances: $balances,
amountToTransfer: $amountToTransfer, summary: $summary,
+// shouldReloadPending: $shouldReloadPending,
shouldReloadBalances: $shouldReloadBalances,
reloadBalances: reloadBalances)
.navigationTitle(navTitle)
@@ -130,6 +132,7 @@ extension BalancesListView {
@Binding var balances: [Balance]
@Binding var amountToTransfer: Amount
@Binding var summary: String
+// @Binding var shouldReloadPending: Int
@Binding var shouldReloadBalances: Int
var reloadBalances: (_ stack: CallStack, _ invalidateCache: Bool) async -> Int?
diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift
@@ -121,6 +121,7 @@ extension MainView {
@EnvironmentObject private var viewState2: ViewState2 // popToRootView()
@State private var shouldReloadBalances = 0
+ @State private var shouldReloadPending = 0
@State private var balances: [Balance] = []
@State private var selectedTab: Tab = .balances
@State private var showKycAlert: Bool = false
@@ -193,6 +194,7 @@ extension MainView {
BalancesListView(stack: stack.push(balancesTitle),
navTitle: balancesTitle,
balances: $balances,
+// shouldReloadPending: $shouldReloadPending,
shouldReloadBalances: $shouldReloadBalances)
}.id(viewState.rootViewId) // any change to rootViewId triggers popToRootView behaviour
.navigationViewStyle(.stack)
@@ -255,14 +257,19 @@ extension MainView {
shouldReloadBalances += 1
}
.onNotification(.TransactionExpired) { notification in
- // reload balances on receiving BalanceChange notification ...
+ // reload balances on receiving TransactionExpired notification ...
logger.info(".onNotification(.TransactionExpired) ==> reload")
shouldReloadBalances += 1
+ shouldReloadPending += 1
}
.onNotification(.TransactionDone) {
shouldReloadBalances += 1
+ shouldReloadPending += 1
selectedTab = .balances
}
+ .onNotification(.TransactionError) { notification in
+ shouldReloadPending += 1
+ }
.onNotification(.Error) { notification in
if let error = notification.userInfo?[NOTIFICATIONERROR] as? Error {
model.setError(error)