This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathAccountActivityView.swift
372 lines (348 loc) · 10.7 KB
/
AccountActivityView.swift
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* Copyright 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import UIKit
import BraveCore
import SwiftUI
import Strings
import DesignSystem
import BraveUI
struct AccountActivityView: View {
@ObservedObject var store: AccountActivityStore
var cryptoStore: CryptoStore
var keyringStore: KeyringStore
@Binding var buySendSwapDestination: BuySendSwapDestination?
@State private var didLoad: Bool = false
@State private var isPresentingEditAccount: Bool = false
@State private var isPresentingExportAccount: Bool = false
var body: some View {
ScrollView {
VStack(spacing: 0) {
headerSection
rowsSection
}
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(store.account.name)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Menu(content: {
Button(action: {
isPresentingEditAccount = true
}) {
Label(Strings.Wallet.editButtonTitle, braveSystemImage: "leo.edit.pencil")
}
Button(action: {
isPresentingExportAccount = true
}) {
Label(Strings.Wallet.exportButtonTitle, braveSystemImage: "leo.key")
}
}, label: {
Image(braveSystemName: "leo.more.horizontal")
.foregroundColor(Color(braveSystemName: .iconInteractive))
})
}
}
.background(
VStack(spacing: 0) {
Color(braveSystemName: .containerBackground)
.frame(maxHeight: 200)
.edgesIgnoringSafeArea(.top)
Color(braveSystemName: .pageBackground)
.edgesIgnoringSafeArea(.all)
}
)
.background(
Color.clear
.sheet(isPresented: $isPresentingEditAccount) {
AccountDetailsView(
keyringStore: keyringStore,
account: store.account,
editMode: true
)
}
)
.background(
Color.clear
.sheet(isPresented: $isPresentingExportAccount) {
NavigationView {
AccountPrivateKeyView(
keyringStore: keyringStore,
account: store.account
)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
isPresentingExportAccount = false
}) {
Text(Strings.cancelButtonTitle)
.foregroundColor(Color(.braveBlurpleTint))
}
}
}
}
}
)
.onAppear {
// Skip reload when popping detail view off stack (assets, nfts, transactions)
guard !didLoad else { return }
didLoad = true
store.update()
}
}
private var headerSection: some View {
VStack(spacing: 0) {
VStack(spacing: 8) {
Blockie(address: store.account.address)
.frame(width: 44, height: 44)
.clipShape(RoundedRectangle(cornerRadius: 4))
.accessibilityHidden(true)
VStack(spacing: 0) {
Text(store.account.name)
.font(.title2.weight(.semibold))
AddressView(address: store.account.address) {
Text(store.account.address.truncatedAddress)
.font(.caption)
}
}
}
Spacer().frame(height: 16)
VStack {
if store.isLoadingAccountFiat {
Text(store.accountTotalFiat)
.font(.title.weight(.medium))
.redacted(reason: .placeholder)
.shimmer(store.isLoadingAccountFiat)
} else {
Text(store.accountTotalFiat)
.font(.title.weight(.medium))
}
Text(store.account.accountSupportDisplayString)
.font(.caption)
}
Spacer().frame(height: 24)
HStack(spacing: 24) {
PortfolioHeaderButton(style: .buy) {
buySendSwapDestination = .init(kind: .buy)
}
PortfolioHeaderButton(style: .send) {
buySendSwapDestination = .init(kind: .send)
}
PortfolioHeaderButton(style: .swap) {
buySendSwapDestination = .init(kind: .swap)
}
}
}
.padding(.vertical, 24)
.frame(maxWidth: .infinity)
.background(
Color(braveSystemName: .containerBackground)
)
}
private var rowsSection: some View {
VStack(spacing: 0) {
NavigationLink(destination: {
AssetsListDetailView(
store: store,
cryptoStore: cryptoStore,
keyringStore: keyringStore
)
}, label: {
let assetsCount = store.userAssets.count
RowView(
iconBraveSystemName: "leo.crypto.wallets",
title: Strings.Wallet.assetsTitle,
description: String.localizedStringWithFormat(
assetsCount == 1 ?
Strings.Wallet.assetsSingularDescription : Strings.Wallet.assetsDescription,
assetsCount
)
)
})
Divider()
NavigationLink(destination: {
NFTGridDetailView(
store: store,
cryptoStore: cryptoStore,
keyringStore: keyringStore
)
}, label: {
let nftCount = store.userNFTs.count
RowView(
iconBraveSystemName: "leo.grid04",
title: Strings.Wallet.nftsTitle,
description: String.localizedStringWithFormat(
nftCount == 1 ?
Strings.Wallet.nftsSingularDescription : Strings.Wallet.nftsDescription,
nftCount
)
)
})
Divider()
NavigationLink(destination: {
AccountTransactionListView(
activityStore: store,
networkStore: cryptoStore.networkStore
)
}, label: {
let transactionCount = store.transactionSections.flatMap(\.transactions).count
RowView(
iconBraveSystemName: "leo.history",
title: Strings.Wallet.transactionsTitle,
description: String.localizedStringWithFormat(
transactionCount == 1 ?
Strings.Wallet.transactionsSingularDescription : Strings.Wallet.transactionsDescription,
transactionCount
)
)
})
if WalletConstants.supportedCoinTypes(.dapps).contains(store.account.coin) {
Divider()
NavigationLink(destination: {
DappsSettings(
coin: store.account.coin,
siteConnectionStore: cryptoStore.settingsStore.manageSiteConnectionsStore(keyringStore: keyringStore)
)
}, label: {
RowView(
iconBraveSystemName: "leo.lock.dots",
title: Strings.Wallet.securityTitle,
description: Strings.Wallet.accountSecurityDescription
)
})
}
}
.background(
Color(braveSystemName: .containerBackground)
.clipShape(RoundedRectangle(cornerRadius: 12))
)
.padding()
.background(
Color(braveSystemName: .pageBackground)
)
}
private struct RowView: View {
let iconBraveSystemName: String
let title: String
let description: String
var body: some View {
HStack(spacing: 16) {
Circle()
.fill(Color(braveSystemName: .pageBackground))
.frame(width: 40, height: 40)
.overlay {
Image(braveSystemName: iconBraveSystemName)
.foregroundColor(Color(braveSystemName: .iconDefault))
}
VStack(alignment: .leading) {
Text(title)
.font(.callout.weight(.semibold))
.foregroundColor(Color(braveSystemName: .textPrimary))
Text(description)
.font(.footnote)
.foregroundColor(Color(braveSystemName: .textSecondary))
}
Spacer()
Image(systemName: "chevron.right")
.font(.body.weight(.semibold))
.foregroundColor(Color(.separator))
}
.padding(.vertical, 10)
.padding(.horizontal, 16)
}
}
}
#if DEBUG
struct AccountActivityView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
AccountActivityView(
store: .previewStore,
cryptoStore: .previewStore,
keyringStore: .previewStore,
buySendSwapDestination: .constant(.none)
)
}
.previewColorSchemes()
}
}
#endif
private struct AssetsListDetailView: View {
@ObservedObject var store: AccountActivityStore
var cryptoStore: CryptoStore
var keyringStore: KeyringStore
@State private var assetForDetails: BraveWallet.BlockchainToken?
var body: some View {
AssetsListView(
assets: store.userAssets,
currencyFormatter: store.currencyFormatter,
selectedAsset: { asset in
assetForDetails = asset
}
)
.navigationTitle(Strings.Wallet.assetsTitle)
.background(
NavigationLink(
isActive: Binding(
get: { assetForDetails != nil },
set: { if !$0 { assetForDetails = nil } }
),
destination: {
if let token = assetForDetails {
AssetDetailView(
assetDetailStore: cryptoStore.assetDetailStore(for: .blockchainToken(token)),
keyringStore: keyringStore,
networkStore: cryptoStore.networkStore
)
.onDisappear {
cryptoStore.closeAssetDetailStore(for: .blockchainToken(token))
}
}
},
label: {
EmptyView()
})
)
}
}
private struct NFTGridDetailView: View {
@ObservedObject var store: AccountActivityStore
var cryptoStore: CryptoStore
var keyringStore: KeyringStore
@State private var nftForDetails: BraveWallet.BlockchainToken?
@Environment(\.buySendSwapDestination)
private var buySendSwapDestination: Binding<BuySendSwapDestination?>
var body: some View {
NFTsGridView(
assets: store.userNFTs,
selectedAsset: { nft in
nftForDetails = nft
}
)
.navigationTitle(Strings.Wallet.nftsTitle)
.background(
NavigationLink(
isActive: Binding(
get: { nftForDetails != nil },
set: { if !$0 { nftForDetails = nil } }
),
destination: {
if let token = nftForDetails {
NFTDetailView(
keyringStore: keyringStore,
nftDetailStore: cryptoStore.nftDetailStore(for: token, nftMetadata: nil, owner: nil),
buySendSwapDestination: buySendSwapDestination
) { metadata in
}
.onDisappear {
cryptoStore.closeNFTDetailStore(for: token)
}
}
},
label: {
EmptyView()
})
)
}
}