From 98c7464eaf82e8a6cf8ba5827a54553370cc3324 Mon Sep 17 00:00:00 2001 From: StephenHeaps <5314553+StephenHeaps@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:49:12 -0400 Subject: [PATCH] Fix #7947, #7944, #7948, #7946: Portfolio Fixes (#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. --- .../Crypto/FiltersDisplaySettingsView.swift | 43 ++++++++++++++++--- .../BraveWallet/Crypto/Stores/NFTStore.swift | 3 ++ .../Crypto/Stores/PortfolioStore.swift | 3 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift b/Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift index c24e734f4b3..532b407eb5f 100644 --- a/Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift +++ b/Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift @@ -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) } } } @@ -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 { @@ -554,7 +569,21 @@ struct FilterPickerRowView