From 60817008f0a1016e5fb0571e80f5da45e96d3946 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 10 Oct 2024 14:23:42 +0200 Subject: [PATCH 01/22] feat: add token verification source count and link to block explorer In a previous redesign, the information about the number of sources a token has been verified on and the link to that token on the relevant block explorer was removed from the swap page. This returns that information. --- app/_locales/en/messages.json | 2 +- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index ecaedb3201d0..32dd05cca287 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -6483,7 +6483,7 @@ "message": "Verify third-party details" }, "verifyThisTokenOn": { - "message": "Verify this token on $1", + "message": "Verify this token on $1.", "description": "Points the user to etherscan as a place they can verify information about a token. $1 is replaced with the translation for \"etherscan\"" }, "verifyThisUnconfirmedTokenOn": { diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 72050df4aca9..9ae7d2926ecb 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -1019,7 +1019,16 @@ export default function PrepareSwapPage({ alignItems={AlignItems.stretch} >
- {selectedToToken?.string && yourTokenToBalance} + {showReviewQuote ? ( +
+ {t('swapTokenVerificationSources', [occurrences])} + {t('verifyThisTokenOn', [ + , + ])} +
+ ) : ( + selectedToToken?.string && yourTokenToBalance + )}
From c7d20bb7eb75bdaef291556b87411e48041223d2 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 14:12:21 +0200 Subject: [PATCH 02/22] fix: update message copy Create new message to handle updated copy for swap token verified sources. --- app/_locales/en/messages.json | 4 ++++ ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 49d48b9c71ac..aaaf6181b4b5 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -5895,6 +5895,10 @@ "message": "Swap $1 to $2", "description": "Used in the transaction display list to describe a swap. $1 and $2 are the symbols of tokens in involved in a swap." }, + "swapTokenVerifiedSources": { + "message": "Verified on $1 sources. You can check on $2.", + "description": "$1 the number of sources that have verified the token, $2 points the user to a block explorer as a place they can verify information about the token." + }, "swapTokenVerifiedOn1SourceDescription": { "message": "$1 is only verified on 1 source. Consider verifying it on $2 before proceeding.", "description": "$1 is a token name, $2 points the user to etherscan as a place they can verify information about a token. $1 is replaced with the translation for \"etherscan\"" diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 9ae7d2926ecb..fca196a0a73c 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -1020,12 +1020,9 @@ export default function PrepareSwapPage({ >
{showReviewQuote ? ( -
- {t('swapTokenVerificationSources', [occurrences])} - {t('verifyThisTokenOn', [ - , - ])} -
+ <> + {t('swapTokenVerifiedSources', [occurrences, ])} + ) : ( selectedToToken?.string && yourTokenToBalance )} From 6b4aed5b9bf5be68aca424f01a140679454a57bc Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 17:26:48 +0200 Subject: [PATCH 03/22] chore: use enum for human readable block explorer names --- shared/constants/swaps.ts | 24 +++++++++++++++++++ .../prepare-swap-page/prepare-swap-page.js | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/shared/constants/swaps.ts b/shared/constants/swaps.ts index 3868c7b6e2f0..53c552da33c0 100644 --- a/shared/constants/swaps.ts +++ b/shared/constants/swaps.ts @@ -175,15 +175,25 @@ export const GAS_API_BASE_URL = 'https://gas.api.cx.metamask.io'; export const GAS_DEV_API_BASE_URL = 'https://gas.uat-api.cx.metamask.io'; const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; +const BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BscScan'; export const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/'; +const MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'EtherScan'; const GOERLI_DEFAULT_BLOCK_EXPLORER_URL = 'https://goerli.etherscan.io/'; +const GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Goerli Etherscan'; const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/'; +const POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'PolygonScan'; const AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL = 'https://snowtrace.io/'; +const AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Snowtrace'; const OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL = 'https://optimistic.etherscan.io/'; +const OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Optimism Explorer'; const ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL = 'https://arbiscan.io/'; +const ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'ArbiScan'; const ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL = 'https://explorer.zksync.io/'; +const ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Zksync Explorer'; export const LINEA_DEFAULT_BLOCK_EXPLORER_URL = 'https://lineascan.build/'; +const LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'LineaScan'; const BASE_DEFAULT_BLOCK_EXPLORER_URL = 'https://basescan.org/'; +const BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BaseScan'; export const ALLOWED_PROD_SWAPS_CHAIN_IDS = [ CHAIN_IDS.MAINNET, @@ -312,6 +322,20 @@ export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP: BlockExplorerUrlMap = [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_URL, } as const; +export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP: BlockExplorerUrlMap = + { + [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + } as const; + export const ETHEREUM = 'ethereum'; export const POLYGON = 'polygon'; export const BSC = 'bsc'; diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index fca196a0a73c..b3fd96718b0f 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -93,6 +93,7 @@ import { } from '../../../../shared/constants/metametrics'; import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, + SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP, TokenBucketPriority, ERROR_FETCHING_QUOTES, QUOTES_NOT_AVAILABLE_ERROR, @@ -445,7 +446,7 @@ export default function PrepareSwapPage({ ); const blockExplorerLabel = rpcPrefs.blockExplorerUrl - ? getURLHostName(blockExplorerTokenLink) + ? SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ?? t('etherscan') : t('etherscan'); const { address: toAddress } = toToken || {}; From 2650379bc95592ab0390d1e560dbc22b01b05464 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 17:42:23 +0200 Subject: [PATCH 04/22] fix: don't show verified sources for chain's default token --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index b3fd96718b0f..b405f6a2afd4 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -94,6 +94,7 @@ import { import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP, + SWAPS_CHAINID_DEFAULT_TOKEN_MAP, TokenBucketPriority, ERROR_FETCHING_QUOTES, QUOTES_NOT_AVAILABLE_ERROR, @@ -797,6 +798,10 @@ export default function PrepareSwapPage({ isTokenEligibleForMaxBalance && hasPositiveFromTokenBalance; + const isNonDefaultToToken = !isSwapsDefaultTokenSymbol( + selectedToToken.symbol, + chainId + ); return (
From 460fe622ead3707149e1dfd0af2a93c1458c288a Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 18:05:43 +0200 Subject: [PATCH 05/22] fix: linting --- app/_locales/en/messages.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index aaaf6181b4b5..935e389bd865 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -5895,10 +5895,6 @@ "message": "Swap $1 to $2", "description": "Used in the transaction display list to describe a swap. $1 and $2 are the symbols of tokens in involved in a swap." }, - "swapTokenVerifiedSources": { - "message": "Verified on $1 sources. You can check on $2.", - "description": "$1 the number of sources that have verified the token, $2 points the user to a block explorer as a place they can verify information about the token." - }, "swapTokenVerifiedOn1SourceDescription": { "message": "$1 is only verified on 1 source. Consider verifying it on $2 before proceeding.", "description": "$1 is a token name, $2 points the user to etherscan as a place they can verify information about a token. $1 is replaced with the translation for \"etherscan\"" @@ -5906,6 +5902,10 @@ "swapTokenVerifiedOn1SourceTitle": { "message": "Potentially inauthentic token" }, + "swapTokenVerifiedSources": { + "message": "Verified on $1 sources. You can check on $2.", + "description": "$1 the number of sources that have verified the token, $2 points the user to a block explorer as a place they can verify information about the token." + }, "swapTooManyDecimalsError": { "message": "$1 allows up to $2 decimals", "description": "$1 is a token symbol and $2 is the max. number of decimals allowed for the token" From 4bc7293cb2aa543da65d8541d179a0dbd8e28bae Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 18:07:02 +0200 Subject: [PATCH 06/22] test: update blockExplorer naming --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js index a76160ef77bb..d67a43d267ce 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js @@ -171,7 +171,7 @@ describe('PrepareSwapPage', () => { , store, ); - const blockExplorer = getByText('etherscan.io'); + const blockExplorer = getByText('Etherscan'); expect(blockExplorer).toBeInTheDocument(); fireEvent.click(blockExplorer); expect(global.platform.openTab).toHaveBeenCalledWith({ From 78702c616727637700be5c4beac4d8fef03e0592 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 18:13:01 +0200 Subject: [PATCH 07/22] fix: linting --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index b405f6a2afd4..0ed90a79b5f1 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -94,7 +94,6 @@ import { import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP, - SWAPS_CHAINID_DEFAULT_TOKEN_MAP, TokenBucketPriority, ERROR_FETCHING_QUOTES, QUOTES_NOT_AVAILABLE_ERROR, @@ -802,6 +801,7 @@ export default function PrepareSwapPage({ selectedToToken.symbol, chainId ); + return (
@@ -1025,7 +1025,7 @@ export default function PrepareSwapPage({ alignItems={AlignItems.stretch} >
- {showReviewQuote ? ( + {showReviewQuote && isNonDefaultToToken ? ( <> {t('swapTokenVerifiedSources', [occurrences, ])} From 5b010b0a7865a977c39a373be06421d0e6d759d8 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 18:15:52 +0200 Subject: [PATCH 08/22] fix: linting --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 0ed90a79b5f1..68be1e5907bc 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -446,7 +446,8 @@ export default function PrepareSwapPage({ ); const blockExplorerLabel = rpcPrefs.blockExplorerUrl - ? SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ?? t('etherscan') + ? SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ?? + t('etherscan') : t('etherscan'); const { address: toAddress } = toToken || {}; @@ -799,7 +800,7 @@ export default function PrepareSwapPage({ const isNonDefaultToToken = !isSwapsDefaultTokenSymbol( selectedToToken.symbol, - chainId + chainId, ); return ( @@ -1027,7 +1028,10 @@ export default function PrepareSwapPage({
{showReviewQuote && isNonDefaultToToken ? ( <> - {t('swapTokenVerifiedSources', [occurrences, ])} + {t('swapTokenVerifiedSources', [ + occurrences, + , + ])} ) : ( selectedToToken?.string && yourTokenToBalance From 8d00e80066765493f948d350819eddcec4c1d700 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 16 Oct 2024 18:50:34 +0200 Subject: [PATCH 09/22] test: fix naming for Etherscan --- shared/constants/swaps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/constants/swaps.ts b/shared/constants/swaps.ts index 53c552da33c0..7b919c81ad71 100644 --- a/shared/constants/swaps.ts +++ b/shared/constants/swaps.ts @@ -177,7 +177,7 @@ export const GAS_DEV_API_BASE_URL = 'https://gas.uat-api.cx.metamask.io'; const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; const BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BscScan'; export const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/'; -const MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'EtherScan'; +const MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Etherscan'; const GOERLI_DEFAULT_BLOCK_EXPLORER_URL = 'https://goerli.etherscan.io/'; const GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Goerli Etherscan'; const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/'; From 6c778bcf479a0e1a4fdf801590645ecb712bcffd Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 17 Oct 2024 08:45:58 +0200 Subject: [PATCH 10/22] test: update tests --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js index d67a43d267ce..2019b1fb8236 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js @@ -128,7 +128,7 @@ describe('PrepareSwapPage', () => { expect( getByText('USDC is only verified on 1 source', { exact: false }), ).toBeInTheDocument(); - expect(getByText('etherscan.io')).toBeInTheDocument(); + expect(getByText('Etherscan')).toBeInTheDocument(); expect(getByText('Continue swapping')).toBeInTheDocument(); }); @@ -151,7 +151,7 @@ describe('PrepareSwapPage', () => { expect( getByText('Verify this token on', { exact: false }), ).toBeInTheDocument(); - expect(getByText('etherscan.io')).toBeInTheDocument(); + expect(getByText('Etherscan')).toBeInTheDocument(); expect(getByText('Continue swapping')).toBeInTheDocument(); }); From 08157c8f8439ea2bbd75e252a9e210927c0406ba Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 17 Oct 2024 17:06:04 +0200 Subject: [PATCH 11/22] refactor: use token address to determine if it is the native token --- .../prepare-swap-page/prepare-swap-page.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index fb0495670c12..f6e8b902746b 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -85,7 +85,6 @@ import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'; import { useEthFiatAmount } from '../../../hooks/useEthFiatAmount'; import { isSwapsDefaultTokenAddress, - isSwapsDefaultTokenSymbol, } from '../../../../shared/modules/swaps.utils'; import { MetaMetricsEventCategory, @@ -229,8 +228,8 @@ export default function PrepareSwapPage({ const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics); const isMarketingEnabled = useSelector(getDataCollectionForMarketing); - const fetchParamsFromToken = isSwapsDefaultTokenSymbol( - sourceTokenInfo?.symbol, + const fetchParamsFromToken = isSwapsDefaultTokenAddress( + sourceTokenInfo?.address, chainId, ) ? defaultSwapsToken @@ -242,7 +241,7 @@ export default function PrepareSwapPage({ // but is not in tokensWithBalances or tokens, then we want to add it to the usersTokens array so that // the balance of the token can appear in the from token selection dropdown const fromTokenArray = - !isSwapsDefaultTokenSymbol(fromToken?.symbol, chainId) && fromToken?.balance + !isSwapsDefaultTokenAddress(fromToken?.address, chainId) && fromToken?.balance ? [fromToken] : []; const usersTokens = uniqBy( @@ -311,7 +310,7 @@ export default function PrepareSwapPage({ { showFiat: true }, true, ); - const swapFromFiatValue = isSwapsDefaultTokenSymbol(fromTokenSymbol, chainId) + const swapFromFiatValue = isSwapsDefaultTokenAddress(fromTokenAddress, chainId) ? swapFromEthFiatValue : swapFromTokenFiatValue; @@ -788,8 +787,8 @@ export default function PrepareSwapPage({ ); } - const isNonDefaultToken = !isSwapsDefaultTokenSymbol( - fromTokenSymbol, + const isNonDefaultFromToken = !isSwapsDefaultTokenAddress( + fromTokenAddress, chainId, ); const hasPositiveFromTokenBalance = rawFromTokenBalance > 0; @@ -800,8 +799,8 @@ export default function PrepareSwapPage({ isTokenEligibleForMaxBalance && hasPositiveFromTokenBalance; - const isNonDefaultToToken = !isSwapsDefaultTokenSymbol( - selectedToToken.symbol, + const isNonDefaultToToken = !isSwapsDefaultTokenAddress( + selectedToToken.address, chainId, ); From 74ad24c304c06014bc5bc9b0780e3a85a8b9bbee Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 17 Oct 2024 17:20:42 +0200 Subject: [PATCH 12/22] fix: fix missed variable name update --- .../swaps/prepare-swap-page/prepare-swap-page.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index f6e8b902746b..4d3dc1d0969f 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -83,9 +83,7 @@ import { usePrevious } from '../../../hooks/usePrevious'; import { useTokenTracker } from '../../../hooks/useTokenTracker'; import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'; import { useEthFiatAmount } from '../../../hooks/useEthFiatAmount'; -import { - isSwapsDefaultTokenAddress, -} from '../../../../shared/modules/swaps.utils'; +import { isSwapsDefaultTokenAddress } from '../../../../shared/modules/swaps.utils'; import { MetaMetricsEventCategory, MetaMetricsEventLinkType, @@ -241,7 +239,8 @@ export default function PrepareSwapPage({ // but is not in tokensWithBalances or tokens, then we want to add it to the usersTokens array so that // the balance of the token can appear in the from token selection dropdown const fromTokenArray = - !isSwapsDefaultTokenAddress(fromToken?.address, chainId) && fromToken?.balance + !isSwapsDefaultTokenAddress(fromToken?.address, chainId) && + fromToken?.balance ? [fromToken] : []; const usersTokens = uniqBy( @@ -310,7 +309,10 @@ export default function PrepareSwapPage({ { showFiat: true }, true, ); - const swapFromFiatValue = isSwapsDefaultTokenAddress(fromTokenAddress, chainId) + const swapFromFiatValue = isSwapsDefaultTokenAddress( + fromTokenAddress, + chainId, + ) ? swapFromEthFiatValue : swapFromTokenFiatValue; @@ -793,7 +795,7 @@ export default function PrepareSwapPage({ ); const hasPositiveFromTokenBalance = rawFromTokenBalance > 0; const isTokenEligibleForMaxBalance = - isSmartTransaction || (!isSmartTransaction && isNonDefaultToken); + isSmartTransaction || (!isSmartTransaction && isNonDefaultFromToken); const showMaxBalanceLink = fromTokenSymbol && isTokenEligibleForMaxBalance && From 05130c13676fd96dfda949a3c8e3021b032b7661 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 17 Oct 2024 18:07:45 +0200 Subject: [PATCH 13/22] refactor: show verified sources before fetching quote --- .../prepare-swap-page/prepare-swap-page.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 4d3dc1d0969f..699587fffe47 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -1023,22 +1023,26 @@ export default function PrepareSwapPage({ + +
+ {selectedToToken?.string && yourTokenToBalance} +
+
- {showReviewQuote && isNonDefaultToToken ? ( - <> - {t('swapTokenVerifiedSources', [ + {isNonDefaultToToken && + t('swapTokenVerifiedSources', [ occurrences, , ])} - - ) : ( - selectedToToken?.string && yourTokenToBalance - )}
From 577614964bdea313ecba59b153cfb39802483de5 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Thu, 17 Oct 2024 18:33:58 +0200 Subject: [PATCH 14/22] style: linting --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 699587fffe47..adc908157cf3 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -1028,7 +1028,7 @@ export default function PrepareSwapPage({ justifyContent={JustifyContent.spaceBetween} alignItems={AlignItems.stretch} > -
+
{selectedToToken?.string && yourTokenToBalance}
@@ -1039,10 +1039,10 @@ export default function PrepareSwapPage({ >
{isNonDefaultToToken && - t('swapTokenVerifiedSources', [ - occurrences, - , - ])} + t('swapTokenVerifiedSources', [ + occurrences, + , + ])}
From 05994b180eb813c873d36e82cb21661585ed68cc Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Fri, 18 Oct 2024 09:09:17 +0200 Subject: [PATCH 15/22] test: update tests to account for multiple identical elements --- .../prepare-swap-page/prepare-swap-page.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js index 2019b1fb8236..fc61c4343b1f 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js @@ -120,7 +120,7 @@ describe('PrepareSwapPage', () => { }, }); const props = createProps(); - const { getByText } = renderWithProvider( + const { getByText, getAllByText } = renderWithProvider( , store, ); @@ -128,7 +128,7 @@ describe('PrepareSwapPage', () => { expect( getByText('USDC is only verified on 1 source', { exact: false }), ).toBeInTheDocument(); - expect(getByText('Etherscan')).toBeInTheDocument(); + expect(getAllByText('Etherscan')[0]).toBeInTheDocument(); expect(getByText('Continue swapping')).toBeInTheDocument(); }); @@ -143,7 +143,7 @@ describe('PrepareSwapPage', () => { }, }); const props = createProps(); - const { getByText } = renderWithProvider( + const { getByText, getAllByText } = renderWithProvider( , store, ); @@ -151,7 +151,7 @@ describe('PrepareSwapPage', () => { expect( getByText('Verify this token on', { exact: false }), ).toBeInTheDocument(); - expect(getByText('Etherscan')).toBeInTheDocument(); + expect(getAllByText('Etherscan')[0]).toBeInTheDocument(); expect(getByText('Continue swapping')).toBeInTheDocument(); }); @@ -167,11 +167,11 @@ describe('PrepareSwapPage', () => { }, }); const props = createProps(); - const { getByText } = renderWithProvider( + const { getByText, getAllByText } = renderWithProvider( , store, ); - const blockExplorer = getByText('Etherscan'); + const blockExplorer = getAllByText('Etherscan')[0]; expect(blockExplorer).toBeInTheDocument(); fireEvent.click(blockExplorer); expect(global.platform.openTab).toHaveBeenCalledWith({ From 30182e22d43b37b37dd87d24dd0981686af2f18f Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Fri, 18 Oct 2024 09:24:50 +0200 Subject: [PATCH 16/22] test: linting --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js index fc61c4343b1f..adb5b56ddd93 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.test.js @@ -167,7 +167,7 @@ describe('PrepareSwapPage', () => { }, }); const props = createProps(); - const { getByText, getAllByText } = renderWithProvider( + const { getAllByText } = renderWithProvider( , store, ); From dd670b95bdbf53ce62ff93941d2daf89f4f3215a Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Fri, 18 Oct 2024 09:50:28 +0200 Subject: [PATCH 17/22] refactor: copy change --- app/_locales/en/messages.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 11d7159c6829..1a9cf3d4e077 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -5908,7 +5908,7 @@ "message": "Potentially inauthentic token" }, "swapTokenVerifiedSources": { - "message": "Verified on $1 sources. You can check on $2.", + "message": "Confirmed by $1 sources. Verify on $2.", "description": "$1 the number of sources that have verified the token, $2 points the user to a block explorer as a place they can verify information about the token." }, "swapTooManyDecimalsError": { From 83acf3a64ce6a763637d9d2265f3f9ce75b19eb3 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Tue, 22 Oct 2024 08:52:03 +0200 Subject: [PATCH 18/22] fix: don't show verified sources count until a to token is selected --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index adc908157cf3..b8cd286a2dc6 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useState, useCallback } from 'react'; import BigNumber from 'bignumber.js'; import PropTypes from 'prop-types'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; -import { uniqBy, isEqual } from 'lodash'; +import { uniqBy, isEqual, isEmpty } from 'lodash'; import { useHistory } from 'react-router-dom'; import { getTokenTrackerLink } from '@metamask/etherscan-link'; import classnames from 'classnames'; @@ -1038,7 +1038,7 @@ export default function PrepareSwapPage({ alignItems={AlignItems.stretch} >
- {isNonDefaultToToken && + {selectedToToken && !isEmpty(selectedToToken) && isNonDefaultToToken && t('swapTokenVerifiedSources', [ occurrences, , From 8f8d708c801deac3bc2e03b2d5999ee4e809fcf4 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Tue, 22 Oct 2024 09:25:09 +0200 Subject: [PATCH 19/22] style: linting --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index b8cd286a2dc6..13c66a7fbcda 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -1038,7 +1038,9 @@ export default function PrepareSwapPage({ alignItems={AlignItems.stretch} >
- {selectedToToken && !isEmpty(selectedToToken) && isNonDefaultToToken && + {selectedToToken && + !isEmpty(selectedToToken) && + isNonDefaultToToken && t('swapTokenVerifiedSources', [ occurrences, , From dfc8e61db476cbff2d098a9cb9d69e60eb8c7dc7 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 23 Oct 2024 16:44:11 +0200 Subject: [PATCH 20/22] refactor: move block explorer url and human readable name constants to common file --- shared/constants/common.ts | 55 +++++++++++++++++++ shared/constants/swaps.ts | 53 ------------------ .../assets/nfts/nft-details/nft-details.tsx | 4 +- .../account-list/account-list.tsx | 4 +- ...nteractive-replacement-token-page.test.tsx | 4 +- .../interactive-replacement-token-page.tsx | 4 +- ui/pages/swaps/awaiting-swap/awaiting-swap.js | 4 +- .../prepare-swap-page/prepare-swap-page.js | 10 ++-- .../item-list/item-list.component.js | 4 +- .../smart-transaction-status.js | 4 +- 10 files changed, 75 insertions(+), 71 deletions(-) diff --git a/shared/constants/common.ts b/shared/constants/common.ts index f45ec8abd7e4..e30610afe5b4 100644 --- a/shared/constants/common.ts +++ b/shared/constants/common.ts @@ -1,5 +1,60 @@ +import { CHAIN_IDS } from './network'; + export enum EtherDenomination { ETH = 'ETH', GWEI = 'GWEI', WEI = 'WEI', } + +const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; +const BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BscScan'; +const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/'; +const MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Etherscan'; +const GOERLI_DEFAULT_BLOCK_EXPLORER_URL = 'https://goerli.etherscan.io/'; +const GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Goerli Etherscan'; +const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/'; +const POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'PolygonScan'; +const AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL = 'https://snowtrace.io/'; +const AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Snowtrace'; +const OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL = 'https://optimistic.etherscan.io/'; +const OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Optimism Explorer'; +const ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL = 'https://arbiscan.io/'; +const ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'ArbiScan'; +const ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL = 'https://explorer.zksync.io/'; +const ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Zksync Explorer'; +const LINEA_DEFAULT_BLOCK_EXPLORER_URL = 'https://lineascan.build/'; +const LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'LineaScan'; +const BASE_DEFAULT_BLOCK_EXPLORER_URL = 'https://basescan.org/'; +const BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BaseScan'; + +type BlockExplorerUrlMap = { + [key: string]: string; +}; + +export const CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP: BlockExplorerUrlMap = + { + [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_URL, + } as const; + +export const CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP: BlockExplorerUrlMap = + { + [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, + } as const; diff --git a/shared/constants/swaps.ts b/shared/constants/swaps.ts index 7b919c81ad71..8dfecccef6e6 100644 --- a/shared/constants/swaps.ts +++ b/shared/constants/swaps.ts @@ -49,10 +49,6 @@ export type SwapsTokenObject = { iconUrl: string; }; -type BlockExplorerUrlMap = { - [key: string]: string; -}; - export const ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = { symbol: CURRENCY_SYMBOLS.ETH, name: 'Ether', @@ -174,27 +170,6 @@ export const TOKEN_API_BASE_URL = 'https://tokens.api.cx.metamask.io'; export const GAS_API_BASE_URL = 'https://gas.api.cx.metamask.io'; export const GAS_DEV_API_BASE_URL = 'https://gas.uat-api.cx.metamask.io'; -const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; -const BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BscScan'; -export const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/'; -const MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Etherscan'; -const GOERLI_DEFAULT_BLOCK_EXPLORER_URL = 'https://goerli.etherscan.io/'; -const GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Goerli Etherscan'; -const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/'; -const POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'PolygonScan'; -const AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL = 'https://snowtrace.io/'; -const AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Snowtrace'; -const OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL = 'https://optimistic.etherscan.io/'; -const OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Optimism Explorer'; -const ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL = 'https://arbiscan.io/'; -const ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'ArbiScan'; -const ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL = 'https://explorer.zksync.io/'; -const ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'Zksync Explorer'; -export const LINEA_DEFAULT_BLOCK_EXPLORER_URL = 'https://lineascan.build/'; -const LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'LineaScan'; -const BASE_DEFAULT_BLOCK_EXPLORER_URL = 'https://basescan.org/'; -const BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL = 'BaseScan'; - export const ALLOWED_PROD_SWAPS_CHAIN_IDS = [ CHAIN_IDS.MAINNET, SWAPS_TESTNET_CHAIN_ID, @@ -308,34 +283,6 @@ export const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = { [CHAIN_IDS.BASE]: BASE_SWAPS_TOKEN_OBJECT, } as const; -export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP: BlockExplorerUrlMap = - { - [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_URL, - } as const; - -export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP: BlockExplorerUrlMap = - { - [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL, - } as const; - export const ETHEREUM = 'ethereum'; export const POLYGON = 'polygon'; export const BSC = 'bsc'; diff --git a/ui/components/app/assets/nfts/nft-details/nft-details.tsx b/ui/components/app/assets/nfts/nft-details/nft-details.tsx index 5ee8525cc98b..0dc9ec05250c 100644 --- a/ui/components/app/assets/nfts/nft-details/nft-details.tsx +++ b/ui/components/app/assets/nfts/nft-details/nft-details.tsx @@ -66,7 +66,7 @@ import { MetaMetricsContext } from '../../../../../contexts/metametrics'; import { Content, Footer, Page } from '../../../../multichain/pages/page'; import { formatCurrency } from '../../../../../helpers/utils/confirm-tx.util'; import { getShortDateFormatterV2 } from '../../../../../pages/asset/util'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../../../shared/constants/common'; import { getConversionRate } from '../../../../../ducks/metamask/metamask'; import { Numeric } from '../../../../../../shared/modules/Numeric'; // TODO: Remove restricted import @@ -277,7 +277,7 @@ export default function NftDetails({ nft }: { nft: Nft }) { null as unknown as string, // no holderAddress { blockExplorerUrl: - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, }, ); }; diff --git a/ui/pages/institutional/account-list/account-list.tsx b/ui/pages/institutional/account-list/account-list.tsx index e710a0e6e93a..84431f867307 100644 --- a/ui/pages/institutional/account-list/account-list.tsx +++ b/ui/pages/institutional/account-list/account-list.tsx @@ -1,6 +1,6 @@ import React from 'react'; import CustodyLabels from '../../../components/institutional/custody-labels'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/common'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { shortenAddress } from '../../../helpers/utils/util'; import Tooltip from '../../../components/ui/tooltip'; @@ -41,7 +41,7 @@ type CustodyAccountListProps = { }; const getButtonLinkHref = (account: Account) => { - const url = SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET]; + const url = CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET]; return `${url}address/${account.address}`; }; diff --git a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.test.tsx b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.test.tsx index b2db09b4d06c..6fca1af16a8e 100644 --- a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.test.tsx +++ b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.test.tsx @@ -5,7 +5,7 @@ import { useHistory } from 'react-router-dom'; import thunk from 'redux-thunk'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; import mockState from '../../../../test/data/mock-state.json'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/common'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { shortenAddress } from '../../../helpers/utils/util'; import { getSelectedInternalAccountFromMockState } from '../../../../test/jest/mocks'; @@ -145,7 +145,7 @@ describe('Interactive Replacement Token Page', function () { it('should render all the accounts correctly', async () => { const expectedHref = `${ - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET] + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET] }address/${custodianAddress}`; await act(async () => { diff --git a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx index c7258d1b2e38..149e8eeed9c0 100644 --- a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx +++ b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx @@ -29,7 +29,7 @@ import { getMetaMaskAccounts } from '../../../selectors'; import { getInstitutionalConnectRequests } from '../../../ducks/institutional/institutional'; import { getSelectedInternalAccount } from '../../../selectors/selectors'; import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/common'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { mmiActionsFactory, @@ -43,7 +43,7 @@ import { getMostRecentOverviewPage } from '../../../ducks/history/history'; import { shortenAddress } from '../../../helpers/utils/util'; const getButtonLinkHref = ({ address }: { address: string }) => { - const url = SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET]; + const url = CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET]; return `${url}address/${address}`; }; diff --git a/ui/pages/swaps/awaiting-swap/awaiting-swap.js b/ui/pages/swaps/awaiting-swap/awaiting-swap.js index 7c410ca03ce5..111af726acfa 100644 --- a/ui/pages/swaps/awaiting-swap/awaiting-swap.js +++ b/ui/pages/swaps/awaiting-swap/awaiting-swap.js @@ -48,8 +48,8 @@ import { QUOTES_NOT_AVAILABLE_ERROR, CONTRACT_DATA_DISABLED_ERROR, OFFLINE_FOR_MAINTENANCE, - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, } from '../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/common'; import { isSwapsDefaultTokenSymbol } from '../../../../shared/modules/swaps.utils'; import PulseLoader from '../../../components/ui/pulse-loader'; @@ -143,7 +143,7 @@ export default function AwaitingSwap({ }; const baseNetworkUrl = rpcPrefs.blockExplorerUrl ?? - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null; const blockExplorerUrl = getBlockExplorerLink( { hash: txHash, chainId }, diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 13c66a7fbcda..2b8a87554212 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -90,14 +90,16 @@ import { MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP, TokenBucketPriority, ERROR_FETCHING_QUOTES, QUOTES_NOT_AVAILABLE_ERROR, QUOTES_EXPIRED_ERROR, MAX_ALLOWED_SLIPPAGE, } from '../../../../shared/constants/swaps'; +import { + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP, + CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP, +} from '../../../../shared/constants/common'; import { resetSwapsPostFetchState, ignoreTokens, @@ -444,12 +446,12 @@ export default function PrepareSwapPage({ null, // no holderAddress { blockExplorerUrl: - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, }, ); const blockExplorerLabel = rpcPrefs.blockExplorerUrl - ? SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ?? + ? CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ?? t('etherscan') : t('etherscan'); diff --git a/ui/pages/swaps/searchable-item-list/item-list/item-list.component.js b/ui/pages/swaps/searchable-item-list/item-list/item-list.component.js index 779d1edf58a8..bd1bb5aa5aaf 100644 --- a/ui/pages/swaps/searchable-item-list/item-list/item-list.component.js +++ b/ui/pages/swaps/searchable-item-list/item-list/item-list.component.js @@ -13,7 +13,7 @@ import { getUseCurrencyRateCheck, } from '../../../../selectors'; import { MetaMetricsEventCategory } from '../../../../../shared/constants/metametrics'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../../shared/constants/common'; import { getURLHostName } from '../../../../helpers/utils/util'; import { MetaMetricsContext } from '../../../../contexts/metametrics'; @@ -35,7 +35,7 @@ export default function ItemList({ const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider); const blockExplorerLink = rpcPrefs.blockExplorerUrl ?? - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null; const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const blockExplorerHostName = getURLHostName(blockExplorerLink); diff --git a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js index 7b8d5910c218..d3127c9a94f3 100644 --- a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js +++ b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js @@ -23,7 +23,7 @@ import { getSmartTransactionsEnabled, getSmartTransactionsOptInStatusForMetrics, } from '../../../../shared/modules/selectors'; -import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps'; +import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/common'; import { DEFAULT_ROUTE, PREPARE_SWAP_ROUTE, @@ -87,7 +87,7 @@ export default function SmartTransactionStatusPage() { ); const baseNetworkUrl = rpcPrefs.blockExplorerUrl ?? - SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null; let smartTransactionStatus = SmartTransactionStatus.pending; From fed5429589bd6bf628640b10077edb0919c2b812 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 23 Oct 2024 16:46:27 +0200 Subject: [PATCH 21/22] style: lint --- shared/constants/common.ts | 25 +++++++++---------- .../prepare-swap-page/prepare-swap-page.js | 3 +-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/shared/constants/common.ts b/shared/constants/common.ts index e30610afe5b4..96d2b0c65b55 100644 --- a/shared/constants/common.ts +++ b/shared/constants/common.ts @@ -31,19 +31,18 @@ type BlockExplorerUrlMap = { [key: string]: string; }; -export const CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP: BlockExplorerUrlMap = - { - [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_URL, - [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_URL, - } as const; +export const CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP: BlockExplorerUrlMap = { + [CHAIN_IDS.BSC]: BSC_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.MAINNET]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.POLYGON]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.GOERLI]: GOERLI_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.AVALANCHE]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.OPTIMISM]: OPTIMISM_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.ARBITRUM]: ARBITRUM_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.LINEA_MAINNET]: LINEA_DEFAULT_BLOCK_EXPLORER_URL, + [CHAIN_IDS.BASE]: BASE_DEFAULT_BLOCK_EXPLORER_URL, +} as const; export const CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP: BlockExplorerUrlMap = { diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 2b8a87554212..d430fb33e807 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -445,8 +445,7 @@ export default function PrepareSwapPage({ null, // no networkId null, // no holderAddress { - blockExplorerUrl: - CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, + blockExplorerUrl: CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, }, ); From fb7523ee8d730b53ec23c112b6854d8e75230a03 Mon Sep 17 00:00:00 2001 From: Bryan Fullam Date: Wed, 30 Oct 2024 12:09:33 +0100 Subject: [PATCH 22/22] fix: account for zksync explorer token URL scheme --- .../prepare-swap-page/prepare-swap-page.js | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index d430fb33e807..1e5eb5179e2c 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { uniqBy, isEqual, isEmpty } from 'lodash'; import { useHistory } from 'react-router-dom'; -import { getTokenTrackerLink } from '@metamask/etherscan-link'; +import { getAccountLink, getTokenTrackerLink } from '@metamask/etherscan-link'; import classnames from 'classnames'; import { MetaMetricsContext } from '../../../contexts/metametrics'; @@ -142,6 +142,7 @@ import SwapsBannerAlert from '../swaps-banner-alert/swaps-banner-alert'; import SwapsFooter from '../swaps-footer'; import SelectedToken from '../selected-token/selected-token'; import ListWithSearch from '../list-with-search/list-with-search'; +import { CHAIN_IDS } from '../../../../shared/constants/network'; import QuotesLoadingAnimation from './quotes-loading-animation'; import ReviewQuote from './review-quote'; @@ -439,15 +440,23 @@ export default function PrepareSwapPage({ onInputChange(fromTokenInputValue, token.string, token.decimals); }; - const blockExplorerTokenLink = getTokenTrackerLink( - selectedToToken.address, - chainId, - null, // no networkId - null, // no holderAddress - { - blockExplorerUrl: CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, - }, - ); + const blockExplorerTokenLink = + chainId === CHAIN_IDS.ZKSYNC_ERA + ? // Use getAccountLink because zksync explorer uses a /address URL scheme instead of /token + getAccountLink(selectedToToken.address, chainId, { + blockExplorerUrl: + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, + }) + : getTokenTrackerLink( + selectedToToken.address, + chainId, + null, // no networkId + null, // no holderAddress + { + blockExplorerUrl: + CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? null, + }, + ); const blockExplorerLabel = rpcPrefs.blockExplorerUrl ? CHAINID_DEFAULT_BLOCK_EXPLORER_HUMAN_READABLE_URL_MAP[chainId] ??