From ad735c394c549b3ed422bfe28c0583ffc29c5d73 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 21 Sep 2024 20:49:31 -0500 Subject: [PATCH] ui: import view --- .../Resources/Localizable.xcstrings | 9 +- .../View/OnboardingView.swift | 94 +++++++++++++++---- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/BDKSwiftExampleWallet/Resources/Localizable.xcstrings b/BDKSwiftExampleWallet/Resources/Localizable.xcstrings index abc5cac..885ae10 100644 --- a/BDKSwiftExampleWallet/Resources/Localizable.xcstrings +++ b/BDKSwiftExampleWallet/Resources/Localizable.xcstrings @@ -70,9 +70,6 @@ } } } - }, - "(Optional) Import 12 Word Seed Phrase" : { - }, "/" : { "localizations" : { @@ -181,6 +178,9 @@ } } } + }, + "12 Word Seed Phrase" : { + }, "12 Word Seed Phrase (Optional)" : { "extractionState" : "stale", @@ -404,6 +404,9 @@ } } } + }, + "Import" : { + }, "Navigation Title" : { "extractionState" : "stale", diff --git a/BDKSwiftExampleWallet/View/OnboardingView.swift b/BDKSwiftExampleWallet/View/OnboardingView.swift index bd8c784..f28c90f 100644 --- a/BDKSwiftExampleWallet/View/OnboardingView.swift +++ b/BDKSwiftExampleWallet/View/OnboardingView.swift @@ -13,6 +13,7 @@ struct OnboardingView: View { @ObservedObject var viewModel: OnboardingViewModel @AppStorage("isOnboarding") var isOnboarding: Bool? @State private var showingOnboardingViewErrorAlert = false + @State private var showingImportView = false var body: some View { @@ -22,6 +23,30 @@ struct OnboardingView: View { VStack { + HStack { + Spacer() + Button { + showingImportView = true + } label: { + Image( + systemName: viewModel.wordArray.isEmpty + ? "square.and.arrow.down" : "square.and.arrow.down.fill" + ) + } + .tint( + viewModel.wordArray.isEmpty ? .secondary : .primary + ) + .font(.title) + .padding() + .sheet(isPresented: $showingImportView) { + ImportView( + isPresented: $showingImportView, + importedWords: $viewModel.words + ) + .presentationDetents([.medium]) + } + } + Spacer() VStack(spacing: 25) { @@ -49,6 +74,7 @@ struct OnboardingView: View { .multilineTextAlignment(.center) .padding() } + .padding() Picker( "Network", @@ -81,26 +107,16 @@ struct OnboardingView: View { .pickerStyle(.automatic) .tint(.primary) - VStack { - TextField( - "(Optional) Import 12 Word Seed Phrase", - text: $viewModel.words + if viewModel.wordArray != [] { + SeedPhraseView( + words: viewModel.wordArray, + preferredWordsPerRow: 2, + usePaging: true, + wordsPerPage: 4 ) - .submitLabel(.done) - .textFieldStyle(RoundedBorderTextFieldStyle()) - .padding(.horizontal, 40) - if viewModel.wordArray != [] { - SeedPhraseView( - words: viewModel.wordArray, - preferredWordsPerRow: 2, - usePaging: true, - wordsPerPage: 4 - ) - .frame(height: 200) - } else { - } + .frame(height: 200) + .padding() } - .padding(.top, 30) Spacer() @@ -131,6 +147,48 @@ struct OnboardingView: View { } } +struct ImportView: View { + @Binding var isPresented: Bool + @Binding var importedWords: String + + private var wordArray: [String] { + importedWords.split(separator: " ").map(String.init) + } + + var body: some View { + + VStack { + + Spacer() + + TextField("12 Word Seed Phrase", text: $importedWords) + .submitLabel(.done) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .padding(.horizontal, 40) + + if !importedWords.isEmpty { + SeedPhraseView( + words: wordArray, + preferredWordsPerRow: 2, + usePaging: true, + wordsPerPage: 4 + ) + .frame(height: 200) + } + + Spacer() + + Button("Import") { + isPresented = false + } + .buttonStyle(BitcoinFilled(tintColor: .bitcoinOrange, isCapsule: true)) + .padding() + + } + + } +} + #if DEBUG #Preview("OnboardingView - en") { OnboardingView(viewModel: .init(bdkClient: .mock))