Skip to content

Commit 946479a

Browse files
authored
fix: update kyoto balance when synced
1 parent d4eadce commit 946479a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

BDKSwiftExampleWallet/Extensions/Notification+Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import Foundation
99

1010
extension Notification.Name {
1111
static let walletCreated = Notification.Name("walletCreated")
12+
static let walletDidUpdate = Notification.Name("walletDidUpdate")
1213
}

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ final class BDKService {
641641
throw WalletError.dbNotFound
642642
}
643643
let _ = try wallet.persist(persister: persister)
644+
NotificationCenter.default.post(name: .walletDidUpdate, object: nil)
644645
}
645646

646647
func fullScanWithInspector(inspector: FullScanScriptInspector) async throws {
@@ -663,6 +664,7 @@ final class BDKService {
663664
throw WalletError.dbNotFound
664665
}
665666
let _ = try wallet.persist(persister: persister)
667+
NotificationCenter.default.post(name: .walletDidUpdate, object: nil)
666668
}
667669

668670
func calculateFee(tx: Transaction) throws -> Amount {

BDKSwiftExampleWallet/View Model/WalletViewModel.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ class WalletViewModel {
164164
}
165165
}
166166
}
167+
168+
NotificationCenter.default.addObserver(
169+
forName: .walletDidUpdate,
170+
object: nil,
171+
queue: .main
172+
) { [weak self] _ in
173+
guard let self else { return }
174+
self.getBalance()
175+
self.getTransactions()
176+
Task {
177+
await self.getPrices()
178+
}
179+
}
167180
}
168181

169182
private func fullScanWithProgress() async {

0 commit comments

Comments
 (0)