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 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Create FiltersDisplaySettingsView for Portfolio filters. Allows changing sort option, hiding/showing small balances, filtering by multiple accounts, and filtering by multiple networks. * Update Network Filter / Network Selection design for Wallet v2 * Update Account Filter / Account Selection design for Wallet v2 * Update to preserve Portfolio filter selections. * Add A-Z sort
- Loading branch information
1 parent
e532093
commit fecb90d
Showing
22 changed files
with
1,568 additions
and
247 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
Sources/BraveWallet/Crypto/Accounts/AccountFilterView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 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 SwiftUI | ||
import BraveCore | ||
import struct Shared.Strings | ||
import BraveUI | ||
|
||
/// Displays all accounts and allows multiple selection for filtering by accounts. | ||
struct AccountFilterView: View { | ||
|
||
@Binding var accounts: [Selectable<BraveWallet.AccountInfo>] | ||
|
||
@Environment(\.presentationMode) @Binding private var presentationMode | ||
|
||
private var allSelected: Bool { | ||
accounts.allSatisfy(\.isSelected) | ||
} | ||
|
||
var body: some View { | ||
AccountSelectionRootView( | ||
navigationTitle: Strings.Wallet.selectAccountsTitle, | ||
allAccounts: accounts.map(\.model), | ||
selectedAccounts: accounts.filter(\.isSelected).map(\.model), | ||
showsSelectAllButton: true, | ||
selectAccount: selectAccount | ||
) | ||
} | ||
|
||
private func selectAccount(_ network: BraveWallet.AccountInfo) { | ||
DispatchQueue.main.async { | ||
if let index = accounts.firstIndex( | ||
where: { $0.model.id == network.id && $0.model.coin == network.coin } | ||
) { | ||
accounts[index] = .init(isSelected: !accounts[index].isSelected, model: accounts[index].model) | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
Sources/BraveWallet/Crypto/Accounts/AccountSelectionRootView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2023 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 SwiftUI | ||
import BraveCore | ||
import struct Shared.Strings | ||
import BraveUI | ||
|
||
struct AccountSelectionRootView: View { | ||
|
||
let navigationTitle: String | ||
let allAccounts: [BraveWallet.AccountInfo] | ||
let selectedAccounts: [BraveWallet.AccountInfo] | ||
var showsSelectAllButton: Bool | ||
var selectAccount: (BraveWallet.AccountInfo) -> Void | ||
|
||
init( | ||
navigationTitle: String, | ||
allAccounts: [BraveWallet.AccountInfo], | ||
selectedAccounts: [BraveWallet.AccountInfo], | ||
showsSelectAllButton: Bool, | ||
selectAccount: @escaping (BraveWallet.AccountInfo) -> Void | ||
) { | ||
self.navigationTitle = navigationTitle | ||
self.allAccounts = allAccounts | ||
self.selectedAccounts = selectedAccounts | ||
self.showsSelectAllButton = showsSelectAllButton | ||
self.selectAccount = selectAccount | ||
} | ||
|
||
var body: some View { | ||
ScrollView { | ||
LazyVStack(spacing: 0) { | ||
SelectAllHeaderView( | ||
title: Strings.Wallet.accountsPageTitle, | ||
showsSelectAllButton: showsSelectAllButton, | ||
allModels: allAccounts, | ||
selectedModels: selectedAccounts, | ||
select: selectAccount | ||
) | ||
ForEach(allAccounts) { account in | ||
AccountListRowView( | ||
account: account, | ||
isSelected: selectedAccounts.contains(account) | ||
) { | ||
selectAccount(account) | ||
} | ||
} | ||
} | ||
} | ||
.listBackgroundColor(Color(uiColor: WalletV2Design.containerBackground)) | ||
.navigationTitle(navigationTitle) | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
|
||
private struct AccountListRowView: View { | ||
|
||
var account: BraveWallet.AccountInfo | ||
var isSelected: Bool | ||
let didSelect: () -> Void | ||
|
||
init( | ||
account: BraveWallet.AccountInfo, | ||
isSelected: Bool, | ||
didSelect: @escaping () -> Void | ||
) { | ||
self.account = account | ||
self.isSelected = isSelected | ||
self.didSelect = didSelect | ||
} | ||
|
||
private var checkmark: some View { | ||
Image(braveSystemName: "leo.check.normal") | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.hidden(isHidden: !isSelected) | ||
.foregroundColor(Color(.braveBlurpleTint)) | ||
.frame(width: 14, height: 14) | ||
.transition(.identity) | ||
.animation(nil, value: isSelected) | ||
} | ||
|
||
var body: some View { | ||
AddressView(address: account.address) { | ||
Button(action: didSelect) { | ||
HStack { | ||
AccountView(address: account.address, name: account.name) | ||
checkmark | ||
} | ||
} | ||
.buttonStyle(FadeButtonStyle()) | ||
} | ||
.accessibilityElement(children: .combine) | ||
.accessibilityAddTraits(isSelected ? [.isSelected] : []) | ||
.padding(.horizontal) | ||
.contentShape(Rectangle()) | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Sources/BraveWallet/Crypto/Accounts/AccountSelectionView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2023 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 SwiftUI | ||
import BraveCore | ||
import struct Shared.Strings | ||
import BraveUI | ||
|
||
/// Displays all accounts and will update the selected account to the account tapped on. | ||
struct AccountSelectionView: View { | ||
@ObservedObject var keyringStore: KeyringStore | ||
let onDismiss: () -> Void | ||
|
||
@State private var isPresentingAddAccount: Bool = false | ||
@Environment(\.presentationMode) @Binding private var presentationMode | ||
|
||
var body: some View { | ||
AccountSelectionRootView( | ||
navigationTitle: Strings.Wallet.selectAccountTitle, | ||
allAccounts: keyringStore.allAccounts, | ||
selectedAccounts: [keyringStore.selectedAccount], | ||
showsSelectAllButton: false, | ||
selectAccount: { selectedAccount in | ||
keyringStore.selectedAccount = selectedAccount | ||
onDismiss() | ||
} | ||
) | ||
.navigationTitle(Strings.Wallet.selectAccountTitle) | ||
.navigationBarTitleDisplayMode(.inline) | ||
.toolbar { | ||
ToolbarItemGroup(placement: .cancellationAction) { | ||
Button(action: { onDismiss() }) { | ||
Text(Strings.cancelButtonTitle) | ||
.foregroundColor(Color(.braveBlurpleTint)) | ||
} | ||
} | ||
ToolbarItemGroup(placement: .primaryAction) { | ||
Button(action: { | ||
isPresentingAddAccount = true | ||
}) { | ||
Label(Strings.Wallet.addAccountTitle, systemImage: "plus") | ||
.foregroundColor(Color(.braveBlurpleTint)) | ||
} | ||
} | ||
} | ||
.sheet(isPresented: $isPresentingAddAccount) { | ||
NavigationView { | ||
AddAccountView(keyringStore: keyringStore) | ||
} | ||
.navigationViewStyle(.stack) | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct AccountSelectionView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
AccountSelectionView( | ||
keyringStore: { | ||
let store = KeyringStore.previewStoreWithWalletCreated | ||
store.addPrimaryAccount("Account 2", coin: .eth, completion: nil) | ||
store.addPrimaryAccount("Account 3", coin: .eth, completion: nil) | ||
return store | ||
}(), | ||
onDismiss: {} | ||
) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.