Skip to content

Commit

Permalink
ui: import view (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Sep 22, 2024
1 parent 6c7fb3f commit 42fa2df
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 21 deletions.
9 changes: 6 additions & 3 deletions BDKSwiftExampleWallet/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
}
}
}
},
"(Optional) Import 12 Word Seed Phrase" : {

},
"/" : {
"localizations" : {
Expand Down Expand Up @@ -181,6 +178,9 @@
}
}
}
},
"12 Word Seed Phrase" : {

},
"12 Word Seed Phrase (Optional)" : {
"extractionState" : "stale",
Expand Down Expand Up @@ -404,6 +404,9 @@
}
}
}
},
"Import" : {

},
"Navigation Title" : {
"extractionState" : "stale",
Expand Down
94 changes: 76 additions & 18 deletions BDKSwiftExampleWallet/View/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) {
Expand Down Expand Up @@ -49,6 +74,7 @@ struct OnboardingView: View {
.multilineTextAlignment(.center)
.padding()
}
.padding()

Picker(
"Network",
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 42fa2df

Please sign in to comment.