Skip to content

Commit

Permalink
Fix brave/brave-ios#7585: Portfolio filters and display settings (bra…
Browse files Browse the repository at this point in the history
…ve/brave-ios#7665)

* 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
StephenHeaps authored Jul 17, 2023
1 parent ba26101 commit 7898bcc
Show file tree
Hide file tree
Showing 22 changed files with 1,568 additions and 247 deletions.
41 changes: 41 additions & 0 deletions Sources/BraveWallet/Crypto/Accounts/AccountFilterView.swift
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)
}
}
}
}
81 changes: 0 additions & 81 deletions Sources/BraveWallet/Crypto/Accounts/AccountListView.swift

This file was deleted.

101 changes: 101 additions & 0 deletions Sources/BraveWallet/Crypto/Accounts/AccountSelectionRootView.swift
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 Sources/BraveWallet/Crypto/Accounts/AccountSelectionView.swift
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
11 changes: 7 additions & 4 deletions Sources/BraveWallet/Crypto/BuySendSwap/AccountPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ struct AccountPicker: View {
}
}
.sheet(isPresented: $isPresentingPicker) {
AccountListView(
keyringStore: keyringStore,
onDismiss: { isPresentingPicker = false }
)
NavigationView {
AccountSelectionView(
keyringStore: keyringStore,
onDismiss: { isPresentingPicker = false }
)
}
.navigationViewStyle(.stack)
}
}

Expand Down
15 changes: 9 additions & 6 deletions Sources/BraveWallet/Crypto/CryptoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ public struct CryptoView: View {
case .panelUnlockOrSetup:
EmptyView()
case .accountSelection:
AccountListView(
keyringStore: keyringStore,
onDismiss: {
dismissAction()
}
)
NavigationView {
AccountSelectionView(
keyringStore: keyringStore,
onDismiss: {
dismissAction()
}
)
}
.navigationViewStyle(.stack)
case .transactionHistory:
NavigationView {
AccountTransactionListView(
Expand Down
Loading

0 comments on commit 7898bcc

Please sign in to comment.