diff --git a/BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift b/BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift index cde3b0f0..7a054f50 100644 --- a/BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift +++ b/BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift @@ -16,13 +16,17 @@ struct BDKSwiftExampleWalletApp: App { var body: some Scene { WindowGroup { NavigationStack(path: $navigationPath) { - if isOnboarding { + let value = try? KeyClient.live.getBackupInfo() + if isOnboarding && (value == nil) { + OnboardingView(viewModel: .init(bdkClient: .live)) + } else if !isOnboarding && (value == nil) { OnboardingView(viewModel: .init(bdkClient: .live)) } else { - HomeView(viewModel: .init(bdkClient: .live)) + HomeView(viewModel: .init(bdkClient: .live), navigationPath: $navigationPath) } } .onChange(of: isOnboarding) { oldValue, newValue in + BDKClient.live.setNeedsFullScan(true) navigationPath = NavigationPath() } } diff --git a/BDKSwiftExampleWallet/View Model/HomeViewModel.swift b/BDKSwiftExampleWallet/View Model/HomeViewModel.swift index a0637e65..8fac658a 100644 --- a/BDKSwiftExampleWallet/View Model/HomeViewModel.swift +++ b/BDKSwiftExampleWallet/View Model/HomeViewModel.swift @@ -29,6 +29,9 @@ class HomeViewModel: ObservableObject { } catch let error as LoadWithPersistError { self.homeViewError = .generic(message: error.localizedDescription) self.showingHomeViewErrorAlert = true + } catch let error as KeyServiceError { + self.homeViewError = .generic(message: error.localizedDescription) + self.showingHomeViewErrorAlert = true } catch { self.homeViewError = .generic(message: error.localizedDescription) self.showingHomeViewErrorAlert = true diff --git a/BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift b/BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift index 19bf3519..21b82d66 100644 --- a/BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift +++ b/BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift @@ -101,7 +101,9 @@ class OnboardingViewModel: ObservableObject { func createWallet() { do { try bdkClient.createWallet(words) - isOnboarding = false + DispatchQueue.main.async { + self.isOnboarding = false + } } catch let error as CreateWithPersistError { DispatchQueue.main.async { self.createWithPersistError = error diff --git a/BDKSwiftExampleWallet/View/HomeView.swift b/BDKSwiftExampleWallet/View/HomeView.swift index 3258be79..167fbcf7 100644 --- a/BDKSwiftExampleWallet/View/HomeView.swift +++ b/BDKSwiftExampleWallet/View/HomeView.swift @@ -9,6 +9,7 @@ import SwiftUI struct HomeView: View { @Bindable var viewModel: HomeViewModel + @Binding var navigationPath: NavigationPath var body: some View { @@ -19,7 +20,8 @@ struct HomeView: View { viewModel: .init( priceClient: .live, bdkClient: .live - ) + ), + sendNavigationPath: $navigationPath ) .tint(.primary) .onAppear { @@ -50,6 +52,9 @@ enum NavigationDestination: Hashable { #if DEBUG #Preview { - HomeView(viewModel: .init(bdkClient: .mock)) + HomeView( + viewModel: .init(bdkClient: .mock), + navigationPath: .constant(.init()) + ) } #endif diff --git a/BDKSwiftExampleWallet/View/Send/AddressView.swift b/BDKSwiftExampleWallet/View/Send/AddressView.swift index a0abf2df..e92e9e2a 100644 --- a/BDKSwiftExampleWallet/View/Send/AddressView.swift +++ b/BDKSwiftExampleWallet/View/Send/AddressView.swift @@ -95,8 +95,12 @@ struct CustomScannerView: View { var body: some View { GeometryReader { geometry in ZStack(alignment: .top) { - CodeScannerView(codeTypes: codeTypes, completion: completion) - .edgesIgnoringSafeArea(.all) + CodeScannerView( + codeTypes: codeTypes, + shouldVibrateOnSuccess: true, + completion: completion + ) + .edgesIgnoringSafeArea(.all) VStack { HStack { diff --git a/BDKSwiftExampleWallet/View/WalletView.swift b/BDKSwiftExampleWallet/View/WalletView.swift index b03a1962..3c1bc744 100644 --- a/BDKSwiftExampleWallet/View/WalletView.swift +++ b/BDKSwiftExampleWallet/View/WalletView.swift @@ -17,7 +17,7 @@ struct WalletView: View { @State private var showAllTransactions = false @State private var showReceiveView = false @State private var showSettingsView = false - @State private var sendNavigationPath = NavigationPath() + @Binding var sendNavigationPath: NavigationPath var body: some View { @@ -299,7 +299,8 @@ struct WalletView: View { bdkClient: .mock, walletSyncState: .synced, transactions: [.mock] - ) + ), + sendNavigationPath: .constant(.init()) ) } #endif