@@ -50,7 +50,7 @@ class WalletViewModel {
5050
5151 private var updateProgress : @Sendable ( UInt64 , UInt64 ) -> Void {
5252 { [ weak self] inspected, total in
53- DispatchQueue . main . async {
53+ Task { @ MainActor [ weak self ] in
5454 // When using Kyoto, progress is provided separately as percent
5555 if self ? . isKyotoClient == true { return }
5656 self ? . totalScripts = total
@@ -63,7 +63,7 @@ class WalletViewModel {
6363
6464 private var updateKyotoProgress : @Sendable ( Float ) -> Void {
6565 { [ weak self] rawProgress in
66- DispatchQueue . main . async { [ weak self] in
66+ Task { @ MainActor [ weak self] in
6767 guard let self else { return }
6868 let sanitized = rawProgress. isFinite ? min ( max ( rawProgress, 0 ) , 100 ) : 0
6969 self . progress = sanitized
@@ -75,7 +75,7 @@ class WalletViewModel {
7575
7676 private var updateProgressFullScan : @Sendable ( UInt64 ) -> Void {
7777 { [ weak self] inspected in
78- DispatchQueue . main . async {
78+ Task { @ MainActor [ weak self ] in
7979 self ? . inspectedScripts = inspected
8080 }
8181 }
@@ -99,25 +99,27 @@ class WalletViewModel {
9999 object: nil ,
100100 queue: . main
101101 ) { [ weak self] notification in
102- guard let self else { return }
103- // Ignore Kyoto updates unless client type is Kyoto
104- if self . bdkClient. getClientType ( ) != . kyoto { return }
105- if let progress = notification. userInfo ? [ " progress " ] as? Float {
106- self . updateKyotoProgress ( progress)
107- if let height = notification. userInfo ? [ " height " ] as? Int {
108- self . currentBlockHeight = UInt32 ( max ( height, 0 ) )
109- }
110- // Consider any progress update as evidence of an active connection
111- // so the UI does not falsely show a red disconnected indicator while syncing.
112- if progress > 0 {
113- self . isKyotoConnected = true
114- }
102+ Task { @MainActor [ weak self] in
103+ guard let self else { return }
104+ // Ignore Kyoto updates unless client type is Kyoto
105+ if self . bdkClient. getClientType ( ) != . kyoto { return }
106+ if let progress = notification. userInfo ? [ " progress " ] as? Float {
107+ self . updateKyotoProgress ( progress)
108+ if let height = notification. userInfo ? [ " height " ] as? Int {
109+ self . currentBlockHeight = UInt32 ( max ( height, 0 ) )
110+ }
111+ // Consider any progress update as evidence of an active connection
112+ // so the UI does not falsely show a red disconnected indicator while syncing.
113+ if progress > 0 {
114+ self . isKyotoConnected = true
115+ }
115116
116- // Update sync state based on Kyoto progress
117- if progress >= 100 {
118- self . walletSyncState = . synced
119- } else if progress > 0 {
120- self . walletSyncState = . syncing
117+ // Update sync state based on Kyoto progress
118+ if progress >= 100 {
119+ self . walletSyncState = . synced
120+ } else if progress > 0 {
121+ self . walletSyncState = . syncing
122+ }
121123 }
122124 }
123125 }
@@ -127,16 +129,19 @@ class WalletViewModel {
127129 object: nil ,
128130 queue: . main
129131 ) { [ weak self] notification in
130- if let connected = notification. userInfo ? [ " connected " ] as? Bool {
131- self ? . isKyotoConnected = connected
132+ Task { @MainActor [ weak self] in
133+ guard let self else { return }
134+ if let connected = notification. userInfo ? [ " connected " ] as? Bool {
135+ self . isKyotoConnected = connected
132136
133- // When Kyoto connects, update sync state if needed
134- if connected && self ? . walletSyncState == . notStarted {
135- // Check current progress to determine state
136- if let progress = self ? . progress, progress >= 100 {
137- self ? . walletSyncState = . synced
138- } else {
139- self ? . walletSyncState = . syncing
137+ // When Kyoto connects, update sync state if needed
138+ if connected && self . walletSyncState == . notStarted {
139+ // Check current progress to determine state
140+ if self . progress >= 100 {
141+ self . walletSyncState = . synced
142+ } else {
143+ self . walletSyncState = . syncing
144+ }
140145 }
141146 }
142147 }
@@ -147,19 +152,19 @@ class WalletViewModel {
147152 object: nil ,
148153 queue: . main
149154 ) { [ weak self] notification in
150- guard let self else { return }
151- // Ignore Kyoto updates unless client type is Kyoto
152- if self . bdkClient . getClientType ( ) != . kyoto { return }
153- if let height = notification . userInfo ? [ " height " ] as? Int {
154- self . currentBlockHeight = UInt32 ( max ( height, 0 ) )
155- // Receiving chain height implies we have peer connectivity
156- self . isKyotoConnected = true
157- // Ensure UI reflects syncing as soon as we see chain activity
158- if self . walletSyncState == . notStarted { self . walletSyncState = . syncing }
159- // Auto-refresh wallet data when Kyoto receives new blocks
160- self . getBalance ( )
161- self . getTransactions ( )
162- Task {
155+ Task { @ MainActor [ weak self ] in
156+ guard let self else { return }
157+ // Ignore Kyoto updates unless client type is Kyoto
158+ if self . bdkClient . getClientType ( ) != . kyoto { return }
159+ if let height = notification . userInfo ? [ " height " ] as? Int {
160+ self . currentBlockHeight = UInt32 ( max ( height , 0 ) )
161+ // Receiving chain height implies we have peer connectivity
162+ self . isKyotoConnected = true
163+ // Ensure UI reflects syncing as soon as we see chain activity
164+ if self . walletSyncState == . notStarted { self . walletSyncState = . syncing }
165+ // Auto-refresh wallet data when Kyoto receives new blocks
166+ self . getBalance ( )
167+ self . getTransactions ( )
163168 await self . getPrices ( )
164169 }
165170 }
@@ -170,10 +175,10 @@ class WalletViewModel {
170175 object: nil ,
171176 queue: . main
172177 ) { [ weak self] _ in
173- guard let self else { return }
174- self . getBalance ( )
175- self . getTransactions ( )
176- Task {
178+ Task { @ MainActor [ weak self ] in
179+ guard let self else { return }
180+ self . getBalance ( )
181+ self . getTransactions ( )
177182 await self . getPrices ( )
178183 }
179184 }
0 commit comments