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';
|
2023-04-03 17:31:04 +02:00
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../../shared/constants/metametrics';
|
2022-08-10 03:26:25 +02:00
|
|
|
import {
|
|
|
|
getIsTokenDetectionSupported,
|
|
|
|
getIsTokenDetectionInactiveOnMainnet,
|
|
|
|
} 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 isTokenDetectionSupported = useSelector(getIsTokenDetectionSupported);
|
2022-08-10 03:26:25 +02:00
|
|
|
const isTokenDetectionInactiveOnMainnet = useSelector(
|
|
|
|
getIsTokenDetectionInactiveOnMainnet,
|
|
|
|
);
|
2022-05-09 19:47:06 +02:00
|
|
|
|
2022-08-10 03:26:25 +02:00
|
|
|
const isTokenDetectionAvailable =
|
|
|
|
isTokenDetectionSupported ||
|
|
|
|
isTokenDetectionInactiveOnMainnet ||
|
2022-05-09 19:47:06 +02:00
|
|
|
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-08-10 03:26:25 +02:00
|
|
|
{isTokenDetectionAvailable && (
|
2021-09-27 19:42:51 +02:00
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
className="import-token-link__link"
|
2022-08-16 17:25:30 +02:00
|
|
|
data-testid="refresh-list-button"
|
2021-09-27 19:42:51 +02:00
|
|
|
type="link"
|
|
|
|
onClick={() => detectNewTokens()}
|
|
|
|
>
|
|
|
|
{t('refreshList')}
|
|
|
|
</Button>
|
|
|
|
{t('or')}
|
|
|
|
</>
|
|
|
|
)}
|
2021-09-10 20:03:42 +02:00
|
|
|
<Button
|
|
|
|
className="import-token-link__link"
|
2022-08-16 17:25:30 +02:00
|
|
|
data-testid="import-token-button"
|
2021-09-10 20:03:42 +02:00
|
|
|
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({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.TokenImportButtonClicked,
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
2022-03-14 19:12:38 +01:00
|
|
|
properties: {
|
2022-08-16 18:39:23 +02:00
|
|
|
location: 'Home',
|
2022-03-14 19:12:38 +01:00
|
|
|
},
|
|
|
|
});
|
2020-06-12 18:22:00 +02:00
|
|
|
}}
|
|
|
|
>
|
2022-08-10 03:26:25 +02:00
|
|
|
{isTokenDetectionAvailable
|
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
|
|
|
}
|