2022-02-16 17:59:39 +01:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2022-03-02 17:01:53 +01:00
|
|
|
import { Redirect, useHistory, useParams } from 'react-router-dom';
|
2022-02-16 17:59:39 +01:00
|
|
|
import { getTokens } from '../../ducks/metamask/metamask';
|
|
|
|
import { getUseTokenDetection, getTokenList } from '../../selectors';
|
|
|
|
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
|
2022-02-23 19:57:16 +01:00
|
|
|
import Identicon from '../../components/ui/identicon';
|
2022-02-16 17:59:39 +01:00
|
|
|
import { I18nContext } from '../../contexts/i18n';
|
|
|
|
import { useTokenTracker } from '../../hooks/useTokenTracker';
|
|
|
|
import { useTokenFiatAmount } from '../../hooks/useTokenFiatAmount';
|
|
|
|
import { showModal } from '../../store/actions';
|
|
|
|
import { NETWORK_TYPE_RPC } from '../../../shared/constants/network';
|
|
|
|
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
|
|
|
import Tooltip from '../../components/ui/tooltip';
|
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import CopyIcon from '../../components/ui/icon/copy-icon.component';
|
|
|
|
import Box from '../../components/ui/box';
|
|
|
|
import Typography from '../../components/ui/typography';
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
DISPLAY,
|
|
|
|
TEXT_ALIGN,
|
|
|
|
OVERFLOW_WRAP,
|
|
|
|
} from '../../helpers/constants/design-system';
|
2022-03-07 19:54:36 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
|
2022-02-16 17:59:39 +01:00
|
|
|
|
|
|
|
export default function TokenDetailsPage() {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
const t = useContext(I18nContext);
|
|
|
|
const tokens = useSelector(getTokens);
|
|
|
|
const tokenList = useSelector(getTokenList);
|
|
|
|
const useTokenDetection = useSelector(getUseTokenDetection);
|
|
|
|
|
2022-03-02 17:01:53 +01:00
|
|
|
const { address: tokenAddress } = useParams();
|
2022-02-23 21:43:41 +01:00
|
|
|
const tokenMetadata = Object.values(tokenList).find((token) =>
|
|
|
|
isEqualCaseInsensitive(token.address, tokenAddress),
|
|
|
|
);
|
2022-03-22 20:46:18 +01:00
|
|
|
const aggregators = tokenMetadata?.aggregators?.join(', ');
|
2022-02-16 17:59:39 +01:00
|
|
|
const fileName = tokenMetadata?.iconUrl;
|
2022-04-06 19:59:16 +02:00
|
|
|
let imagePath = fileName;
|
|
|
|
if (!process.env.TOKEN_DETECTION_V2) {
|
|
|
|
imagePath = useTokenDetection ? fileName : `images/contract/${fileName}`;
|
|
|
|
}
|
2022-02-16 17:59:39 +01:00
|
|
|
|
|
|
|
const token = tokens.find(({ address }) =>
|
|
|
|
isEqualCaseInsensitive(address, tokenAddress),
|
|
|
|
);
|
|
|
|
|
|
|
|
const { tokensWithBalances } = useTokenTracker([token]);
|
|
|
|
const tokenBalance = tokensWithBalances[0]?.string;
|
|
|
|
const tokenCurrencyBalance = useTokenFiatAmount(
|
|
|
|
token?.address,
|
|
|
|
tokenBalance,
|
|
|
|
token?.symbol,
|
|
|
|
);
|
|
|
|
|
|
|
|
const currentNetwork = useSelector((state) => ({
|
|
|
|
nickname: state.metamask.provider.nickname,
|
|
|
|
type: state.metamask.provider.type,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const { nickname: networkNickname, type: networkType } = currentNetwork;
|
|
|
|
|
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
|
|
|
|
|
|
|
if (!token) {
|
|
|
|
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Box className="page-container token-details">
|
|
|
|
<Box marginLeft={5} marginRight={6}>
|
|
|
|
<Typography
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
margin={[4, 0, 0, 0]}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__title"
|
|
|
|
>
|
|
|
|
{t('tokenDetails')}
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={() => history.push(`${ASSET_ROUTE}/${token.address}`)}
|
|
|
|
className="token-details__closeButton"
|
|
|
|
/>
|
|
|
|
</Typography>
|
|
|
|
<Box display={DISPLAY.FLEX} marginTop={4}>
|
|
|
|
<Typography
|
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
margin={[0, 5, 0, 0]}
|
|
|
|
variant={TYPOGRAPHY.H4}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__token-value"
|
|
|
|
>
|
2022-02-26 01:00:51 +01:00
|
|
|
{tokenBalance || ''}
|
2022-02-16 17:59:39 +01:00
|
|
|
</Typography>
|
|
|
|
<Box marginTop={1}>
|
|
|
|
<Identicon
|
|
|
|
diameter={32}
|
|
|
|
address={token.address}
|
|
|
|
image={tokenMetadata ? imagePath : token.image}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Typography
|
|
|
|
margin={[4, 0, 0, 0]}
|
|
|
|
variant={TYPOGRAPHY.H7}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{tokenCurrencyBalance || ''}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
margin={[6, 0, 0, 0]}
|
|
|
|
variant={TYPOGRAPHY.H9}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-16 17:59:39 +01:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('tokenContractAddress')}
|
|
|
|
</Typography>
|
|
|
|
<Box display={DISPLAY.FLEX}>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[2, 0, 0, 0]}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 17:59:39 +01:00
|
|
|
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
|
|
|
|
className="token-details__token-address"
|
|
|
|
>
|
|
|
|
{token.address}
|
|
|
|
</Typography>
|
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
title={copied ? t('copiedExclamation') : t('copyToClipboard')}
|
|
|
|
containerClassName="token-details__copy-icon"
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
className="token-details__copyIcon"
|
|
|
|
onClick={() => {
|
|
|
|
handleCopy(token.address);
|
|
|
|
}}
|
|
|
|
>
|
2022-03-25 23:15:31 +01:00
|
|
|
<CopyIcon size={11} color="var(--color-primary-default)" />
|
2022-02-16 17:59:39 +01:00
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H9}
|
|
|
|
margin={[4, 0, 0, 0]}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-16 17:59:39 +01:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('tokenDecimalTitle')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[1, 0, 0, 0]}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{token.decimals}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H9}
|
|
|
|
margin={[4, 0, 0, 0]}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-16 17:59:39 +01:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('network')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[1, 0, 0, 0]}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{networkType === NETWORK_TYPE_RPC
|
|
|
|
? networkNickname ?? t('privateNetwork')
|
|
|
|
: t(networkType)}
|
|
|
|
</Typography>
|
2022-03-22 20:46:18 +01:00
|
|
|
{process.env.TOKEN_DETECTION_V2 && aggregators && (
|
|
|
|
<>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H9}
|
|
|
|
margin={[4, 0, 0, 0]}
|
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('tokenList')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[1, 0, 0, 0]}
|
|
|
|
color={COLORS.TEXT_DEFAULT}
|
|
|
|
>
|
|
|
|
{`${aggregators}.`}
|
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
)}
|
2022-02-16 17:59:39 +01:00
|
|
|
<Button
|
2022-03-21 14:33:06 +01:00
|
|
|
type="secondary"
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__hide-token-button"
|
|
|
|
onClick={() => {
|
|
|
|
dispatch(
|
|
|
|
showModal({ name: 'HIDE_TOKEN_CONFIRMATION', token, history }),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
2022-03-09 16:24:53 +01:00
|
|
|
<Typography variant={TYPOGRAPHY.H6} color={COLORS.PRIMARY_DEFAULT}>
|
2022-02-16 17:59:39 +01:00
|
|
|
{t('hideToken')}
|
|
|
|
</Typography>
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|