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';
|
2023-05-02 14:36:24 +02:00
|
|
|
import { getProviderConfig, getTokens } from '../../ducks/metamask/metamask';
|
2022-07-18 16:43:30 +02:00
|
|
|
import { getTokenList } from '../../selectors';
|
2022-02-16 17:59:39 +01:00
|
|
|
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';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { NETWORK_TYPES } from '../../../shared/constants/network';
|
2022-02-16 17:59:39 +01:00
|
|
|
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
|
|
|
import Tooltip from '../../components/ui/tooltip';
|
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import Box from '../../components/ui/box';
|
|
|
|
import {
|
2023-05-10 02:55:30 +02:00
|
|
|
TextVariant,
|
|
|
|
FontWeight,
|
2022-02-16 17:59:39 +01:00
|
|
|
DISPLAY,
|
2023-05-10 02:55:30 +02:00
|
|
|
TextAlign,
|
|
|
|
OverflowWrap,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
|
|
|
IconColor,
|
2022-02-16 17:59:39 +01:00
|
|
|
} from '../../helpers/constants/design-system';
|
2022-03-07 19:54:36 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
|
2023-01-31 18:00:26 +01:00
|
|
|
import {
|
2023-04-24 16:19:19 +02:00
|
|
|
ButtonIcon,
|
|
|
|
ButtonIconSize,
|
|
|
|
IconName,
|
2023-05-10 02:55:30 +02:00
|
|
|
Text,
|
2023-04-24 16:19:19 +02:00
|
|
|
} from '../../components/component-library';
|
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);
|
|
|
|
|
2022-03-02 17:01:53 +01:00
|
|
|
const { address: tokenAddress } = useParams();
|
2022-08-10 03:26:25 +02:00
|
|
|
const tokenMetadata = tokenList[tokenAddress.toLowerCase()];
|
2022-03-22 20:46:18 +01:00
|
|
|
const aggregators = tokenMetadata?.aggregators?.join(', ');
|
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,
|
|
|
|
);
|
|
|
|
|
2023-05-02 14:36:24 +02:00
|
|
|
const { nickname, type: networkType } = useSelector(getProviderConfig);
|
2022-02-16 17:59:39 +01:00
|
|
|
|
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
|
|
|
|
|
|
|
if (!token) {
|
|
|
|
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Box className="page-container token-details">
|
|
|
|
<Box marginLeft={5} marginRight={6}>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
fontWeight={FontWeight.Bold}
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={4}
|
2023-05-10 02:55:30 +02:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
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"
|
|
|
|
/>
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-02-16 17:59:39 +01:00
|
|
|
<Box display={DISPLAY.FLEX} marginTop={4}>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
align={TextAlign.Center}
|
|
|
|
fontWeight={FontWeight.Bold}
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginRight={5}
|
2023-05-10 02:55:30 +02:00
|
|
|
variant={TextVariant.headingSm}
|
|
|
|
as="h4"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__token-value"
|
|
|
|
>
|
2022-02-26 01:00:51 +01:00
|
|
|
{tokenBalance || ''}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-02-16 17:59:39 +01:00
|
|
|
<Box marginTop={1}>
|
|
|
|
<Identicon
|
|
|
|
diameter={32}
|
|
|
|
address={token.address}
|
2022-08-10 03:26:25 +02:00
|
|
|
image={tokenMetadata ? tokenMetadata.iconUrl : token.image}
|
2022-02-16 17:59:39 +01:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={4}
|
2023-05-10 02:55:30 +02:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{tokenCurrencyBalance || ''}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={6}
|
2023-05-10 02:55:30 +02:00
|
|
|
variant={TextVariant.bodyXs}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-05-10 02:55:30 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{t('tokenContractAddress')}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-02-16 17:59:39 +01:00
|
|
|
<Box display={DISPLAY.FLEX}>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={2}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2023-05-10 02:55:30 +02:00
|
|
|
overflowWrap={OverflowWrap.BreakWord}
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__token-address"
|
|
|
|
>
|
|
|
|
{token.address}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-02-16 17:59:39 +01:00
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
title={copied ? t('copiedExclamation') : t('copyToClipboard')}
|
|
|
|
containerClassName="token-details__copy-icon"
|
|
|
|
>
|
2023-01-31 18:00:26 +01:00
|
|
|
<ButtonIcon
|
2023-02-02 21:15:26 +01:00
|
|
|
ariaLabel="copy"
|
2023-04-24 16:19:19 +02:00
|
|
|
name={copied ? IconName.CopySuccess : IconName.Copy}
|
2022-02-16 17:59:39 +01:00
|
|
|
className="token-details__copyIcon"
|
2023-01-31 18:00:26 +01:00
|
|
|
onClick={() => handleCopy(token.address)}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.primaryDefault}
|
2023-04-24 16:19:19 +02:00
|
|
|
size={ButtonIconSize.Sm}
|
2023-01-31 18:00:26 +01:00
|
|
|
/>
|
2022-02-16 17:59:39 +01:00
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodyXs}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={4}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-05-10 02:55:30 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{t('tokenDecimalTitle')}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={1}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{token.decimals}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodyXs}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={4}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-05-10 02:55:30 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
|
|
|
{t('network')}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={1}
|
|
|
|
marginTop={0}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2022-02-16 17:59:39 +01:00
|
|
|
>
|
2022-09-14 16:55:31 +02:00
|
|
|
{networkType === NETWORK_TYPES.RPC
|
2023-03-09 22:00:28 +01:00
|
|
|
? nickname ?? t('privateNetwork')
|
2022-02-16 17:59:39 +01:00
|
|
|
: t(networkType)}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-08-10 03:26:25 +02:00
|
|
|
{aggregators && (
|
2022-03-22 20:46:18 +01:00
|
|
|
<>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodyXs}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={4}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-05-10 02:55:30 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-03-22 20:46:18 +01:00
|
|
|
>
|
|
|
|
{t('tokenList')}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2022-07-20 22:47:51 +02:00
|
|
|
margin={0}
|
|
|
|
marginTop={1}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2022-03-22 20:46:18 +01:00
|
|
|
>
|
|
|
|
{`${aggregators}.`}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-03-22 20:46:18 +01:00
|
|
|
</>
|
|
|
|
)}
|
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 }),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
2023-05-10 02:55:30 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.primaryDefault}
|
|
|
|
>
|
2022-02-16 17:59:39 +01:00
|
|
|
{t('hideToken')}
|
2023-05-10 02:55:30 +02:00
|
|
|
</Text>
|
2022-02-16 17:59:39 +01:00
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|