@@ -43,24 +43,6 @@ class WalletViewModel {
43
43
bdkClient. needsFullScan ( )
44
44
}
45
45
46
- // private var updateProgress: @Sendable (UInt64, UInt64) -> Void {
47
- // { [weak self] inspected, total in
48
- // DispatchQueue.main.async {
49
- // self?.totalScripts = total
50
- // self?.inspectedScripts = inspected
51
- // self?.progress = total > 0 ? Float(inspected) / Float(total) : 0
52
- // }
53
- // }
54
- // }
55
- //
56
- // private var updateProgressFullScan: @Sendable (UInt64) -> Void {
57
- // { [weak self] inspected in
58
- // DispatchQueue.main.async {
59
- // self?.inspectedScripts = inspected
60
- // }
61
- // }
62
- // }
63
-
64
46
init (
65
47
bdkClient: BDKClient = . live,
66
48
keyClient: KeyClient = . live,
@@ -125,11 +107,7 @@ class WalletViewModel {
125
107
self . walletSyncState = . syncing
126
108
do {
127
109
try await bdkClient. syncScanWithSyncScanProgress { [ weak self] inspected, total in
128
- DispatchQueue . main. async {
129
- self ? . totalScripts = total
130
- self ? . inspectedScripts = inspected
131
- self ? . progress = total > 0 ? Float ( inspected) / Float( total) : 0
132
- }
110
+ self ? . updateSyncProgress ( inspected, total)
133
111
}
134
112
self . walletSyncState = . synced
135
113
} catch let error as CannotConnectError {
@@ -154,9 +132,7 @@ class WalletViewModel {
154
132
self . walletSyncState = . syncing
155
133
do {
156
134
try await bdkClient. fullScanWithFullScanProgress { [ weak self] progress in
157
- DispatchQueue . main. async {
158
- self ? . inspectedScripts = progress
159
- }
135
+ self ? . updateFullProgress ( progress)
160
136
}
161
137
self . walletSyncState = . synced
162
138
} catch let error as CannotConnectError {
@@ -173,4 +149,19 @@ class WalletViewModel {
173
149
self . showingWalletViewErrorAlert = true
174
150
}
175
151
}
152
+
153
+ private func updateFullProgress( _ progress: UInt64 ) {
154
+ DispatchQueue . main. async { [ weak self] in
155
+ self ? . inspectedScripts = progress
156
+ }
157
+ }
158
+
159
+ private func updateSyncProgress( _ inspected: UInt64 , _ total: UInt64 ) {
160
+ DispatchQueue . main. async { [ weak self] in
161
+ self ? . totalScripts = total
162
+ self ? . inspectedScripts = inspected
163
+ self ? . progress = total > 0 ? Float ( inspected) / Float( total) : 0
164
+ }
165
+ }
166
+
176
167
}
0 commit comments