Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update scam token warning #26994

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9114724
Update scam warning to include suggested token ticker
gambinish Sep 9, 2024
10a3152
Remove matic chain collision warning
gambinish Sep 9, 2024
b9fcb8e
Update scam token modal title
gambinish Sep 9, 2024
9b4a753
Merge branch 'develop' into fix/mmassets-384_update-scam-token-warning
gambinish Sep 9, 2024
54b90b3
Update useSelector mocking in token-cell-test
gambinish Sep 9, 2024
3b3b77d
Only hexToDecimal on EVM compatible chains
gambinish Sep 9, 2024
af22a2b
Lint locales
gambinish Sep 9, 2024
717570c
Add locales
gambinish Sep 9, 2024
97f41c2
Add undefined check for token-list-item
gambinish Sep 10, 2024
160437f
Merge develop and address merge conflict
gambinish Sep 19, 2024
e32d9f5
Fix merge conflict in token-cell.test.tsx
gambinish Sep 19, 2024
17e18a8
Lint
gambinish Sep 19, 2024
2157a6d
Update app/_locales/en/messages.json
gambinish Sep 20, 2024
cd931f8
Update app/_locales/en/messages.json
gambinish Sep 20, 2024
e6b567e
Cleanup
gambinish Sep 20, 2024
63c0aae
Merge branch 'fix/mmassets-384_update-scam-token-warning' of github.c…
gambinish Sep 20, 2024
711e394
Merge develop
gambinish Sep 20, 2024
975f416
Merge branch 'develop' into fix/mmassets-384_update-scam-token-warning
gambinish Sep 20, 2024
fb8f44e
Update unit test
gambinish Sep 20, 2024
5788ae8
Merge branch 'fix/mmassets-384_update-scam-token-warning' of github.c…
gambinish Sep 20, 2024
2de9985
Merge branch 'develop' into fix/mmassets-384_update-scam-token-warning
gambinish Sep 20, 2024
70f82e6
Add test coverage
gambinish Sep 20, 2024
0e886d0
Merge branch 'fix/mmassets-384_update-scam-token-warning' of github.c…
gambinish Sep 20, 2024
e43b0fc
Merge branch 'develop' into fix/mmassets-384_update-scam-token-warning
gambinish Sep 20, 2024
74ebf60
Use find method, expand decimalChainId type
gambinish Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/es/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/hi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/id/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/ja/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/ko/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/pt/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/ru/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/tr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/vi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/_locales/zh_CN/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-xs mm-avatar-network multichain-token-list-item__badge__avatar-network mm-text--body-xs mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--rounded-full mm-box--border-color-transparent box--border-style-solid box--border-width-1"
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-xs mm-avatar-network multichain-token-list-item__badge__avatar-network mm-text--body-xs mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-transparent box--border-style-solid box--border-width-1"
>
?
</div>
Expand Down
13 changes: 12 additions & 1 deletion ui/components/app/assets/token-cell/token-cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';
Expand Down Expand Up @@ -90,7 +92,16 @@ describe('Token Cell', () => {
image: '',
onClick: jest.fn(),
};
(useSelector as jest.Mock).mockReturnValue(MOCK_GET_TOKEN_LIST);
const useSelectorMock = useSelector;
(useSelectorMock as jest.Mock).mockImplementation((selector) => {
if (selector === getTokenList) {
return MOCK_GET_TOKEN_LIST;
}
if (selector === getMultichainCurrentChainId) {
return '0x89';
}
return undefined;
});
(useTokenFiatAmount as jest.Mock).mockReturnValue('5.00');

it('should match snapshot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -35,13 +36,30 @@ const state = {
},
};

const safeChainDetails = {
chainId: '1',
nativeCurrency: {
symbol: 'ETH',
},
};

let openTabSpy: jest.SpyInstance<void, [opts: { url: string }], unknown>;

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(() => {
Expand Down Expand Up @@ -100,6 +118,34 @@ describe('TokenListItem', () => {
showPercentage: true,
tokenImage: '',
title: '',
tokenSymbol: 'SCAM_TOKEN',
};
const { getByTestId, getByText } = renderWithProvider(
<TokenListItem {...propsToUse} />,
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(
<TokenListItem {...propsToUse} />,
Expand All @@ -109,7 +155,11 @@ describe('TokenListItem', () => {
const warningScamModal = getByTestId('scam-warning');
fireEvent.click(warningScamModal);

expect(getByText('This is a potential scam')).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', () => {
Expand Down
Loading