Skip to content

Commit 3835d7f

Browse files
committed
fix: wallet loading
1 parent c29f840 commit 3835d7f

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

BDKSwiftExampleWallet/Resources/Localizable.xcstrings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@
421421
}
422422
}
423423
}
424+
},
425+
"Loading wallet..." : {
426+
424427
},
425428
"Navigation Title" : {
426429
"extractionState" : "stale",

BDKSwiftExampleWallet/View Model/HomeViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class HomeViewModel: ObservableObject {
1414
let bdkClient: BDKClient
1515

1616
var homeViewError: AppError?
17+
var isWalletLoaded = false
1718
var showingHomeViewErrorAlert = false
1819

1920
init(bdkClient: BDKClient = .live) {
@@ -23,6 +24,7 @@ class HomeViewModel: ObservableObject {
2324
func loadWallet() {
2425
do {
2526
try bdkClient.loadWallet()
27+
isWalletLoaded = true
2628
} catch let error as DescriptorError {
2729
let errorMessage: String
2830
switch error {

BDKSwiftExampleWallet/View/HomeView.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ struct HomeView: View {
1212
@Binding var navigationPath: NavigationPath
1313

1414
var body: some View {
15-
1615
ZStack {
1716
Color(uiColor: UIColor.systemBackground)
1817

19-
WalletView(
20-
viewModel: .init(
21-
bdkClient: .live,
22-
priceClient: .live
23-
),
24-
sendNavigationPath: $navigationPath
25-
)
26-
.tint(.primary)
27-
.onAppear {
28-
viewModel.loadWallet()
18+
if !viewModel.isWalletLoaded {
19+
ProgressView("Loading wallet...")
20+
} else {
21+
WalletView(
22+
viewModel: .init(
23+
bdkClient: .live,
24+
priceClient: .live
25+
),
26+
sendNavigationPath: $navigationPath
27+
)
28+
.tint(.primary)
2929
}
30-
30+
}
31+
.onAppear {
32+
viewModel.loadWallet()
3133
}
3234
.alert(isPresented: $viewModel.showingHomeViewErrorAlert) {
3335
Alert(

0 commit comments

Comments
 (0)