From 9114724f2f0a8dc765ee70662ca840a70a6d67ba Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 11:47:51 -0700 Subject: [PATCH 01/18] Update scam warning to include suggested token ticker --- app/_locales/en/messages.json | 7 +++++-- .../token-list-item/token-list-item.js | 18 +++++++++++++++++- .../token-list-item/token-list-item.test.js | 4 +++- .../networks-form/networks-form.js | 6 ------ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index dbae0bb4a916..f4d7e9a443d7 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -2990,8 +2990,11 @@ "message": "Edit network details" }, "nativeTokenScamWarningDescription": { - "message": "This network doesn't match its associated chain ID or name. Many popular tokens use the name $1, making it a target for scams. Scammers may trick you into sending them more valuable currency in return. Verify everything before you continue.", - "description": "$1 represents the currency name" + "message": "The network currency symbol entered does not match it’s associated currency symbol on the current chain ID. You have entered $1 while the detected currency symbol should be $2. Please verify you are connected to the correct chain. ", + "description": "$1 represents the currency name, $2 represents the expected currency symbol" + }, + "nativeTokenScamWarningDescriptionExpectedTokenFallback": { + "message": "something else" }, "nativeTokenScamWarningTitle": { "message": "This is a potential scam" diff --git a/ui/components/multichain/token-list-item/token-list-item.js b/ui/components/multichain/token-list-item/token-list-item.js index f28a53bcd075..c7f12e8045f7 100644 --- a/ui/components/multichain/token-list-item/token-list-item.js +++ b/ui/components/multichain/token-list-item/token-list-item.js @@ -54,6 +54,10 @@ import { MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { CURRENCY_SYMBOLS } from '../../../../shared/constants/network'; +import { + decimalToHex, + hexToDecimal, +} from '../../../../shared/modules/conversion.utils'; import { NETWORKS_ROUTE } from '../../../helpers/constants/routes'; import { setSelectedNetworkConfigurationId } from '../../../store/actions'; @@ -61,6 +65,7 @@ import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { getProviderConfig } from '../../../ducks/metamask/metamask'; import { getPortfolioUrl } from '../../../helpers/utils/portfolio'; +import { useSafeChains } from '../../../pages/settings/networks-tab/networks-form/use-safe-chains'; import { PercentageChange } from './price/percentage-change/percentage-change'; export const TokenListItem = ({ @@ -85,6 +90,13 @@ export const TokenListItem = ({ const metaMetricsId = useSelector(getMetaMetricsId); const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics); const isMarketingEnabled = useSelector(getDataCollectionForMarketing); + const { safeChains } = useSafeChains(); + + const decimalChainId = parseInt(hexToDecimal(chainId), 10); + + const [safeChainDetails] = safeChains.filter((chain) => { + return chain.chainId === decimalChainId; + }); // Scam warning const showScamWarning = @@ -385,7 +397,11 @@ export const TokenListItem = ({ {t('nativeTokenScamWarningTitle')} - {t('nativeTokenScamWarningDescription', [tokenSymbol])} + {t('nativeTokenScamWarningDescription', [ + tokenSymbol, + safeChainDetails?.nativeCurrency.symbol || + t('nativeTokenScamWarningDescriptionExpectedTokenFallback'), // never render "undefined" string value + ])} { const warningScamModal = getByTestId('scam-warning'); fireEvent.click(warningScamModal); - expect(getByText('This is a potential scam')).toBeInTheDocument(); + expect( + getByText('Incorrect Network Currency Symbol Entered'), + ).toBeInTheDocument(); }); it('should render crypto balance if useNativeCurrencyAsPrimaryCurrency is false', () => { diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index 487bf56f8378..8dd420cbb1f0 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -210,12 +210,6 @@ const NetworksForm = ({ }); safeChainsList.current = [ ...safeChains, - { - chainId: 137, - nativeCurrency: { - symbol: CHAINLIST_CURRENCY_SYMBOLS_MAP_NETWORK_COLLISION.MATIC, - }, - }, { chainId: 78, nativeCurrency: { From 10a31524a19be180512bc1a168938bedc8f3622b Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 11:48:26 -0700 Subject: [PATCH 02/18] Remove matic chain collision warning --- shared/constants/network.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/constants/network.ts b/shared/constants/network.ts index de8429d8ba6d..93cb30910f86 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -369,7 +369,6 @@ const CHAINLIST_CURRENCY_SYMBOLS_MAP = { export const CHAINLIST_CURRENCY_SYMBOLS_MAP_NETWORK_COLLISION = { WETHIO: 'ZYN', CHZ: 'CHZ', - MATIC: 'POL', }; export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.svg'; From b9fcb8e5662f309990e20ccb79a1f37810d95cf7 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 13:13:57 -0700 Subject: [PATCH 03/18] Update scam token modal title --- 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 f4d7e9a443d7..bb8a3cf301e7 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -2997,7 +2997,7 @@ "message": "something else" }, "nativeTokenScamWarningTitle": { - "message": "This is a potential scam" + "message": "Incorrect Network Currency Symbol Entered" }, "needHelp": { "message": "Need help? Contact $1", From 54b90b3da4953bb4e54e18256ac53256647b23bd Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 14:41:13 -0700 Subject: [PATCH 04/18] Update useSelector mocking in token-cell-test --- .../__snapshots__/token-cell.test.js.snap | 2 +- .../app/assets/token-cell/token-cell.test.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/components/app/assets/token-cell/__snapshots__/token-cell.test.js.snap b/ui/components/app/assets/token-cell/__snapshots__/token-cell.test.js.snap index e40a15f69863..4eeeb5603d46 100644 --- a/ui/components/app/assets/token-cell/__snapshots__/token-cell.test.js.snap +++ b/ui/components/app/assets/token-cell/__snapshots__/token-cell.test.js.snap @@ -27,7 +27,7 @@ exports[`Token Cell should match snapshot 1`] = ` class="mm-box mm-badge-wrapper__badge-container mm-badge-wrapper__badge-container--circular-top-right" >
?
diff --git a/ui/components/app/assets/token-cell/token-cell.test.js b/ui/components/app/assets/token-cell/token-cell.test.js index 6404f3603e58..c4e0c7ec7252 100644 --- a/ui/components/app/assets/token-cell/token-cell.test.js +++ b/ui/components/app/assets/token-cell/token-cell.test.js @@ -5,6 +5,8 @@ import { fireEvent } from '@testing-library/react'; import { useSelector } from 'react-redux'; import { renderWithProvider } from '../../../../../test/lib/render-helpers'; import { useTokenFiatAmount } from '../../../../hooks/useTokenFiatAmount'; +import { getTokenList } from '../../../../selectors'; +import { getMultichainCurrentChainId } from '../../../../selectors/multichain'; import { useIsOriginalTokenSymbol } from '../../../../hooks/useIsOriginalTokenSymbol'; import TokenCell from '.'; @@ -88,7 +90,17 @@ describe('Token Cell', () => { currentCurrency: 'usd', onClick: jest.fn(), }; - useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); + const useSelectorMock = useSelector; + useSelectorMock.mockImplementation((selector) => { + if (selector === getTokenList) { + return MOCK_GET_TOKEN_LIST; + } + if (selector === getMultichainCurrentChainId) { + return '0x89'; + } + return undefined; + }); + // useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); useTokenFiatAmount.mockReturnValue('5.00'); it('should match snapshot', () => { From 3b3b77ddffd459d26669f704fbfed81fc0097024 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 14:55:03 -0700 Subject: [PATCH 05/18] Only hexToDecimal on EVM compatible chains --- .../multichain/token-list-item/token-list-item.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.js b/ui/components/multichain/token-list-item/token-list-item.js index c7f12e8045f7..ca7b5300fc03 100644 --- a/ui/components/multichain/token-list-item/token-list-item.js +++ b/ui/components/multichain/token-list-item/token-list-item.js @@ -54,10 +54,7 @@ import { MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { CURRENCY_SYMBOLS } from '../../../../shared/constants/network'; -import { - decimalToHex, - hexToDecimal, -} from '../../../../shared/modules/conversion.utils'; +import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; import { NETWORKS_ROUTE } from '../../../helpers/constants/routes'; import { setSelectedNetworkConfigurationId } from '../../../store/actions'; @@ -92,7 +89,7 @@ export const TokenListItem = ({ const isMarketingEnabled = useSelector(getDataCollectionForMarketing); const { safeChains } = useSafeChains(); - const decimalChainId = parseInt(hexToDecimal(chainId), 10); + const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); const [safeChainDetails] = safeChains.filter((chain) => { return chain.chainId === decimalChainId; From af22a2b64180c1daf5694405e4599ab8d2345c97 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 15:09:06 -0700 Subject: [PATCH 06/18] Lint locales --- app/_locales/en/messages.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 46f6b58ca4ed..2e43fe7ac6ac 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -2994,10 +2994,12 @@ "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningDescriptionExpectedTokenFallback": { - "message": "something else" + "message": "something else", + "description": "graceful fallback for when token symbol isn't found" }, "nativeTokenScamWarningTitle": { - "message": "Incorrect Network Currency Symbol Entered" + "message": "Incorrect Network Currency Symbol Entered", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Need help? Contact $1", From 717570c560e45df4b1fdcb565c367c7bc62e5929 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 15:25:33 -0700 Subject: [PATCH 07/18] Add locales --- app/_locales/de/messages.json | 5 +++-- app/_locales/el/messages.json | 5 +++-- app/_locales/es/messages.json | 5 +++-- app/_locales/fr/messages.json | 5 +++-- app/_locales/hi/messages.json | 5 +++-- app/_locales/id/messages.json | 5 +++-- app/_locales/ja/messages.json | 5 +++-- app/_locales/ko/messages.json | 5 +++-- app/_locales/pt/messages.json | 5 +++-- app/_locales/ru/messages.json | 5 +++-- app/_locales/tl/messages.json | 5 +++-- app/_locales/tr/messages.json | 5 +++-- app/_locales/vi/messages.json | 5 +++-- app/_locales/zh_CN/messages.json | 5 +++-- 14 files changed, 42 insertions(+), 28 deletions(-) diff --git a/app/_locales/de/messages.json b/app/_locales/de/messages.json index dd34a61bf4e4..78aa380fbfe9 100644 --- a/app/_locales/de/messages.json +++ b/app/_locales/de/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Dieses Netzwerk passt nicht zu seiner zugehörigen Chain-ID oder seinem Namen. Viele beliebte Tokens verwenden den Namen $1, was sie zu einem Ziel für Betrüger macht. Betrüger könnten Sie dazu verleiten, ihnen im Gegenzug wertvollere Währung zu schicken. Überprüfen Sie alles, bevor Sie fortfahren.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Dies ist ein möglicher Betrug" + "message": "Dies ist ein möglicher Betrug", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Brauchen Sie Hilfe? Kontaktieren Sie $1.", diff --git a/app/_locales/el/messages.json b/app/_locales/el/messages.json index 45be1ea60597..9782e9fd28d0 100644 --- a/app/_locales/el/messages.json +++ b/app/_locales/el/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Αυτό το δίκτυο δεν ταιριάζει με το αναγνωριστικό ή το όνομα της σχετικής αλυσίδας. Πολλά δημοφιλή tokens χρησιμοποιούν το όνομα $1, καθιστώντας το στόχο για απάτες. Οι απατεώνες μπορεί να σας ξεγελάσουν για να τους στείλετε πιο πολύτιμα νομίσματα σε αντάλλαγμα. Επαληθεύστε τα πάντα προτού συνεχίσετε.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Πρόκειται για πιθανή απάτη" + "message": "Πρόκειται για πιθανή απάτη", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Χρειάζεστε βοήθεια; Επικοινωνήστε με $1", diff --git a/app/_locales/es/messages.json b/app/_locales/es/messages.json index 4bf761eef0ba..80a1d6e0e620 100644 --- a/app/_locales/es/messages.json +++ b/app/_locales/es/messages.json @@ -2919,10 +2919,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Esta red no coincide con su ID de cadena o nombre asociado. Muchos tokens populares usan el nombre $1, lo que los convierte en blanco de estafas. Los estafadores pueden engañarlo para que les envíe dinero más valioso a cambio. Verifique todo antes de continuar.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Esto es una estafa potencial" + "message": "Esto es una estafa potencial", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "¿Necesita ayuda? Comuníquese con $1", diff --git a/app/_locales/fr/messages.json b/app/_locales/fr/messages.json index 8980dfb0fd48..8e6ca3dc8afa 100644 --- a/app/_locales/fr/messages.json +++ b/app/_locales/fr/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "L’ID ou le nom de la chaîne associée à ce réseau n’est pas correct. De nombreux jetons populaires utilisent le nom $1, ce qui en fait une cible pour les escrocs. Vérifiez tout avant de continuer, car vous risquez de vous faire arnaquer.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Il pourrait s’agir d’une arnaque" + "message": "Il pourrait s’agir d’une arnaque", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Vous avez besoin d’aide ? Contactez $1", diff --git a/app/_locales/hi/messages.json b/app/_locales/hi/messages.json index 2d0caae66f01..bce8f5b66848 100644 --- a/app/_locales/hi/messages.json +++ b/app/_locales/hi/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "यह नेटवर्क अपनी एसोसिएटेड चेन ID या नाम से मेल नहीं खाता है। कई लोकप्रिय टोकन $1 नाम का उपयोग करते हैं, जिससे इसमें स्कैम किया जा सकता है। स्कैम करने वाले आपको बदले में ज़्यादा कीमती करेंसी भेजने का झांसा दे सकते हैं। आगे बढ़ने से पहले सब कुछ वेरीफाई करें।", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "यह एक बड़ा स्कैम हो सकता है" + "message": "यह एक बड़ा स्कैम हो सकता है", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "मदद चाहिए? $1 से कॉन्टेक्ट करें", diff --git a/app/_locales/id/messages.json b/app/_locales/id/messages.json index 4047a026b379..9b7c5fb38e95 100644 --- a/app/_locales/id/messages.json +++ b/app/_locales/id/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Jaringan ini tidak cocok dengan ID chain atau nama yang terkait. Banyak token populer menggunakan nama $1, menjadikannya target penipuan. Penipu dapat mengelabui Anda agar mengirimkan mata uang yang lebih berharga sebagai imbalannya. Verifikasikan semuanya sebelum melanjutkan.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Ini berpotensi penipuan" + "message": "Ini berpotensi penipuan", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Butuh bantuan? Hubungi $1", diff --git a/app/_locales/ja/messages.json b/app/_locales/ja/messages.json index 46f0ef9d1d95..c4cebd5e742b 100644 --- a/app/_locales/ja/messages.json +++ b/app/_locales/ja/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "このネットワークは関連付けられているチェーンIDまたは名前と一致していません。人気のトークンの多くが「$1」という名前を使用しているため、詐欺の対象となっています。詐欺師はより価値の高い通貨を送り返すよう仕向けてくる可能性があります。続行する前にすべてを確認してください。", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "これは詐欺の可能性があります" + "message": "これは詐欺の可能性があります", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "アシスタンスが必要な場合は、$1にお問い合わせください", diff --git a/app/_locales/ko/messages.json b/app/_locales/ko/messages.json index 904cd16deb49..0d6ea6681e8d 100644 --- a/app/_locales/ko/messages.json +++ b/app/_locales/ko/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "이 네트워크는 연결된 체인 ID 또는 이름이 일치하지 않습니다. 여러 인기 토큰이 $1(이)라는 이름을 사용하기 때문에 사기의 표적이 되고 있습니다. 사기꾼은 더 가격이 높은 암호화폐를 주겠다고 속일 수 있습니다. 계속하기 전에 모든 사항을 확인하세요.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "사기일 수 있습니다" + "message": "사기일 수 있습니다", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "도움이 필요하신가요? $1에 문의하세요.", diff --git a/app/_locales/pt/messages.json b/app/_locales/pt/messages.json index a1340fd2568a..20d97c761bb6 100644 --- a/app/_locales/pt/messages.json +++ b/app/_locales/pt/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Esta rede não corresponde ao seu ID da cadeia ou nome associado. Como muitos tokens populares usam o nome $1, ele é visado para golpes. Golpistas podem enganar você para que envie a eles alguma moeda mais valiosa em troca. Confirme todas as informações antes de prosseguir.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Isto é um possível golpe" + "message": "Isto é um possível golpe", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Precisa de ajuda? Contate $1", diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 8c94d3ad9074..97f5dc9441e2 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Эта сеть не соответствует ID или имени связанного с ней блокчейна. Многие популярные токены используют название $1, что делает его объектом мошенничества. Мошенники могут обманом заставить вас отправить им взамен более ценную валюту. Проверьте все, прежде чем продолжить.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Это потенциальное мошенничество" + "message": "Это потенциальное мошенничество", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Нужна помощь? Обратитесь в $1", diff --git a/app/_locales/tl/messages.json b/app/_locales/tl/messages.json index 1b86e07a8628..159d20d6e098 100644 --- a/app/_locales/tl/messages.json +++ b/app/_locales/tl/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Ang network na ito ay hindi tugma sa kaugnay na chain ID o pangalan nito. Maraming popular na token ang gumagamit ng pangalang $1, kaya nagiging puntirya ito ng mga scam. Maaari kang linlangin ng mga scammer na magpadala sa kanila ng mas mahal na currency bilang kapalit. I-verify ang lahat bago magpatuloy.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Isa itong potensyal na scam" + "message": "Isa itong potensyal na scam", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Kailangan ng tulong? Makipag-ugnayan sa $1", diff --git a/app/_locales/tr/messages.json b/app/_locales/tr/messages.json index f1833f56875d..cafeb1641e0d 100644 --- a/app/_locales/tr/messages.json +++ b/app/_locales/tr/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Bu ağ, ilişkili zincir kimliği veya adı ile uyumlu değil. Pek çok popüler token $1 adını kullanarak bunu dolandırıcılar için hedef haline getirir. Dolandırıcılar, karşılığında kendilerine daha değerli para birimi göndermek üzere sizi kandırabilir. Devam etmeden önce her şeyi doğrulayın.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Bu potansiyel bir dolandırıcılıktır" + "message": "Bu potansiyel bir dolandırıcılıktır", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Yardıma mı ihtiyacınız var? $1 bölümüne ulaşın", diff --git a/app/_locales/vi/messages.json b/app/_locales/vi/messages.json index 0f1d335eb92b..4fbc3ee66672 100644 --- a/app/_locales/vi/messages.json +++ b/app/_locales/vi/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "Mạng này không trùng khớp với tên hoặc ID chuỗi liên quan của nó. Nhiều token phổ biến sử dụng tên $1, khiến nó trở thành mục tiêu của các hành vi lừa đảo. Kẻ lừa đảo có thể lừa bạn gửi lại cho họ loại tiền tệ có giá trị hơn. Hãy xác minh mọi thứ trước khi tiếp tục.", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "Đây có khả năng là một hành vi lừa đảo" + "message": "Đây có khả năng là một hành vi lừa đảo", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "Bạn cần trợ giúp? Liên hệ $1", diff --git a/app/_locales/zh_CN/messages.json b/app/_locales/zh_CN/messages.json index 584299b4c155..33527d87e581 100644 --- a/app/_locales/zh_CN/messages.json +++ b/app/_locales/zh_CN/messages.json @@ -2922,10 +2922,11 @@ }, "nativeTokenScamWarningDescription": { "message": "此网络与其关联的链 ID 或名称不匹配。多种常用代币均使用名称 $1,使其成为欺诈目标。欺诈方可能会诱骗您向其发送更有价值的货币作为回报。在继续之前,请验证所有内容。", - "description": "$1 represents the currency name" + "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningTitle": { - "message": "这可能是欺诈" + "message": "这可能是欺诈", + "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { "message": "需要帮助?请联系 $1", From 97f41c2a754b444eef1b6577d3529fe70e6886a8 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 9 Sep 2024 17:12:33 -0700 Subject: [PATCH 08/18] Add undefined check for token-list-item --- .../multichain/token-list-item/token-list-item.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.js b/ui/components/multichain/token-list-item/token-list-item.js index ca7b5300fc03..8a32ca361f13 100644 --- a/ui/components/multichain/token-list-item/token-list-item.js +++ b/ui/components/multichain/token-list-item/token-list-item.js @@ -91,9 +91,11 @@ export const TokenListItem = ({ const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); - const [safeChainDetails] = safeChains.filter((chain) => { - return chain.chainId === decimalChainId; - }); + const [safeChainDetails] = + safeChains && + safeChains.filter((chain) => { + return chain.chainId === decimalChainId; + }); // Scam warning const showScamWarning = From e32d9f538d3707d74b60aca0386b8a7fc2765cc5 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Thu, 19 Sep 2024 12:56:37 -0700 Subject: [PATCH 09/18] Fix merge conflict in token-cell.test.tsx --- ui/components/app/assets/token-cell/token-cell.test.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ui/components/app/assets/token-cell/token-cell.test.tsx b/ui/components/app/assets/token-cell/token-cell.test.tsx index 822ddf5b8f76..72097e29cddd 100644 --- a/ui/components/app/assets/token-cell/token-cell.test.tsx +++ b/ui/components/app/assets/token-cell/token-cell.test.tsx @@ -92,9 +92,8 @@ describe('Token Cell', () => { image: '', onClick: jest.fn(), }; -<<<<<<< HEAD:ui/components/app/assets/token-cell/token-cell.test.js const useSelectorMock = useSelector; - useSelectorMock.mockImplementation((selector) => { + (useSelectorMock as jest.Mock).mockImplementation((selector) => { if (selector === getTokenList) { return MOCK_GET_TOKEN_LIST; } @@ -104,11 +103,7 @@ describe('Token Cell', () => { return undefined; }); // useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); - useTokenFiatAmount.mockReturnValue('5.00'); -======= - (useSelector as jest.Mock).mockReturnValue(MOCK_GET_TOKEN_LIST); (useTokenFiatAmount as jest.Mock).mockReturnValue('5.00'); ->>>>>>> develop:ui/components/app/assets/token-cell/token-cell.test.tsx it('should match snapshot', () => { const { container } = renderWithProvider( From 17e18a836552d9e6e2fadf3d2d7b579140bbfdad Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Thu, 19 Sep 2024 13:53:19 -0700 Subject: [PATCH 10/18] Lint --- .../multichain/token-list-item/token-list-item.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index 02291683f9a4..22fe06f17d9e 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -109,11 +109,11 @@ export const TokenListItem = ({ const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); - const [safeChainDetails] = - safeChains && - safeChains.filter((chain) => { - return chain.chainId === decimalChainId; - }); + const [safeChainDetails] = safeChains + ? safeChains.filter((chain) => { + return chain.chainId === decimalChainId.toString(); + }) + : []; // Scam warning const showScamWarning = From 2157a6d6f215e405921c2f8606282be6fb5b1b16 Mon Sep 17 00:00:00 2001 From: Nick Gambino <35090461+gambinish@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:20:55 -0700 Subject: [PATCH 11/18] Update app/_locales/en/messages.json Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com> --- 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 f01394654eb7..89941c76e898 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -3008,7 +3008,7 @@ "message": "Edit network details" }, "nativeTokenScamWarningDescription": { - "message": "The network currency symbol entered does not match it’s associated currency symbol on the current chain ID. You have entered $1 while the detected currency symbol should be $2. Please verify you are connected to the correct chain. ", + "message": "The native token symbol does not match the expected symbol of the native token for the network with the associated chain ID. You have entered $1 while the expected token symbol is $2. Please verify you are connected to the correct chain.", "description": "$1 represents the currency name, $2 represents the expected currency symbol" }, "nativeTokenScamWarningDescriptionExpectedTokenFallback": { From cd931f8a610efc28df5cdb247e471127a760bc50 Mon Sep 17 00:00:00 2001 From: Nick Gambino <35090461+gambinish@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:21:07 -0700 Subject: [PATCH 12/18] Update app/_locales/en/messages.json Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com> --- 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 89941c76e898..d62a6dc87c83 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -3016,7 +3016,7 @@ "description": "graceful fallback for when token symbol isn't found" }, "nativeTokenScamWarningTitle": { - "message": "Incorrect Network Currency Symbol Entered", + "message": "Unexpected Native Token Symbol", "description": "Title for nativeTokenScamWarningDescription" }, "needHelp": { From e6b567e22f7f3cb3227a752dde7f109db9b17266 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Fri, 20 Sep 2024 09:48:34 -0700 Subject: [PATCH 13/18] Cleanup --- ui/components/app/assets/token-cell/token-cell.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/components/app/assets/token-cell/token-cell.test.tsx b/ui/components/app/assets/token-cell/token-cell.test.tsx index 72097e29cddd..70714e9975f8 100644 --- a/ui/components/app/assets/token-cell/token-cell.test.tsx +++ b/ui/components/app/assets/token-cell/token-cell.test.tsx @@ -102,7 +102,6 @@ describe('Token Cell', () => { } return undefined; }); - // useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); (useTokenFiatAmount as jest.Mock).mockReturnValue('5.00'); it('should match snapshot', () => { From fb8f44e143507a4a5683ace009a424736c730290 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Fri, 20 Sep 2024 10:16:38 -0700 Subject: [PATCH 14/18] Update unit test --- .../multichain/token-list-item/token-list-item.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.test.tsx b/ui/components/multichain/token-list-item/token-list-item.test.tsx index efb71bac104d..0ff156d33705 100644 --- a/ui/components/multichain/token-list-item/token-list-item.test.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.test.tsx @@ -109,9 +109,7 @@ describe('TokenListItem', () => { const warningScamModal = getByTestId('scam-warning'); fireEvent.click(warningScamModal); - expect( - getByText('Incorrect Network Currency Symbol Entered'), - ).toBeInTheDocument(); + expect(getByText('Unexpected Native Token Symbol')).toBeInTheDocument(); }); it('should render crypto balance if useNativeCurrencyAsPrimaryCurrency is false', () => { From 70f82e6fb7f4933fcd2af4d672d38988499fcbf6 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Fri, 20 Sep 2024 11:57:49 -0700 Subject: [PATCH 15/18] Add test coverage --- .../token-list-item/token-list-item.test.tsx | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.test.tsx b/ui/components/multichain/token-list-item/token-list-item.test.tsx index 0ff156d33705..0ccb5a68dbbc 100644 --- a/ui/components/multichain/token-list-item/token-list-item.test.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.test.tsx @@ -6,6 +6,7 @@ import { renderWithProvider } from '../../../../test/lib/render-helpers'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { getIntlLocale } from '../../../ducks/locale/locale'; import { mockNetworkState } from '../../../../test/stub/networks'; +import { useSafeChains } from '../../../pages/settings/networks-tab/networks-form/use-safe-chains'; import { TokenListItem } from '.'; const state = { @@ -35,13 +36,30 @@ const state = { }, }; +const safeChainDetails = { + chainId: '1', + nativeCurrency: { + symbol: 'ETH', + }, +}; + let openTabSpy: jest.SpyInstance; jest.mock('../../../ducks/locale/locale', () => ({ getIntlLocale: jest.fn(), })); +jest.mock( + '../../../pages/settings/networks-tab/networks-form/use-safe-chains', + () => ({ + useSafeChains: jest.fn().mockReturnValue({ + safeChains: [safeChainDetails], + }), + }), +); + const mockGetIntlLocale = getIntlLocale; +const mockGetSafeChains = useSafeChains; describe('TokenListItem', () => { beforeAll(() => { @@ -100,6 +118,34 @@ describe('TokenListItem', () => { showPercentage: true, tokenImage: '', title: '', + tokenSymbol: 'SCAM_TOKEN', + }; + const { getByTestId, getByText } = renderWithProvider( + , + store, + ); + + const warningScamModal = getByTestId('scam-warning'); + fireEvent.click(warningScamModal); + + expect( + getByText( + 'The native token symbol does not match the expected symbol of the native token for the network with the associated chain ID. You have entered SCAM_TOKEN while the expected token symbol is ETH. Please verify you are connected to the correct chain.', + ), + ).toBeInTheDocument(); + }); + + it('should display warning scam modal fallback when safechains fails to resolve correctly', () => { + (mockGetSafeChains as unknown as jest.Mock).mockReturnValue([]); + const store = configureMockStore()(state); + const propsToUse = { + primary: '11.9751 ETH', + isNativeCurrency: true, + isOriginalTokenSymbol: false, + showPercentage: true, + tokenImage: '', + title: '', + tokenSymbol: 'SCAM_TOKEN', }; const { getByTestId, getByText } = renderWithProvider( , @@ -109,7 +155,11 @@ describe('TokenListItem', () => { const warningScamModal = getByTestId('scam-warning'); fireEvent.click(warningScamModal); - expect(getByText('Unexpected Native Token Symbol')).toBeInTheDocument(); + expect( + getByText( + 'The native token symbol does not match the expected symbol of the native token for the network with the associated chain ID. You have entered SCAM_TOKEN while the expected token symbol is something else. Please verify you are connected to the correct chain.', + ), + ).toBeInTheDocument(); }); it('should render crypto balance if useNativeCurrencyAsPrimaryCurrency is false', () => { From 74ebf605f41b8210cc20e15756a21dd5eb2daf21 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Fri, 20 Sep 2024 17:54:34 -0700 Subject: [PATCH 16/18] Use find method, expand decimalChainId type --- .../multichain/token-list-item/token-list-item.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index 4ceb85c09d76..f990e37a731e 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -106,11 +106,12 @@ export const TokenListItem = ({ const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); - const [safeChainDetails] = safeChains - ? safeChains.filter((chain) => { - return chain.chainId === decimalChainId.toString(); - }) - : []; + const safeChainDetails = + safeChains && + typeof decimalChainId === 'number' && + safeChains.find((chain) => { + return chain.chainId === decimalChainId.toString(); + }); // Scam warning const showScamWarning = From bf6def14978d30e60ead905e9205ec3a717785b4 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 23 Sep 2024 10:55:38 -0700 Subject: [PATCH 17/18] Lint --- .../multichain/token-list-item/token-list-item.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index f990e37a731e..9a5f2b38cbea 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -61,7 +61,10 @@ import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; import { NETWORKS_ROUTE } from '../../../helpers/constants/routes'; import { setEditedNetwork } from '../../../store/actions'; import { getPortfolioUrl } from '../../../helpers/utils/portfolio'; -import { useSafeChains } from '../../../pages/settings/networks-tab/networks-form/use-safe-chains'; +import { + SafeChain, + useSafeChains, +} from '../../../pages/settings/networks-tab/networks-form/use-safe-chains'; import { PercentageChange } from './price/percentage-change/percentage-change'; type TokenListItemProps = { @@ -106,7 +109,7 @@ export const TokenListItem = ({ const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); - const safeChainDetails = + const safeChainDetails: SafeChain | false | undefined = safeChains && typeof decimalChainId === 'number' && safeChains.find((chain) => { @@ -419,8 +422,9 @@ export const TokenListItem = ({ {t('nativeTokenScamWarningDescription', [ tokenSymbol, - safeChainDetails?.nativeCurrency.symbol || - t('nativeTokenScamWarningDescriptionExpectedTokenFallback'), // never render "undefined" string value + safeChainDetails + ? safeChainDetails.nativeCurrency.symbol + : t('nativeTokenScamWarningDescriptionExpectedTokenFallback'), // never render "undefined" string value ])} From 2c4e0a8cd09b7d91147d2c4a8d8a9553df1820be Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 23 Sep 2024 11:23:29 -0700 Subject: [PATCH 18/18] Fix e2e --- .../token-list-item/token-list-item.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index 9a5f2b38cbea..1198d3bdd165 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -109,12 +109,12 @@ export const TokenListItem = ({ const decimalChainId = isEvm && parseInt(hexToDecimal(chainId), 10); - const safeChainDetails: SafeChain | false | undefined = - safeChains && - typeof decimalChainId === 'number' && - safeChains.find((chain) => { + const safeChainDetails: SafeChain | undefined = safeChains?.find((chain) => { + if (typeof decimalChainId === 'number') { return chain.chainId === decimalChainId.toString(); - }); + } + return undefined; + }); // Scam warning const showScamWarning = @@ -422,9 +422,8 @@ export const TokenListItem = ({ {t('nativeTokenScamWarningDescription', [ tokenSymbol, - safeChainDetails - ? safeChainDetails.nativeCurrency.symbol - : t('nativeTokenScamWarningDescriptionExpectedTokenFallback'), // never render "undefined" string value + safeChainDetails?.nativeCurrency?.symbol || + t('nativeTokenScamWarningDescriptionExpectedTokenFallback'), // never render "undefined" string value ])}