Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
remove the check and ui for unsupported coin market.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Apr 20, 2023
1 parent e28f3bc commit 4f16586
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 47 deletions.
11 changes: 1 addition & 10 deletions Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,7 @@ struct AssetDetailView: View {
case .blockchainToken(_):
accountsBalanceView
transactionsView
case .coinMarket(let coinMarket, let isSupported):
if isSupported {
accountsBalanceView
transactionsView
} else {
Text(Strings.Wallet.assetDetailNoSupported)
.font(.footnote)
.foregroundColor(Color(.braveLabel))
.listRowBackground(Color.clear)
}
case .coinMarket(let coinMarket):
Section {
HStack {
VStack(spacing: 10) {
Expand Down
9 changes: 2 additions & 7 deletions Sources/BraveWallet/Crypto/Market/MarketView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ struct MarketView: View {
self.marketStore = cryptoStore.marketStore
}

private var isSelectedCoinMarketSupported: Bool {
guard let coinMarket = selectedCoinMarket else { return false }
return marketStore.allCoingeckoTokens.contains(where: { $0.coingeckoId.caseInsensitiveCompare(coinMarket.id) == .orderedSame })
}

private var emptyState: some View {
VStack(alignment: .center, spacing: 10) {
Text(Strings.Wallet.coinMarketEmptyMsg)
Expand Down Expand Up @@ -176,12 +171,12 @@ struct MarketView: View {
destination: {
if let coinMarket = selectedCoinMarket {
AssetDetailView(
assetDetailStore: cryptoStore.assetDetailStore(for: .coinMarket(coinMarket, isSelectedCoinMarketSupported)),
assetDetailStore: cryptoStore.assetDetailStore(for: .coinMarket(coinMarket)),
keyringStore: keyringStore,
networkStore: cryptoStore.networkStore
)
.onDisappear {
cryptoStore.closeAssetDetailStore(for: .coinMarket(coinMarket, isSelectedCoinMarketSupported))
cryptoStore.closeAssetDetailStore(for: .coinMarket(coinMarket))
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ struct AccountAssetViewModel: Identifiable {

enum AssetDetailType: Identifiable {
case blockchainToken(BraveWallet.BlockchainToken)
case coinMarket(BraveWallet.CoinMarket, Bool)
case coinMarket(BraveWallet.CoinMarket)

var id: String {
switch self {
case .blockchainToken(let token):
return token.tokenId
case .coinMarket(let coinMarket, _):
case .coinMarket(let coinMarket):
return coinMarket.id
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ class AssetDetailStore: ObservableObject {
switch assetDetailType {
case .blockchainToken(let token):
return token
case .coinMarket(let coinMarket, _):
case .coinMarket(let coinMarket):
return .init().then {
for tokens in allBuyTokensAllOptions.values {
if let matchedToken = tokens.first(where: { token in token.symbol.caseInsensitiveCompare(coinMarket.symbol) == .orderedSame }) {
Expand Down Expand Up @@ -209,7 +209,7 @@ class AssetDetailStore: ObservableObject {
self.accounts = await fetchAccountBalances(updatedAccounts, keyring: keyring, network: network)
let assetRatios = [token.assetRatioId.lowercased(): assetPriceValue]
self.transactionSummaries = await fetchTransactionSummarys(keyring: keyring, network: network, assetRatios: assetRatios)
case .coinMarket(let coinMarket, _):
case .coinMarket(let coinMarket):
// comes from Market tab
self.price = self.currencyFormatter.string(from: NSNumber(value: coinMarket.currentPrice)) ?? ""
self.priceDelta = self.percentFormatter.string(from: NSNumber(value: coinMarket.priceChangePercentage24h / 100.0)) ?? ""
Expand Down
19 changes: 0 additions & 19 deletions Sources/BraveWallet/Crypto/Stores/MarketStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class MarketStore: ObservableObject {
private let rpcService: BraveWalletJsonRpcService
private let walletService: BraveWalletBraveWalletService
private let assetsRequestLimit = 250
var allCoingeckoTokens: [BraveWallet.BlockchainToken] = []
let priceFormatter: NumberFormatter = .usdCurrencyFormatter
let priceChangeFormatter = NumberFormatter().then {
$0.numberStyle = .percent
Expand Down Expand Up @@ -67,26 +66,8 @@ public class MarketStore: ObservableObject {
// update currency code
guard !Task.isCancelled else { return }
self.currencyCode = await walletService.defaultBaseCurrency()
// update all supported coingecko tokens
guard !Task.isCancelled else { return }
self.allCoingeckoTokens = await fetchCoingeckoTokens()

self.isLoading = false
}
}

// Returns all coingecko tokens from the BlockchainRegistry and User's assets
@MainActor func fetchCoingeckoTokens() async -> [BraveWallet.BlockchainToken] {
let allNetworks = await rpcService.allNetworksForSupportedCoins()
let allUserAssets = await walletService.allUserAssets(in: allNetworks)
// Filter `allTokens` to remove any tokens existing in `allUserAssets`. This is possible for ERC721 tokens in the registry without a `tokenId`, which requires the user to add as a custom token
let allUserTokens = allUserAssets.flatMap(\.tokens).filter { !$0.coingeckoId.isEmpty }
let allBlockchainTokens = await blockchainRegistry.allTokens(in: allNetworks)
.flatMap(\.tokens)
.filter { token in
!allUserTokens.contains(where: { $0.id == token.id && !$0.coingeckoId.isEmpty })
}

return allUserTokens + allBlockchainTokens
}
}
7 changes: 0 additions & 7 deletions Sources/BraveWallet/WalletStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3946,13 +3946,6 @@ extension Strings {
value: "Market",
comment: "The page title that will display the top 250 tokens from the market via CoinGecko"
)
public static let assetDetailNoSupported = NSLocalizedString(
"wallet.assetDetailNoSupported",
tableName: "BraveWallet",
bundle: .module,
value: "This asset is not supported by Brave Wallet",
comment: "A label that will be displayed instead of account balances and transactions when the token is not supported by Brave Wallet."
)
public static let coinMarketInformation = NSLocalizedString(
"wallet.coinMarketInformation",
tableName: "BraveWallet",
Expand Down

0 comments on commit 4f16586

Please sign in to comment.