@@ -45,6 +45,7 @@ class WalletViewModel {
4545 var syncMode : SyncMode {
4646 bdkClient. getSyncMode ( ) ?? . esplora
4747 }
48+ var isConnected : Bool = false
4849
4950 init (
5051 bdkClient: BDKClient = . live,
@@ -58,13 +59,31 @@ class WalletViewModel {
5859 self . priceClient = priceClient
5960 self . transactions = transactions
6061 self . walletSyncState = walletSyncState
61- NotificationCenter . default. addObserver ( self , selector: #selector( receiveNotification ( _: ) ) , name: . shouldUpdateWallet, object: nil )
62+ addNotifications ( )
63+ }
64+
65+ deinit {
66+ NotificationCenter . default. removeObserver ( self )
67+ }
68+
69+ private func addNotifications( ) {
70+ NotificationCenter . default. addObserver ( self , selector: #selector( receiveNotification ( _: ) ) , name: . walletDidUpdate, object: nil )
71+ NotificationCenter . default. addObserver ( self , selector: #selector( receiveNotification ( _: ) ) , name: . walletDidConnect, object: nil )
72+ NotificationCenter . default. addObserver ( self , selector: #selector( receiveNotification ( _: ) ) , name: . walletDidConnect, object: nil )
6273 }
6374
6475 @objc private func receiveNotification( _ notification: Notification ) {
65- if notification. name == . shouldUpdateWallet {
76+ switch notification. name {
77+ case . walletDidUpdate:
6678 getBalance ( )
6779 getTransactions ( )
80+ case . walletDidConnect:
81+ isConnected = true
82+
83+ case . walletDidDisconnect:
84+ isConnected = false
85+
86+ default : break
6887 }
6988 }
7089
0 commit comments