Skip to content

Commit dd4ec93

Browse files
committed
scan desc+xpub
1 parent e1e1089 commit dd4ec93

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

BDKSwiftExampleWallet/Resources/Localizable.xcstrings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@
243243
}
244244
}
245245
}
246+
},
247+
"Backup is not synced across devices." : {
248+
246249
},
247250
"BDK Wallet" : {
248251
"extractionState" : "stale",
@@ -590,9 +593,6 @@
590593
},
591594
"Seed" : {
592595

593-
},
594-
"Seed is not synced across devices." : {
595-
596596
},
597597
"Select Bitcoin Network" : {
598598

BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OnboardingViewModel: ObservableObject {
2222
|| words.hasPrefix("sh(")
2323
}
2424
var isXPub: Bool {
25-
words.hasPrefix("xpub") || words.hasPrefix("tpub")
25+
words.hasPrefix("xpub") || words.hasPrefix("tpub") || words.hasPrefix("vpub")
2626
}
2727
@Published var networkColor = Color.gray
2828
@Published var onboardingViewError: AppError?
@@ -40,7 +40,7 @@ class OnboardingViewModel: ObservableObject {
4040
}
4141
@Published var words: String = ""
4242
var wordArray: [String] {
43-
if words.hasPrefix("xpub") || words.hasPrefix("tpub") {
43+
if words.hasPrefix("xpub") || words.hasPrefix("tpub") || words.hasPrefix("vpub") {
4444
return []
4545
}
4646
let trimmedWords = words.trimmingCharacters(in: .whitespacesAndNewlines)

BDKSwiftExampleWallet/View/OnboardingView.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct OnboardingView: View {
1414
@ObservedObject var viewModel: OnboardingViewModel
1515
@State private var showingOnboardingViewErrorAlert = false
1616
@State private var showingImportView = false
17+
@State private var showingScanner = false
1718
let pasteboard = UIPasteboard.general
1819

1920
var body: some View {
@@ -25,7 +26,24 @@ struct OnboardingView: View {
2526
VStack {
2627

2728
HStack {
29+
2830
Spacer()
31+
32+
Button {
33+
showingScanner = true
34+
} label: {
35+
Image(
36+
systemName: viewModel.words.isEmpty
37+
? "qrcode.viewfinder" : "clear"
38+
)
39+
.contentTransition(.symbolEffect(.replace))
40+
}
41+
.tint(
42+
viewModel.words.isEmpty ? .secondary : .primary
43+
)
44+
.font(.title)
45+
.padding()
46+
2947
Button {
3048
if viewModel.words.isEmpty {
3149
if let clipboardContent = UIPasteboard.general.string {
@@ -153,6 +171,24 @@ struct OnboardingView: View {
153171
}
154172
)
155173
}
174+
.sheet(isPresented: $showingScanner) {
175+
CustomScannerView(
176+
codeTypes: [.qr],
177+
completion: { result in
178+
switch result {
179+
case .success(let result):
180+
viewModel.words = result.string
181+
showingScanner = false
182+
case .failure(let error):
183+
viewModel.onboardingViewError = .generic(
184+
message: error.localizedDescription
185+
)
186+
showingScanner = false
187+
}
188+
},
189+
pasteAction: {}
190+
)
191+
}
156192

157193
}
158194
}

0 commit comments

Comments
 (0)