1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/components/multichain/import-token-link/import-token-link.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-03-23 11:08:33 +01:00
import React, { useContext } from 'react';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { ButtonLink, IconName, Box } from '../../component-library';
2023-03-23 11:08:33 +01:00
import {
AlignItems,
Display,
2023-03-23 11:08:33 +01:00
Size,
} from '../../../helpers/constants/design-system';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { IMPORT_TOKEN_ROUTE } from '../../../helpers/constants/routes';
import { detectNewTokens } from '../../../store/actions';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
2023-03-23 11:08:33 +01:00
import {
getIsTokenDetectionSupported,
getIsTokenDetectionInactiveOnMainnet,
} from '../../../selectors';
export const ImportTokenLink = ({ className, ...props }) => {
2023-03-23 11:08:33 +01:00
const trackEvent = useContext(MetaMetricsContext);
const t = useI18nContext();
const history = useHistory();
const isTokenDetectionSupported = useSelector(getIsTokenDetectionSupported);
const isTokenDetectionInactiveOnMainnet = useSelector(
getIsTokenDetectionInactiveOnMainnet,
);
const isTokenDetectionAvailable =
isTokenDetectionSupported ||
isTokenDetectionInactiveOnMainnet ||
Boolean(process.env.IN_TEST);
return (
<Box
className={classnames('multichain-import-token-link', className)}
{...props}
>
<Box display={Display.Flex} alignItems={AlignItems.center}>
2023-03-23 11:08:33 +01:00
<ButtonLink
size={Size.MD}
data-testid="import-token-button"
startIconName={IconName.Add}
2023-03-23 11:08:33 +01:00
onClick={() => {
history.push(IMPORT_TOKEN_ROUTE);
trackEvent({
event: MetaMetricsEventName.TokenImportButtonClicked,
category: MetaMetricsEventCategory.Navigation,
2023-03-23 11:08:33 +01:00
properties: {
location: 'Home',
},
});
}}
>
{isTokenDetectionAvailable
? t('importTokensCamelCase')
: t('importTokensCamelCase').charAt(0).toUpperCase() +
t('importTokensCamelCase').slice(1)}
</ButtonLink>
</Box>
<Box display={Display.Flex} alignItems={AlignItems.center} paddingTop={2}>
2023-03-23 11:08:33 +01:00
<ButtonLink
size={Size.MD}
startIconName={IconName.Refresh}
2023-03-23 11:08:33 +01:00
data-testid="refresh-list-button"
onClick={() => detectNewTokens()}
>
{t('refreshList')}
</ButtonLink>
</Box>
</Box>
);
};
ImportTokenLink.propTypes = {
2023-03-23 11:08:33 +01:00
/**
* An additional className to apply to the TokenList.
*/
className: PropTypes.string,
};