-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSweepSettingsView.swift
More file actions
198 lines (166 loc) · 5.97 KB
/
SweepSettingsView.swift
File metadata and controls
198 lines (166 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import BitkitCore
import Lottie
import SwiftUI
struct SweepSettingsView: View {
@EnvironmentObject var navigation: NavigationViewModel
@EnvironmentObject private var viewModel: SweepViewModel
var body: some View {
VStack(alignment: .leading, spacing: 0) {
NavigationBar(title: navigationTitle)
.padding(.bottom, 30)
switch viewModel.checkState {
case .idle, .checking:
loadingView
case .found:
foundFundsView
case .noFunds:
noFundsView
case let .error(message):
errorView(message: message)
}
}
.navigationBarHidden(true)
.padding(.horizontal, 16)
.bottomSafeAreaPadding()
.background(Color.customBlack)
.task {
viewModel.reset()
await viewModel.checkBalance()
}
}
private var navigationTitle: String {
switch viewModel.checkState {
case .found:
return t("sweep__found_title")
case .noFunds:
return t("sweep__no_funds_title")
default:
return t("sweep__title")
}
}
// MARK: - Loading View
@ViewBuilder
private var loadingView: some View {
VStack(alignment: .leading, spacing: 0) {
BodyMText(t("sweep__loading_description"))
.foregroundColor(.textSecondary)
Spacer()
// Magnifying glass image
Image("magnifying-glass-illustration")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 311, height: 311)
.frame(maxWidth: .infinity, alignment: .center)
Spacer()
// Loading indicator
VStack(spacing: 32) {
ActivityIndicator(size: 32)
CaptionMText(t("sweep__looking_for_funds"))
.foregroundColor(.textSecondary)
}
.frame(maxWidth: .infinity, alignment: .center)
}
}
// MARK: - Found Funds View
@ViewBuilder
private var foundFundsView: some View {
VStack(alignment: .leading, spacing: 0) {
BodyMText(t("sweep__found_description"))
.foregroundColor(.textSecondary)
.padding(.bottom, 24)
CaptionMText(t("sweep__funds_found"))
.foregroundColor(.textSecondary)
.padding(.bottom, 16)
if let balances = viewModel.sweepableBalances {
VStack(alignment: .leading, spacing: 0) {
if balances.legacyBalance > 0 {
fundRow(
title: "Legacy (P2PKH)",
utxoCount: balances.legacyUtxosCount,
balance: balances.legacyBalance
)
}
if balances.p2shBalance > 0 {
fundRow(
title: "SegWit (P2SH)",
utxoCount: balances.p2shUtxosCount,
balance: balances.p2shBalance
)
}
if balances.taprootBalance > 0 {
fundRow(
title: "Taproot (P2TR)",
utxoCount: balances.taprootUtxosCount,
balance: balances.taprootBalance
)
}
// Total row
HStack {
TitleText(t("common__total"))
Spacer()
MoneyText(sats: Int(balances.totalBalance), size: .title, symbol: true, symbolColor: .textPrimary)
}
.padding(.top, 16)
}
}
Spacer()
CustomButton(title: t("sweep__sweep_to_wallet")) {
navigation.navigate(.sweepConfirm)
}
.accessibilityIdentifier("SweepToWalletButton")
}
}
@ViewBuilder
private func fundRow(title: String, utxoCount: UInt32, balance: UInt64) -> some View {
VStack(spacing: 0) {
HStack {
Text("\(title), \(utxoCount) UTXO\(utxoCount == 1 ? "" : "s")")
.font(Fonts.semiBold(size: 13))
.foregroundColor(.textPrimary)
Spacer()
MoneyText(sats: Int(balance), size: .captionB, symbol: true, symbolColor: .textPrimary)
}
.padding(.vertical, 16)
Divider()
.background(Color.gray5)
}
}
// MARK: - No Funds View
@ViewBuilder
private var noFundsView: some View {
VStack(alignment: .leading, spacing: 0) {
BodyMText(t("sweep__no_funds_description"))
.foregroundColor(.textSecondary)
Spacer()
Image("check")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 311, height: 311)
.frame(maxWidth: .infinity, alignment: .center)
Spacer()
CustomButton(title: t("common__ok")) {
navigation.navigateBack()
}
}
}
// MARK: - Error View
@ViewBuilder
private func errorView(message: String) -> some View {
VStack(spacing: 24) {
Spacer()
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 64))
.foregroundColor(.redAccent)
VStack(spacing: 8) {
BodyMSBText(t("sweep__error_title"))
BodyMText(message)
.foregroundColor(.textSecondary)
.multilineTextAlignment(.center)
}
Spacer()
CustomButton(title: t("common__retry")) {
Task { await viewModel.checkBalance() }
}
}
}
}