1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 22:24:27 +01:00
metamask-extension/ui/components/app/asset-list/detected-tokens-link/detected-tokens-link.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { useContext } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Box from '../../../ui/box/box';
import Button from '../../../ui/button';
import { useI18nContext } from '../../../../hooks/useI18nContext';
2023-04-27 16:28:08 +02:00
import {
getCurrentChainId,
getDetectedTokensInCurrentNetwork,
} from '../../../../selectors';
import { MetaMetricsContext } from '../../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
MetaMetricsTokenEventSource,
} from '../../../../../shared/constants/metametrics';
2022-05-09 19:47:06 +02:00
const DetectedTokensLink = ({ className = '', setShowDetectedTokens }) => {
const t = useI18nContext();
const trackEvent = useContext(MetaMetricsContext);
const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork);
const detectedTokensDetails = detectedTokens.map(
({ address, symbol }) => `${symbol} - ${address}`,
);
2023-04-27 16:28:08 +02:00
const chainId = useSelector(getCurrentChainId);
const onClick = () => {
setShowDetectedTokens(true);
trackEvent({
event: MetaMetricsEventName.TokenImportClicked,
category: MetaMetricsEventCategory.Wallet,
properties: {
2023-04-27 16:28:08 +02:00
source_connection_method: MetaMetricsTokenEventSource.Detected,
chain_id: chainId,
tokens: detectedTokensDetails,
},
});
};
return (
<Box
className={classNames('detected-tokens-link', className)}
marginTop={1}
>
<Button
type="link"
className="detected-tokens-link__link"
onClick={onClick}
>
{detectedTokens.length === 1
? t('numberOfNewTokensDetectedSingular')
: t('numberOfNewTokensDetectedPlural', [detectedTokens.length])}
</Button>
</Box>
);
};
DetectedTokensLink.propTypes = {
2022-05-09 19:47:06 +02:00
setShowDetectedTokens: PropTypes.func.isRequired,
className: PropTypes.string,
};
export default DetectedTokensLink;