diff --git a/Sources/BraveWallet/Crypto/NFT/NFTView.swift b/Sources/BraveWallet/Crypto/NFT/NFTView.swift index 58ff435af8f2..2c14254313ba 100644 --- a/Sources/BraveWallet/Crypto/NFT/NFTView.swift +++ b/Sources/BraveWallet/Crypto/NFT/NFTView.swift @@ -104,8 +104,8 @@ struct NFTView: View { self.isPresentingNetworkFilter = true }) { HStack { - Text(nftStore.networkFilter.title) Image(braveSystemName: "leo.list") + Text(nftStore.networkFilter.title) } .font(.footnote.weight(.medium)) .foregroundColor(Color(.braveBlurpleTint)) @@ -128,18 +128,29 @@ struct NFTView: View { Text(Strings.Wallet.assetsTitle) .font(.footnote) .foregroundColor(Color(.secondaryBraveLabel)) + .padding(.leading, 16) if nftStore.isLoadingDiscoverAssets && isNFTDiscoveryEnabled { ProgressView() .padding(.leading, 5) } Spacer() networkFilterButton + .padding(.trailing, 10) + addCustomAssetButton } .textCase(nil) .padding(.horizontal, 10) .frame(maxWidth: .infinity, alignment: .leading) } + private var addCustomAssetButton: some View { + Button(action: { + isShowingAddCustomNFT = true + }) { + Image(systemName: "plus") + } + } + private var nftDiscoveryDescriptionText: NSAttributedString? { let attributedString = NSMutableAttributedString( string: Strings.Wallet.nftDiscoveryCalloutDescription, @@ -156,44 +167,57 @@ struct NFTView: View { return attributedString } - var body: some View { - ScrollView { - VStack { - nftHeaderView - if nftStore.userVisibleNFTs.isEmpty { - emptyView - .listRowBackground(Color(.clear)) - } else { - LazyVGrid(columns: nftGrids) { - ForEach(nftStore.userVisibleNFTs) { nft in - Button(action: { - selectedNFTViewModel = nft - }) { - VStack(alignment: .leading, spacing: 4) { - nftImage(nft) - .padding(.bottom, 8) - Text(nft.token.nftTokenTitle) - .font(.callout.weight(.medium)) - .foregroundColor(Color(.braveLabel)) - .multilineTextAlignment(.leading) - if !nft.token.symbol.isEmpty { - Text(nft.token.symbol) - .font(.caption) - .foregroundColor(Color(.secondaryBraveLabel)) - .multilineTextAlignment(.leading) - } - } + @ViewBuilder var nftGridsView: some View { + if nftStore.userVisibleNFTs.isEmpty { + emptyView + .listRowBackground(Color(.clear)) + } else { + LazyVGrid(columns: nftGrids) { + ForEach(nftStore.userVisibleNFTs) { nft in + Button(action: { + selectedNFTViewModel = nft + }) { + VStack(alignment: .leading, spacing: 4) { + nftImage(nft) + .padding(.bottom, 8) + Text(nft.token.nftTokenTitle) + .font(.callout.weight(.medium)) + .foregroundColor(Color(.braveLabel)) + .multilineTextAlignment(.leading) + if !nft.token.symbol.isEmpty { + Text(nft.token.symbol) + .font(.caption) + .foregroundColor(Color(.secondaryBraveLabel)) + .multilineTextAlignment(.leading) } } } - VStack(spacing: 16) { - Divider() - editUserAssetsButton + .contextMenu { + Button(action: { + nftStore.updateVisibility(nft.token, visible: false) + }) { + Label(Strings.recentSearchHide, braveSystemImage: "leo.eye.off") + } } - .padding(.top, 20) } } - .padding(24) + VStack(spacing: 16) { + Divider() + editUserAssetsButton + } + .padding(.top, 20) + } + } + + var body: some View { + ScrollView { + VStack { + nftHeaderView + .padding(.horizontal, 8) + nftGridsView + .padding(.horizontal, 24) + } + .padding(.vertical, 24) } .background(Color(UIColor.braveGroupedBackground)) .background( diff --git a/Sources/BraveWallet/Crypto/Portfolio/AddCustomAssetView.swift b/Sources/BraveWallet/Crypto/Portfolio/AddCustomAssetView.swift index ba427c3f3edd..b15ebf9ce4cb 100644 --- a/Sources/BraveWallet/Crypto/Portfolio/AddCustomAssetView.swift +++ b/Sources/BraveWallet/Crypto/Portfolio/AddCustomAssetView.swift @@ -77,6 +77,33 @@ struct AddCustomAssetView: View { .pickerStyle(.segmented) } } + Section( + header: WalletListHeaderView(title: networkSelectionStore.networkSelectionInForm?.coin == .sol ? Text(Strings.Wallet.tokenMintAddress) : Text(Strings.Wallet.tokenAddress)) + ) { + TextField(Strings.Wallet.enterAddress, text: $addressInput) + .onChange(of: addressInput) { newValue in + guard !newValue.isEmpty else { return } + userAssetStore.tokenInfo(address: newValue) { token in + guard let token else { return } + if nameInput.isEmpty { + nameInput = token.name + } + if symbolInput.isEmpty { + symbolInput = token.symbol + } + if !token.isErc721, !token.isNft, decimalsInput.isEmpty { + decimalsInput = "\(token.decimals)" + } + if let network = networkStore.allChains.first(where: { $0.chainId == token.chainId }) { + networkSelectionStore.networkSelectionInForm = network + } + } + } + .autocapitalization(.none) + .autocorrectionDisabled() + .disabled(userAssetStore.isSearchingToken) + .listRowBackground(Color(.secondaryBraveGroupedBackground)) + } Section( header: WalletListHeaderView(title: Text(Strings.Wallet.customTokenNetworkHeader)) ) { @@ -107,33 +134,6 @@ struct AddCustomAssetView: View { } .listRowBackground(Color(.secondaryBraveGroupedBackground)) } - Section( - header: WalletListHeaderView(title: networkSelectionStore.networkSelectionInForm?.coin == .sol ? Text(Strings.Wallet.tokenMintAddress) : Text(Strings.Wallet.tokenAddress)) - ) { - TextField(Strings.Wallet.enterAddress, text: $addressInput) - .onChange(of: addressInput) { newValue in - guard !newValue.isEmpty else { return } - userAssetStore.tokenInfo(address: newValue) { token in - guard let token else { return } - if nameInput.isEmpty { - nameInput = token.name - } - if symbolInput.isEmpty { - symbolInput = token.symbol - } - if !token.isErc721, !token.isNft, decimalsInput.isEmpty { - decimalsInput = "\(token.decimals)" - } - if let network = networkStore.allChains.first(where: { $0.chainId == token.chainId }) { - networkSelectionStore.networkSelectionInForm = network - } - } - } - .autocapitalization(.none) - .autocorrectionDisabled() - .disabled(userAssetStore.isSearchingToken) - .listRowBackground(Color(.secondaryBraveGroupedBackground)) - } Section( header: WalletListHeaderView(title: Text(Strings.Wallet.tokenSymbol)) ) { diff --git a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift index 18ccb1c6b67d..bf9e15c10513 100644 --- a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift @@ -151,6 +151,14 @@ public class NFTStore: ObservableObject { func enableNFTDiscovery() { walletService.setNftDiscoveryEnabled(true) } + + func updateVisibility(_ token: BraveWallet.BlockchainToken, visible: Bool) { + walletService.setUserAssetVisible(token, visible: visible) { [weak self] success in + if success { + self?.update() + } + } + } } extension NFTStore: BraveWalletJsonRpcServiceObserver {