Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rave/brave-ios#7946: Portfolio Fixes (brave/brave-ios#7950)

* Hide/Remove Filecoin accounts from Portfolio & NFT filters until they are supported.

* Fix `Network Logo` and `Hide Unowned` NFT Filters & Display Settings toggles not resetting to defaults when `Reset` tapped

* Disable `Reset` button on Filters & Display Settings when filters are showing defaults.

* Fix Filters & Display Settings Picker text truncated, janky animation when switching selection.
  • Loading branch information
StephenHeaps authored Aug 24, 2023
1 parent bbdcffc commit 40d28b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
43 changes: 36 additions & 7 deletions Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ struct FiltersDisplaySettingsView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: restoreToDefaults) {
Button(action: resetToDefaults) {
Text(Strings.Wallet.settingsResetTransactionAlertButtonTitle)
.fontWeight(.semibold)
.foregroundColor(Color(uiColor: WalletV2Design.textInteractive))
}
.disabled(isResetDisabled)
}
}
}
Expand Down Expand Up @@ -380,12 +380,27 @@ struct FiltersDisplaySettingsView: View {
.shadow(color: Color.black.opacity(0.04), radius: 16, x: 0, y: -8)
}

func restoreToDefaults() {
self.groupBy = .none
private var isResetDisabled: Bool {
groupBy == GroupBy(rawValue: Preferences.Wallet.groupByFilter.defaultValue) ?? .none
&& sortOrder == SortOrder(rawValue: Preferences.Wallet.sortOrderFilter.defaultValue) ?? .valueDesc
&& isHidingSmallBalances == Preferences.Wallet.isHidingSmallBalancesFilter.defaultValue
&& isHidingUnownedNFTs == Preferences.Wallet.isHidingUnownedNFTsFilter.defaultValue
&& isShowingNFTNetworkLogo == Preferences.Wallet.isShowingNFTNetworkLogoFilter.defaultValue
&& accounts.allSatisfy(\.isSelected)
&& networks.allSatisfy { selectableNetwork in
let isTestnet = WalletConstants.supportedTestNetworkChainIds.contains(selectableNetwork.model.chainId)
return selectableNetwork.isSelected == !isTestnet
}
}

func resetToDefaults() {
/// Assets are not grouped by default
self.groupBy = GroupBy(rawValue: Preferences.Wallet.groupByFilter.defaultValue) ?? .none
// Fiat value in descending order (largest fiat to smallest) by default
self.sortOrder = .valueDesc
// Small balances shown by default
self.isHidingSmallBalances = false
self.sortOrder = SortOrder(rawValue: Preferences.Wallet.sortOrderFilter.defaultValue) ?? .valueDesc
self.isHidingSmallBalances = Preferences.Wallet.isHidingSmallBalancesFilter.defaultValue
self.isHidingUnownedNFTs = Preferences.Wallet.isHidingUnownedNFTsFilter.defaultValue
self.isShowingNFTNetworkLogo = Preferences.Wallet.isShowingNFTNetworkLogoFilter.defaultValue

// All accounts selected by default
self.accounts = self.accounts.map {
Expand Down Expand Up @@ -554,7 +569,21 @@ struct FilterPickerRowView<T: Equatable & Identifiable & Hashable, Content: View
Image(braveSystemName: "leo.carat.down")
}
})
.osAvailabilityModifiers({
if #unavailable(iOS 17) {
// Prior to iOS 17, if selection changes from outside
// the Menu (ex. Reset button) the view might not
// resize to fit a larger label
$0.id(selection)
} else {
$0
}
})
.foregroundColor(Color(WalletV2Design.textInteractive))
.transaction { transaction in
transaction.animation = nil
transaction.disablesAnimations = true
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/BraveWallet/Crypto/Stores/NFTStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public class NFTStore: ObservableObject {
self.updateTask?.cancel()
self.updateTask = Task { @MainActor in
self.allAccounts = await keyringService.allAccounts().accounts
.filter { account in
WalletConstants.supportedCoinTypes.contains(account.coin)
}
self.allNetworks = await rpcService.allNetworksForSupportedCoins().filter { network in
if !Preferences.Wallet.showTestNetworks.value { // filter out test networks
return !WalletConstants.supportedTestNetworkChainIds.contains(where: { $0 == network.chainId })
Expand Down
3 changes: 3 additions & 0 deletions Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public class PortfolioStore: ObservableObject {
self.updateTask = Task { @MainActor in
self.isLoadingBalances = true
self.allAccounts = await keyringService.allAccounts().accounts
.filter { account in
WalletConstants.supportedCoinTypes.contains(account.coin)
}
self.allNetworks = await rpcService.allNetworksForSupportedCoins().filter { network in
if !Preferences.Wallet.showTestNetworks.value { // filter out test networks
return !WalletConstants.supportedTestNetworkChainIds.contains(where: { $0 == network.chainId })
Expand Down

0 comments on commit 40d28b4

Please sign in to comment.