From ef4f2aafd65f98a0cb7237ae9e189d0578cfd622 Mon Sep 17 00:00:00 2001 From: salimtb Date: Thu, 21 Nov 2024 11:45:43 +0100 Subject: [PATCH] Fix: fix after merge --- ui/components/app/assets/asset-list/asset-list.tsx | 12 +++++++++++- .../detected-token-selection-popover.js | 11 ++++++++++- ui/components/app/detected-token/detected-token.js | 14 ++++++++++---- .../detected-token-banner/detected-token-banner.js | 12 ++++++++++-- yarn.lock | 4 ++-- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/ui/components/app/assets/asset-list/asset-list.tsx b/ui/components/app/assets/asset-list/asset-list.tsx index 9ae4d49f557a..a362243cc113 100644 --- a/ui/components/app/assets/asset-list/asset-list.tsx +++ b/ui/components/app/assets/asset-list/asset-list.tsx @@ -7,6 +7,7 @@ import { getAllDetectedTokensForSelectedAddress, getDetectedTokensInCurrentNetwork, getIstokenDetectionInactiveOnNonMainnetSupportedNetwork, + getNetworkConfigurationsByChainId, getPreferences, getSelectedAccount, } from '../../../../selectors'; @@ -77,8 +78,17 @@ const AssetList = ({ onClickAsset, showTokensLinks }: AssetListProps) => { const isTokenDetectionInactiveOnNonMainnetSupportedNetwork = useSelector( getIstokenDetectionInactiveOnNonMainnetSupportedNetwork, ); + + const allNetworks = useSelector(getNetworkConfigurationsByChainId); const { tokenNetworkFilter } = useSelector(getPreferences); - const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length; + const allOpts: Record = {}; + Object.keys(allNetworks || {}).forEach((chainId) => { + allOpts[chainId] = true; + }); + + const allNetworksFilterShown = + Object.keys(tokenNetworkFilter || {}).length !== + Object.keys(allOpts || {}).length; const [showFundingMethodModal, setShowFundingMethodModal] = useState(false); const [showReceiveModal, setShowReceiveModal] = useState(false); diff --git a/ui/components/app/detected-token/detected-token-selection-popover/detected-token-selection-popover.js b/ui/components/app/detected-token/detected-token-selection-popover/detected-token-selection-popover.js index 8dfe00452eec..5974d8ba71b6 100644 --- a/ui/components/app/detected-token/detected-token-selection-popover/detected-token-selection-popover.js +++ b/ui/components/app/detected-token/detected-token-selection-popover/detected-token-selection-popover.js @@ -14,6 +14,7 @@ import { getCurrentChainId, getCurrentNetwork, getDetectedTokensInCurrentNetwork, + getNetworkConfigurationsByChainId, getPreferences, } from '../../../../selectors'; @@ -37,8 +38,16 @@ const DetectedTokenSelectionPopover = ({ const chainId = useSelector(getCurrentChainId); const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork); + const allNetworks = useSelector(getNetworkConfigurationsByChainId); const { tokenNetworkFilter } = useSelector(getPreferences); - const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length; + const allOpts = {}; + Object.keys(allNetworks || {}).forEach((networkId) => { + allOpts[networkId] = true; + }); + + const allNetworksFilterShown = + Object.keys(tokenNetworkFilter || {}).length !== + Object.keys(allOpts || {}).length; const currentNetwork = useSelector(getCurrentNetwork); diff --git a/ui/components/app/detected-token/detected-token.js b/ui/components/app/detected-token/detected-token.js index e27b6111764e..31e100547e12 100644 --- a/ui/components/app/detected-token/detected-token.js +++ b/ui/components/app/detected-token/detected-token.js @@ -60,10 +60,16 @@ const DetectedToken = ({ setShowDetectedTokens }) => { getAllDetectedTokensForSelectedAddress, ); const currentChainId = useSelector(getCurrentChainId); + const allNetworks = useSelector(getNetworkConfigurationsByChainId); const { tokenNetworkFilter } = useSelector(getPreferences); - const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length; + const allOpts = {}; + Object.keys(allNetworks || {}).forEach((chainId) => { + allOpts[chainId] = true; + }); - const configuration = useSelector(getNetworkConfigurationsByChainId); + const allNetworksFilterShown = + Object.keys(tokenNetworkFilter || {}).length !== + Object.keys(allOpts || {}).length; const totalDetectedTokens = useMemo(() => { return process.env.PORTFOLIO_VIEW && !allNetworksFilterShown @@ -148,7 +154,7 @@ const DetectedToken = ({ setShowDetectedTokens }) => { const importPromises = Object.entries(tokensByChainId).map( async ([networkId, { tokens }]) => { - const chainConfig = configuration[networkId]; + const chainConfig = allNetworks[networkId]; const { defaultRpcEndpointIndex } = chainConfig; const { networkClientId: networkInstanceId } = chainConfig.rpcEndpoints[defaultRpcEndpointIndex]; @@ -202,7 +208,7 @@ const DetectedToken = ({ setShowDetectedTokens }) => { const promises = Object.entries(groupedByChainId).map( async ([chainId, tokens]) => { - const chainConfig = configuration[chainId]; + const chainConfig = allNetworks[chainId]; const { defaultRpcEndpointIndex } = chainConfig; const { networkClientId: networkInstanceId } = chainConfig.rpcEndpoints[defaultRpcEndpointIndex]; diff --git a/ui/components/multichain/detected-token-banner/detected-token-banner.js b/ui/components/multichain/detected-token-banner/detected-token-banner.js index 162650f8a772..2147bdd08bf9 100644 --- a/ui/components/multichain/detected-token-banner/detected-token-banner.js +++ b/ui/components/multichain/detected-token-banner/detected-token-banner.js @@ -10,6 +10,7 @@ import { getPreferences, getSelectedInternalAccount, getAllDetectedTokens, + getNetworkConfigurationsByChainId, } from '../../../selectors'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { @@ -26,9 +27,16 @@ export const DetectedTokensBanner = ({ }) => { const t = useI18nContext(); const trackEvent = useContext(MetaMetricsContext); + const allNetworks = useSelector(getNetworkConfigurationsByChainId); const { tokenNetworkFilter } = useSelector(getPreferences); + const allOpts = {}; + Object.keys(allNetworks || {}).forEach((chainId) => { + allOpts[chainId] = true; + }); - const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length; + const allNetworksFilterShown = + Object.keys(tokenNetworkFilter || {}).length !== + Object.keys(allOpts || {}).length; const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork); const { address: selectedAddress } = useSelector(getSelectedInternalAccount); @@ -58,7 +66,7 @@ export const DetectedTokensBanner = ({ ? Object.values(detectedTokensMultichain) .flat() .map(({ address, symbol }) => `${symbol} - ${address}`) - : detectedTokens.map(({ address, symbol }) => `${symbol} - ${address}`); + : detectedTokens?.map(({ address, symbol }) => `${symbol} - ${address}`); const totalTokens = process.env.PORTFOLIO_VIEW && !allNetworksFilterShown diff --git a/yarn.lock b/yarn.lock index 5dc2340b7c99..654620b38f41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4975,7 +4975,7 @@ __metadata: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A44.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-44.1.0-012aa448d8.patch": version: 44.1.0 - resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A44.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-44.1.0-012aa448d8.patch::version=44.1.0&hash=611d79" + resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A44.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-44.1.0-012aa448d8.patch::version=44.1.0&hash=423db2" dependencies: "@ethereumjs/util": "npm:^8.1.0" "@ethersproject/abi": "npm:^5.7.0" @@ -5008,7 +5008,7 @@ __metadata: "@metamask/keyring-controller": ^18.0.0 "@metamask/network-controller": ^22.0.0 "@metamask/preferences-controller": ^14.0.0 - checksum: 10/6927a6af16d6e83a488a3f82e71fbf78b016728009672df12937411cfe7fa087bef34fd2642e04e2038c0baba91d64b9315c54800059e8dddeb31a06ebf25e1e + checksum: 10/5e3b0109e6b5c0d65338a18b2c590d15229003e05c55cf0013d8e32687bbe774de05872a7b61038aa90177a6ce01b32814c3c680ee3c10cbad8cba9db2d796aa languageName: node linkType: hard