Skip to content

Commit bf844b5

Browse files
committed
chore: organizing code
1 parent 8c2a9d9 commit bf844b5

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

BDKSwiftExampleWallet/View Model/WalletViewModel.swift

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ class WalletViewModel {
4343
bdkClient.needsFullScan()
4444
}
4545

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-
6446
init(
6547
bdkClient: BDKClient = .live,
6648
keyClient: KeyClient = .live,
@@ -125,11 +107,7 @@ class WalletViewModel {
125107
self.walletSyncState = .syncing
126108
do {
127109
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)
133111
}
134112
self.walletSyncState = .synced
135113
} catch let error as CannotConnectError {
@@ -154,9 +132,7 @@ class WalletViewModel {
154132
self.walletSyncState = .syncing
155133
do {
156134
try await bdkClient.fullScanWithFullScanProgress { [weak self] progress in
157-
DispatchQueue.main.async {
158-
self?.inspectedScripts = progress
159-
}
135+
self?.updateFullProgress(progress)
160136
}
161137
self.walletSyncState = .synced
162138
} catch let error as CannotConnectError {
@@ -173,4 +149,19 @@ class WalletViewModel {
173149
self.showingWalletViewErrorAlert = true
174150
}
175151
}
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+
176167
}

0 commit comments

Comments
 (0)