From 965975343b97c819cb1a687fb2d552b6c7868713 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 16 Nov 2025 17:25:09 -0600 Subject: [PATCH] fix: update kyoto balance when synced --- .../Extensions/Notification+Extensions.swift | 1 + .../Service/BDK Service/BDKService.swift | 2 ++ .../View Model/WalletViewModel.swift | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/BDKSwiftExampleWallet/Extensions/Notification+Extensions.swift b/BDKSwiftExampleWallet/Extensions/Notification+Extensions.swift index fdfc2c08..ea6f42d7 100644 --- a/BDKSwiftExampleWallet/Extensions/Notification+Extensions.swift +++ b/BDKSwiftExampleWallet/Extensions/Notification+Extensions.swift @@ -9,4 +9,5 @@ import Foundation extension Notification.Name { static let walletCreated = Notification.Name("walletCreated") + static let walletDidUpdate = Notification.Name("walletDidUpdate") } diff --git a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift index cdd6ab80..7343f516 100644 --- a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift +++ b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift @@ -641,6 +641,7 @@ final class BDKService { throw WalletError.dbNotFound } let _ = try wallet.persist(persister: persister) + NotificationCenter.default.post(name: .walletDidUpdate, object: nil) } func fullScanWithInspector(inspector: FullScanScriptInspector) async throws { @@ -663,6 +664,7 @@ final class BDKService { throw WalletError.dbNotFound } let _ = try wallet.persist(persister: persister) + NotificationCenter.default.post(name: .walletDidUpdate, object: nil) } func calculateFee(tx: Transaction) throws -> Amount { diff --git a/BDKSwiftExampleWallet/View Model/WalletViewModel.swift b/BDKSwiftExampleWallet/View Model/WalletViewModel.swift index 726df404..9001d8ae 100644 --- a/BDKSwiftExampleWallet/View Model/WalletViewModel.swift +++ b/BDKSwiftExampleWallet/View Model/WalletViewModel.swift @@ -164,6 +164,19 @@ class WalletViewModel { } } } + + NotificationCenter.default.addObserver( + forName: .walletDidUpdate, + object: nil, + queue: .main + ) { [weak self] _ in + guard let self else { return } + self.getBalance() + self.getTransactions() + Task { + await self.getPrices() + } + } } private func fullScanWithProgress() async {