mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
1304ec7af5
We want to convert NetworkController to TypeScript in order to be able to compare differences in the controller between in this repo and the core repo. To do this, however, we need to convert the dependencies of the controller to TypeScript. As a part of this effort, this commit converts `shared/constants/metametrics` to TypeScript. Note that simple objects have been largely replaced with enums. There are some cases where I even split up some of these objects into multiple enums. Co-authored-by: Mark Stacey <markjstacey@gmail.com>
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import React, { useContext } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import classNames from 'classnames';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import { getDetectedTokensInCurrentNetwork } from '../../../selectors';
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
import {
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventName,
|
|
MetaMetricsTokenEventSource,
|
|
} from '../../../../shared/constants/metametrics';
|
|
import { BannerAlert } from '../../component-library';
|
|
|
|
export const DetectedTokensBanner = ({
|
|
className,
|
|
actionButtonOnClick,
|
|
...props
|
|
}) => {
|
|
const t = useI18nContext();
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork);
|
|
const detectedTokensDetails = detectedTokens.map(
|
|
({ address, symbol }) => `${symbol} - ${address}`,
|
|
);
|
|
|
|
const handleOnClick = () => {
|
|
actionButtonOnClick();
|
|
trackEvent({
|
|
event: MetaMetricsEventName.TokenImportClicked,
|
|
category: MetaMetricsEventCategory.Wallet,
|
|
properties: {
|
|
source: MetaMetricsTokenEventSource.Detected,
|
|
tokens: detectedTokensDetails,
|
|
},
|
|
});
|
|
};
|
|
return (
|
|
<BannerAlert
|
|
className={classNames('multichain-detected-token-banner', className)}
|
|
actionButtonLabel={t('importTokensCamelCase')}
|
|
actionButtonOnClick={handleOnClick}
|
|
data-testid="detected-token-banner"
|
|
{...props}
|
|
>
|
|
{detectedTokens.length === 1
|
|
? t('numberOfNewTokensDetectedSingular')
|
|
: t('numberOfNewTokensDetectedPlural', [detectedTokens.length])}
|
|
</BannerAlert>
|
|
);
|
|
};
|
|
|
|
DetectedTokensBanner.propTypes = {
|
|
/**
|
|
* Handler to be passed to the DetectedTokenBanner component
|
|
*/
|
|
actionButtonOnClick: PropTypes.func.isRequired,
|
|
/**
|
|
* An additional className to the DetectedTokenBanner component
|
|
*/
|
|
className: PropTypes.string,
|
|
};
|