mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
fix issue where token details page unnecessarily relies on send asset state (#13717)
This commit is contained in:
parent
6e34b70db3
commit
7ddd8cfede
@ -17,8 +17,6 @@ import {
|
|||||||
import { getURLHostName } from '../../../helpers/utils/util';
|
import { getURLHostName } from '../../../helpers/utils/util';
|
||||||
import { showModal } from '../../../store/actions';
|
import { showModal } from '../../../store/actions';
|
||||||
import { useNewMetricEvent } from '../../../hooks/useMetricEvent';
|
import { useNewMetricEvent } from '../../../hooks/useMetricEvent';
|
||||||
import { ASSET_TYPES, updateSendAsset } from '../../../ducks/send';
|
|
||||||
|
|
||||||
import AssetNavigation from './asset-navigation';
|
import AssetNavigation from './asset-navigation';
|
||||||
import AssetOptions from './asset-options';
|
import AssetOptions from './asset-options';
|
||||||
|
|
||||||
@ -70,13 +68,9 @@ export default function TokenAsset({ token }) {
|
|||||||
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
||||||
}}
|
}}
|
||||||
onViewTokenDetails={() => {
|
onViewTokenDetails={() => {
|
||||||
dispatch(
|
history.push({
|
||||||
updateSendAsset({
|
pathname: TOKEN_DETAILS,
|
||||||
type: ASSET_TYPES.TOKEN,
|
state: { tokenAddress: token.address },
|
||||||
details: { ...token },
|
|
||||||
}),
|
|
||||||
).then(() => {
|
|
||||||
history.push(TOKEN_DETAILS);
|
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
tokenSymbol={token.symbol}
|
tokenSymbol={token.symbol}
|
||||||
|
@ -2,7 +2,6 @@ import React, { useContext } from 'react';
|
|||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { Redirect, useHistory } from 'react-router-dom';
|
import { Redirect, useHistory } from 'react-router-dom';
|
||||||
import { getTokens } from '../../ducks/metamask/metamask';
|
import { getTokens } from '../../ducks/metamask/metamask';
|
||||||
import { getSendAssetAddress } from '../../ducks/send';
|
|
||||||
import { getUseTokenDetection, getTokenList } from '../../selectors';
|
import { getUseTokenDetection, getTokenList } from '../../selectors';
|
||||||
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
|
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
|
||||||
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
||||||
@ -31,18 +30,13 @@ export default function TokenDetailsPage() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const t = useContext(I18nContext);
|
const t = useContext(I18nContext);
|
||||||
|
|
||||||
const tokens = useSelector(getTokens);
|
const tokens = useSelector(getTokens);
|
||||||
const tokenList = useSelector(getTokenList);
|
const tokenList = useSelector(getTokenList);
|
||||||
const useTokenDetection = useSelector(getUseTokenDetection);
|
const useTokenDetection = useSelector(getUseTokenDetection);
|
||||||
|
|
||||||
const assetAddress = useSelector((state) => ({
|
const tokenAddress = history?.location?.state?.tokenAddress;
|
||||||
asset: getSendAssetAddress(state),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const { asset: tokenAddress } = assetAddress;
|
const tokenMetadata = tokenList?.[tokenAddress];
|
||||||
|
|
||||||
const tokenMetadata = tokenList[tokenAddress];
|
|
||||||
const fileName = tokenMetadata?.iconUrl;
|
const fileName = tokenMetadata?.iconUrl;
|
||||||
const imagePath = useTokenDetection
|
const imagePath = useTokenDetection
|
||||||
? fileName
|
? fileName
|
||||||
|
@ -3,8 +3,10 @@ import configureMockStore from 'redux-mock-store';
|
|||||||
import { fireEvent } from '@testing-library/react';
|
import { fireEvent } from '@testing-library/react';
|
||||||
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
||||||
import Identicon from '../../components/ui/identicon/identicon.component';
|
import Identicon from '../../components/ui/identicon/identicon.component';
|
||||||
|
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
||||||
import TokenDetailsPage from './token-details-page';
|
import TokenDetailsPage from './token-details-page';
|
||||||
|
|
||||||
|
const testTokenAddress = '0xaD6D458402F60fD3Bd25163575031ACDce07538A';
|
||||||
const state = {
|
const state = {
|
||||||
metamask: {
|
metamask: {
|
||||||
selectedAddress: '0xAddress',
|
selectedAddress: '0xAddress',
|
||||||
@ -86,10 +88,10 @@ const state = {
|
|||||||
},
|
},
|
||||||
tokens: [
|
tokens: [
|
||||||
{
|
{
|
||||||
address: '0xaD6D458402F60fD3Bd25163575031ACDce07538A',
|
address: testTokenAddress,
|
||||||
symbol: 'DAA',
|
symbol: 'DAA',
|
||||||
decimals: 18,
|
decimals: 18,
|
||||||
image: null,
|
image: 'testImage',
|
||||||
isERC721: false,
|
isERC721: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -101,28 +103,23 @@ const state = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
send: {
|
|
||||||
asset: {
|
|
||||||
balance: '0x0',
|
|
||||||
type: 'TOKEN',
|
|
||||||
details: {
|
|
||||||
address: '0xaD6D458402F60fD3Bd25163575031ACDce07538A',
|
|
||||||
decimals: 18,
|
|
||||||
image: null,
|
|
||||||
isERC721: false,
|
|
||||||
symbol: 'DAI',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
token: {
|
|
||||||
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
|
|
||||||
decimals: 18,
|
|
||||||
image: './images/eth_logo.svg',
|
|
||||||
isERC721: false,
|
|
||||||
symbol: 'ETH',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jest.mock('react-router-dom', () => {
|
||||||
|
const original = jest.requireActual('react-router-dom');
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
useHistory: () => ({
|
||||||
|
push: jest.fn(),
|
||||||
|
location: {
|
||||||
|
state: {
|
||||||
|
tokenAddress: testTokenAddress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('TokenDetailsPage', () => {
|
describe('TokenDetailsPage', () => {
|
||||||
it('should render title "Token details" in token details page', () => {
|
it('should render title "Token details" in token details page', () => {
|
||||||
const store = configureMockStore()(state);
|
const store = configureMockStore()(state);
|
||||||
@ -139,14 +136,13 @@ describe('TokenDetailsPage', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render an icon image', () => {
|
it('should render an icon image', () => {
|
||||||
const image = (
|
const token = state.metamask.tokens.find(({ address }) =>
|
||||||
<Identicon
|
isEqualCaseInsensitive(address, testTokenAddress),
|
||||||
diameter={32}
|
|
||||||
address={state.send.asset.details.address}
|
|
||||||
image={state.token.image}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
expect(image).toBeDefined();
|
const iconImage = (
|
||||||
|
<Identicon diameter={32} address={testTokenAddress} image={token.image} />
|
||||||
|
);
|
||||||
|
expect(iconImage).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render token contract address title in token details page', () => {
|
it('should render token contract address title in token details page', () => {
|
||||||
@ -158,7 +154,7 @@ describe('TokenDetailsPage', () => {
|
|||||||
it('should render token contract address in token details page', () => {
|
it('should render token contract address in token details page', () => {
|
||||||
const store = configureMockStore()(state);
|
const store = configureMockStore()(state);
|
||||||
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
||||||
expect(getByText(state.send.asset.details.address)).toBeInTheDocument();
|
expect(getByText(testTokenAddress)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call copy button when click is simulated', () => {
|
it('should call copy button when click is simulated', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user