import React, { useMemo, useContext } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import Identicon from '../../ui/identicon';
import ListItem from '../../ui/list-item';
import Tooltip from '../../ui/tooltip';
import InfoIcon from '../../ui/icon/info-icon.component';
import Button from '../../ui/button';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { ASSET_TYPES, updateSendAsset } from '../../../ducks/send';
import { SEND_ROUTE } from '../../../helpers/constants/routes';
import { SEVERITIES } from '../../../helpers/constants/design-system';
import { INVALID_ASSET_TYPE } from '../../../helpers/constants/error-keys';
import { MetaMetricsContext } from '../../../contexts/metametrics.new';
const AssetListItem = ({
className,
'data-testid': dataTestId,
iconClassName,
onClick,
tokenAddress,
tokenSymbol,
tokenDecimals,
tokenImage,
warning,
primary,
secondary,
identiconBorder,
isERC721,
}) => {
const t = useI18nContext();
const dispatch = useDispatch();
const history = useHistory();
const trackEvent = useContext(MetaMetricsContext);
const titleIcon = warning ? (
) : null;
const midContent = warning ? (
<>
{warning}
>
) : null;
const sendTokenButton = useMemo(() => {
if (tokenAddress === null || tokenAddress === undefined) {
return null;
}
return (
);
}, [
tokenSymbol,
trackEvent,
tokenAddress,
tokenDecimals,
history,
t,
dispatch,
]);
return (
{primary}
{tokenSymbol}
}
titleIcon={titleIcon}
subtitle={secondary ? {secondary}
: null}
onClick={onClick}
icon={
}
midContent={midContent}
rightContent={
!isERC721 && (
<>
{sendTokenButton}
>
)
}
/>
);
};
AssetListItem.propTypes = {
className: PropTypes.string,
'data-testid': PropTypes.string,
iconClassName: PropTypes.string,
onClick: PropTypes.func.isRequired,
tokenAddress: PropTypes.string,
tokenSymbol: PropTypes.string,
tokenDecimals: PropTypes.number,
tokenImage: PropTypes.string,
warning: PropTypes.node,
primary: PropTypes.string,
secondary: PropTypes.string,
identiconBorder: PropTypes.bool,
isERC721: PropTypes.bool,
};
AssetListItem.defaultProps = {
className: undefined,
'data-testid': undefined,
iconClassName: undefined,
tokenAddress: undefined,
tokenImage: undefined,
warning: undefined,
};
export default AssetListItem;