From ba8495514cf857d1380ba47f185164c6ec2a53e9 Mon Sep 17 00:00:00 2001 From: Lantt Date: Fri, 8 Apr 2022 16:08:04 +0800 Subject: [PATCH] fix: should filter asset which not on support chain --- .../plugins/EVM/UI/Web3State/getAssetsFn.ts | 45 ++++++++++++------- .../src/plugins/Wallet/services/assets.ts | 1 + 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts b/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts index f767bbfb913f..d52b42264d73 100644 --- a/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts +++ b/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts @@ -1,4 +1,11 @@ -import { Pageable, Pagination, TokenType, Web3Plugin } from '@masknet/plugin-infra' +import { + getRegisteredWeb3Networks, + NetworkPluginID, + Pageable, + Pagination, + TokenType, + Web3Plugin, +} from '@masknet/plugin-infra' import BalanceCheckerABI from '@masknet/web3-contracts/abis/BalanceChecker.json' import ERC721ABI from '@masknet/web3-contracts/abis/ERC721.json' import type { ERC721 } from '@masknet/web3-contracts/types/ERC721' @@ -25,7 +32,6 @@ import BigNumber from 'bignumber.js' import { uniqBy } from 'lodash-unified' import Web3 from 'web3' import type { AbiItem } from 'web3-utils' -import { PLUGIN_NETWORKS } from '../../constants' import { makeSortAssertWithoutChainFn } from '../../utils/token' import { createGetLatestBalance } from './createGetLatestBalance' import { createNonFungibleToken } from './createNonFungibleToken' @@ -39,7 +45,10 @@ export const getFungibleAssetsFn = async (address: string, providerType: string, network: Web3Plugin.NetworkDescriptor, pagination?: Pagination) => { const chainId = context.chainId.getCurrentValue() const wallet = context.wallets.getCurrentValue().find((x) => isSameAddress(x.address, address)) - const networks = PLUGIN_NETWORKS + const networks = getRegisteredWeb3Networks().filter( + (x) => NetworkPluginID.PLUGIN_EVM === x.networkSupporterPluginID && x.isMainnet, + ) + const supportedNetworkIds = networks.map((x) => x.chainId) const trustedTokens = uniqBy( context.erc20Tokens .getCurrentValue() @@ -52,22 +61,24 @@ export const getFungibleAssetsFn = ) const { BALANCE_CHECKER_ADDRESS } = getEthereumConstants(chainId) const dataFromProvider = await context.getAssetsList(address, FungibleAssetProvider.DEBANK) - const assetsFromProvider: Web3Plugin.Asset[] = dataFromProvider.map((x) => ({ - id: x.token.address, - chainId: x.token.chainId, - balance: x.balance, - price: x.price, - value: x.value, - logoURI: x.logoURI, - token: { - ...x.token, - type: TokenType.Fungible, - name: x.token.name ?? 'Unknown Token', - symbol: x.token.symbol ?? 'Unknown', + const assetsFromProvider = dataFromProvider + .map>((x) => ({ id: x.token.address, chainId: x.token.chainId, - }, - })) + balance: x.balance, + price: x.price, + value: x.value, + logoURI: x.logoURI, + token: { + ...x.token, + name: x.token.name ?? 'Unknown Token', + symbol: x.token.symbol ?? 'Unknown', + id: x.token.address, + chainId: x.token.chainId, + type: TokenType.Fungible, + }, + })) + .filter((x) => supportedNetworkIds.includes(x.chainId)) const balanceCheckerContract = createContract( web3, diff --git a/packages/mask/src/plugins/Wallet/services/assets.ts b/packages/mask/src/plugins/Wallet/services/assets.ts index 8cb0df11296f..1d1c8c2c3915 100644 --- a/packages/mask/src/plugins/Wallet/services/assets.ts +++ b/packages/mask/src/plugins/Wallet/services/assets.ts @@ -143,6 +143,7 @@ export async function getAssetsList( function formatAssetsFromDebank(data: WalletTokenRecord[], network?: NetworkType) { return data + .filter((x) => getChainIdFromName(x.chain)) .filter((x) => !network || getChainIdFromName(x.chain) === getChainIdFromNetworkType(network)) .filter((x) => x.is_verified) .map((y): Asset => {