Skip to content

Commit 6db1270

Browse files
committed
nav: wip
1 parent 92ae5f6 commit 6db1270

File tree

7 files changed

+166
-71
lines changed

7 files changed

+166
-71
lines changed

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ private class BDKService {
170170
amount: amount,
171171
feeRate: feeRate
172172
)
173-
try signAndBroadcast(psbt: psbt)
173+
try! signAndBroadcast(psbt: psbt)
174+
print("send sended")
174175
}
175176

176177
func buildTransaction(address: String, amount: UInt64, feeRate: UInt64) throws

BDKSwiftExampleWallet/View Model/BuildTransactionViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class BuildTransactionViewModel {
4444
name: Notification.Name("TransactionSent"),
4545
object: nil
4646
)
47+
print("Sent!")
4748
} catch let error as EsploraError {
4849
self.buildTransactionViewError = .generic(message: error.localizedDescription)
4950
self.showingBuildTransactionViewErrorAlert = true

BDKSwiftExampleWallet/View/AddressView.swift

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import SwiftUI
1212
struct AddressView: View {
1313
let amount: String
1414
@State var address: String = ""
15-
@Binding var rootIsActive: Bool
15+
// @Binding var rootIsActive: Bool
16+
@Binding var navigationPath: NavigationPath
1617
let pasteboard = UIPasteboard.general
1718
@State private var isShowingScanner = false
1819
@State private var isShowingAlert = false
@@ -99,23 +100,34 @@ struct AddressView: View {
99100

100101
Spacer()
101102

102-
NavigationLink(
103-
destination:
104-
FeeView(
105-
amount: amount,
106-
address: address,
107-
viewModel: .init(),
108-
rootIsActive: self.$rootIsActive
109-
)
110-
) {
111-
Label(
112-
title: { Text("Next") },
113-
icon: { Image(systemName: "arrow.right") }
114-
)
115-
.labelStyle(.iconOnly)
116-
}
117-
.isDetailLink(false)
118-
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
103+
// NavigationLink(
104+
// destination:
105+
// FeeView(
106+
// amount: amount,
107+
// address: address,
108+
// viewModel: .init(),
109+
// rootIsActive: self.$rootIsActive
110+
// )
111+
// ) {
112+
// Label(
113+
// title: { Text("Next") },
114+
// icon: { Image(systemName: "arrow.right") }
115+
// )
116+
// .labelStyle(.iconOnly)
117+
// }
118+
// .isDetailLink(false)
119+
// .buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
120+
121+
Button {
122+
navigationPath.append(NavigationDestination.fee(amount: amount, address: address))
123+
} label: {
124+
Label(
125+
title: { Text("Next") },
126+
icon: { Image(systemName: "arrow.right") }
127+
)
128+
.labelStyle(.iconOnly)
129+
}
130+
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
119131

120132
}
121133
.padding()
@@ -152,17 +164,21 @@ extension AddressView {
152164

153165
#if DEBUG
154166
#Preview {
167+
155168
AddressView(
156169
amount: "200",
157170
address: "tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl",
158-
rootIsActive: .constant(false)
171+
// rootIsActive: .constant(false)
172+
navigationPath: .constant(NavigationPath())
159173
)
160174
}
161175
#Preview {
162176
AddressView(
163177
amount: "200",
164178
address: "tb1pw6y0vtmsn46epvz0j8ddc46ketmp28t82p22hcrrkch3a0jhu40qe267dl",
165-
rootIsActive: .constant(false)
179+
// rootIsActive: .constant(false)\
180+
navigationPath: .constant(NavigationPath())
181+
166182
)
167183
.environment(\.dynamicTypeSize, .accessibility5)
168184
}

BDKSwiftExampleWallet/View/AmountView.swift

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import SwiftUI
1111
struct AmountView: View {
1212
@Bindable var viewModel: AmountViewModel
1313
@State var numpadAmount = "0"
14-
@State var isActive: Bool = false
14+
// @State var isActive: Bool = false
15+
@Binding var navigationPath: NavigationPath
1516

1617
var body: some View {
1718

@@ -60,23 +61,36 @@ struct AmountView: View {
6061
Spacer()
6162

6263
VStack {
64+
65+
// Button {
66+
// isActive = true
67+
// } label: {
68+
// Label(
69+
// title: { Text("Next") },
70+
// icon: { Image(systemName: "arrow.right") }
71+
// )
72+
// .labelStyle(.iconOnly)
73+
// }
74+
// .buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
75+
// NavigationLink(
76+
// destination: AddressView(amount: numpadAmount, rootIsActive: $isActive),
77+
// isActive: $isActive
78+
// ) {
79+
// EmptyView()
80+
// }
81+
// .hidden()
82+
6383
Button {
64-
isActive = true
65-
} label: {
66-
Label(
67-
title: { Text("Next") },
68-
icon: { Image(systemName: "arrow.right") }
69-
)
70-
.labelStyle(.iconOnly)
71-
}
72-
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
73-
NavigationLink(
74-
destination: AddressView(amount: numpadAmount, rootIsActive: $isActive),
75-
isActive: $isActive
76-
) {
77-
EmptyView()
78-
}
79-
.hidden()
84+
navigationPath.append(NavigationDestination.address(amount: numpadAmount))
85+
} label: {
86+
Label(
87+
title: { Text("Next") },
88+
icon: { Image(systemName: "arrow.right") }
89+
)
90+
.labelStyle(.iconOnly)
91+
}
92+
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
93+
8094
}
8195

8296
}
@@ -85,8 +99,13 @@ struct AmountView: View {
8599
viewModel.getBalance()
86100
}
87101
}
88-
.onChange(of: isActive) {
89-
if !isActive {
102+
// .onChange(of: isActive) {
103+
// if !isActive {
104+
// numpadAmount = "0"
105+
// }
106+
// }
107+
.onChange(of: navigationPath) { oldPath, newPath in
108+
if newPath.isEmpty {
90109
numpadAmount = "0"
91110
}
92111
}
@@ -145,11 +164,18 @@ struct NumpadButton: View {
145164

146165
#if DEBUG
147166
#Preview {
148-
AmountView(viewModel: .init(bdkClient: .mock))
167+
AmountView(
168+
viewModel: .init(bdkClient: .mock),
169+
navigationPath: .constant(NavigationPath())
170+
)
149171
}
150172

151173
#Preview {
152-
AmountView(viewModel: .init(bdkClient: .mock))
174+
AmountView(
175+
viewModel: .init(bdkClient: .mock),
176+
navigationPath: .constant(NavigationPath())
177+
178+
)
153179
.environment(\.dynamicTypeSize, .accessibility5)
154180
}
155181
#endif

BDKSwiftExampleWallet/View/BuildTransactionView.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct BuildTransactionView: View {
1616
@Bindable var viewModel: BuildTransactionViewModel
1717
@State var isSent: Bool = false
1818
@State var isError: Bool = false
19-
@Binding var shouldPopToRootView: Bool
19+
// @Binding var shouldPopToRootView: Bool
20+
@Binding var navigationPath: NavigationPath
2021
@State private var isCopied = false
2122
@State private var showCheckmark = false
2223

@@ -86,7 +87,8 @@ struct BuildTransactionView: View {
8687
if self.viewModel.buildTransactionViewError == nil {
8788
self.isSent = true
8889
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
89-
self.shouldPopToRootView = false
90+
// self.shouldPopToRootView = false
91+
self.navigationPath.removeLast(self.navigationPath.count)
9092
}
9193
} else {
9294
self.isSent = false
@@ -186,7 +188,9 @@ struct BuildTransactionView: View {
186188
viewModel: .init(
187189
bdkClient: .mock
188190
),
189-
shouldPopToRootView: .constant(false)
191+
// shouldPopToRootView: .constant(false)
192+
navigationPath: .constant(NavigationPath())
193+
190194
)
191195
}
192196

@@ -198,7 +202,9 @@ struct BuildTransactionView: View {
198202
viewModel: .init(
199203
bdkClient: .mock
200204
),
201-
shouldPopToRootView: .constant(false)
205+
// shouldPopToRootView: .constant(false)
206+
navigationPath: .constant(NavigationPath())
207+
202208
)
203209
.environment(\.dynamicTypeSize, .accessibility5)
204210
}

BDKSwiftExampleWallet/View/FeeView.swift

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ struct FeeView: View {
1313
let amount: String
1414
let address: String
1515
@Bindable var viewModel: FeeViewModel
16-
@Binding var rootIsActive: Bool
16+
// @Binding var rootIsActive: Bool
17+
@Binding var navigationPath: NavigationPath
1718

1819
var body: some View {
1920

@@ -66,24 +67,35 @@ struct FeeView: View {
6667

6768
Spacer()
6869

69-
NavigationLink(
70-
destination: BuildTransactionView(
71-
amount: amount,
72-
address: address,
73-
fee: viewModel.selectedFee ?? 1,
74-
viewModel: .init(),
75-
shouldPopToRootView: self.$rootIsActive
76-
77-
)
78-
) {
79-
Label(
80-
title: { Text("Next") },
81-
icon: { Image(systemName: "arrow.right") }
82-
)
83-
.labelStyle(.iconOnly)
84-
}
85-
.isDetailLink(false)
86-
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
70+
// NavigationLink(
71+
// destination: BuildTransactionView(
72+
// amount: amount,
73+
// address: address,
74+
// fee: viewModel.selectedFee ?? 1,
75+
// viewModel: .init(),
76+
// shouldPopToRootView: self.$rootIsActive
77+
//
78+
// )
79+
// ) {
80+
// Label(
81+
// title: { Text("Next") },
82+
// icon: { Image(systemName: "arrow.right") }
83+
// )
84+
// .labelStyle(.iconOnly)
85+
// }
86+
// .isDetailLink(false)
87+
// .buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
88+
89+
Button {
90+
navigationPath.append(NavigationDestination.buildTransaction(amount: amount, address: address, fee: viewModel.selectedFee ?? 1))
91+
} label: {
92+
Label(
93+
title: { Text("Next") },
94+
icon: { Image(systemName: "arrow.right") }
95+
)
96+
.labelStyle(.iconOnly)
97+
}
98+
.buttonStyle(BitcoinOutlined(width: 100, isCapsule: true))
8799

88100
}
89101
.padding()
@@ -113,7 +125,9 @@ struct FeeView: View {
113125
amount: "50",
114126
address: "tb1pxg0lakl0x4jee73f38m334qsma7mn2yv764x9an5ylht6tx8ccdsxtktrt",
115127
viewModel: .init(feeClient: .mock, bdkClient: .mock),
116-
rootIsActive: .constant(false)
128+
// rootIsActive: .constant(false)
129+
navigationPath: .constant(NavigationPath())
130+
117131
)
118132
}
119133

@@ -122,7 +136,9 @@ struct FeeView: View {
122136
amount: "50",
123137
address: "tb1pxg0lakl0x4jee73f38m334qsma7mn2yv764x9an5ylht6tx8ccdsxtktrt",
124138
viewModel: .init(feeClient: .mock, bdkClient: .mock),
125-
rootIsActive: .constant(false)
139+
// rootIsActive: .constant(false)
140+
navigationPath: .constant(NavigationPath())
141+
126142
)
127143
.environment(\.dynamicTypeSize, .accessibility5)
128144
}

BDKSwiftExampleWallet/View/TabHomeView.swift

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99

1010
struct TabHomeView: View {
1111
@Bindable var viewModel: TabHomeViewModel
12+
@State private var sendNavigationPath = NavigationPath()
1213

1314
var body: some View {
1415

@@ -29,10 +30,31 @@ struct TabHomeView: View {
2930
.tabItem {
3031
Image(systemName: "arrow.down")
3132
}
32-
AmountView(viewModel: .init())
33-
.tabItem {
34-
Image(systemName: "arrow.up")
35-
}
33+
34+
// AmountView(viewModel: .init())
35+
// .tabItem {
36+
// Image(systemName: "arrow.up")
37+
// }
38+
39+
40+
NavigationStack(path: $sendNavigationPath) {
41+
AmountView(viewModel: .init(), navigationPath: $sendNavigationPath)
42+
.navigationDestination(for: NavigationDestination.self) { destination in
43+
switch destination {
44+
case .address(let amount):
45+
AddressView(amount: amount, navigationPath: $sendNavigationPath)
46+
case .fee(let amount, let address):
47+
FeeView(amount: amount, address: address, viewModel: .init(), navigationPath: $sendNavigationPath)
48+
case .buildTransaction(let amount, let address, let fee):
49+
BuildTransactionView(amount: amount, address: address, fee: fee, viewModel: .init(), navigationPath: $sendNavigationPath)
50+
}
51+
}
52+
}
53+
.tabItem {
54+
Image(systemName: "arrow.up")
55+
}
56+
57+
3658
SettingsView(viewModel: .init())
3759
.tabItem {
3860
Image(systemName: "gear")
@@ -58,6 +80,13 @@ struct TabHomeView: View {
5880

5981
}
6082

83+
enum NavigationDestination: Hashable {
84+
case address(amount: String)
85+
case fee(amount: String, address: String)
86+
case buildTransaction(amount: String, address: String, fee: Int)
87+
}
88+
89+
6190
#if DEBUG
6291
#Preview {
6392
TabHomeView(viewModel: .init(bdkClient: .mock))

0 commit comments

Comments
 (0)