2022-03-14 19:12:38 +01:00
|
|
|
import React, { useContext } from 'react';
|
2022-05-09 19:47:06 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2021-09-10 22:21:04 +02:00
|
|
|
import { IMPORT_TOKEN_ROUTE } from '../../../helpers/constants/routes';
|
2021-02-04 19:15:23 +01:00
|
|
|
import Button from '../../ui/button';
|
2021-09-10 20:03:42 +02:00
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
import { TEXT_ALIGN } from '../../../helpers/constants/design-system';
|
|
|
|
import { detectNewTokens } from '../../../store/actions';
|
2022-04-01 21:11:12 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../shared/constants/metametrics';
|
2022-05-09 19:47:06 +02:00
|
|
|
import { getIsMainnet, getIsTokenDetectionSupported } from '../../../selectors';
|
2018-10-16 22:54:34 +02:00
|
|
|
|
2022-05-09 19:47:06 +02:00
|
|
|
export default function ImportTokenLink() {
|
2022-03-14 19:12:38 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const history = useHistory();
|
2018-10-16 22:54:34 +02:00
|
|
|
|
2022-05-09 19:47:06 +02:00
|
|
|
const isMainnet = useSelector(getIsMainnet);
|
|
|
|
const isTokenDetectionSupported = useSelector(getIsTokenDetectionSupported);
|
|
|
|
|
|
|
|
const isTokenDetectionsupported =
|
|
|
|
isMainnet ||
|
|
|
|
(process.env.TOKEN_DETECTION_V2 && isTokenDetectionSupported) ||
|
|
|
|
Boolean(process.env.IN_TEST);
|
|
|
|
|
2020-06-12 18:22:00 +02:00
|
|
|
return (
|
2021-09-10 20:03:42 +02:00
|
|
|
<Box className="import-token-link" textAlign={TEXT_ALIGN.CENTER}>
|
2022-05-09 19:47:06 +02:00
|
|
|
{isTokenDetectionsupported && (
|
2021-09-27 19:42:51 +02:00
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
className="import-token-link__link"
|
|
|
|
type="link"
|
|
|
|
onClick={() => detectNewTokens()}
|
|
|
|
>
|
|
|
|
{t('refreshList')}
|
|
|
|
</Button>
|
|
|
|
{t('or')}
|
|
|
|
</>
|
|
|
|
)}
|
2021-09-10 20:03:42 +02:00
|
|
|
<Button
|
|
|
|
className="import-token-link__link"
|
|
|
|
type="link"
|
2020-06-12 18:22:00 +02:00
|
|
|
onClick={() => {
|
2021-09-10 22:21:04 +02:00
|
|
|
history.push(IMPORT_TOKEN_ROUTE);
|
2022-03-14 19:12:38 +01:00
|
|
|
trackEvent({
|
|
|
|
event: 'Clicked "Add Token"',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.NAVIGATION,
|
2022-03-14 19:12:38 +01:00
|
|
|
properties: {
|
|
|
|
action: 'Token Menu',
|
|
|
|
legacy_event: true,
|
|
|
|
},
|
|
|
|
});
|
2020-06-12 18:22:00 +02:00
|
|
|
}}
|
|
|
|
>
|
2022-05-09 19:47:06 +02:00
|
|
|
{isTokenDetectionsupported
|
2021-09-27 19:42:51 +02:00
|
|
|
? t('importTokens')
|
|
|
|
: t('importTokens').charAt(0).toUpperCase() +
|
|
|
|
t('importTokens').slice(1)}
|
2020-06-12 18:22:00 +02:00
|
|
|
</Button>
|
2021-09-10 20:03:42 +02:00
|
|
|
</Box>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-16 22:54:34 +02:00
|
|
|
}
|