You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.0 KiB
158 lines
4.0 KiB
4 years ago
|
import React, { useMemo } 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 { useMetricEvent } from '../../../hooks/useMetricEvent';
|
||
|
import { updateSendToken } from '../../../store/actions';
|
||
|
import { SEND_ROUTE } from '../../../helpers/constants/routes';
|
||
|
import { SEVERITIES } from '../../../helpers/constants/design-system';
|
||
5 years ago
|
|
||
5 years ago
|
const AssetListItem = ({
|
||
|
className,
|
||
|
'data-testid': dataTestId,
|
||
|
iconClassName,
|
||
|
onClick,
|
||
|
tokenAddress,
|
||
5 years ago
|
tokenSymbol,
|
||
|
tokenDecimals,
|
||
5 years ago
|
tokenImage,
|
||
|
warning,
|
||
5 years ago
|
primary,
|
||
|
secondary,
|
||
4 years ago
|
identiconBorder,
|
||
5 years ago
|
}) => {
|
||
4 years ago
|
const t = useI18nContext();
|
||
|
const dispatch = useDispatch();
|
||
|
const history = useHistory();
|
||
5 years ago
|
const sendTokenEvent = useMetricEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Home',
|
||
|
name: 'Clicked Send: Token',
|
||
|
},
|
||
4 years ago
|
});
|
||
4 years ago
|
const titleIcon = warning ? (
|
||
|
<Tooltip
|
||
|
wrapperClassName="asset-list-item__warning-tooltip"
|
||
|
interactive
|
||
|
position="bottom"
|
||
|
html={warning}
|
||
|
>
|
||
4 years ago
|
<InfoIcon severity={SEVERITIES.WARNING} />
|
||
4 years ago
|
</Tooltip>
|
||
4 years ago
|
) : null;
|
||
5 years ago
|
|
||
4 years ago
|
const midContent = warning ? (
|
||
|
<>
|
||
4 years ago
|
<InfoIcon severity={SEVERITIES.WARNING} />
|
||
4 years ago
|
<div className="asset-list-item__warning">{warning}</div>
|
||
|
</>
|
||
4 years ago
|
) : null;
|
||
5 years ago
|
|
||
5 years ago
|
const sendTokenButton = useMemo(() => {
|
||
4 years ago
|
if (tokenAddress === null || tokenAddress === undefined) {
|
||
4 years ago
|
return null;
|
||
5 years ago
|
}
|
||
|
return (
|
||
|
<Button
|
||
|
type="link"
|
||
|
className="asset-list-item__send-token-button"
|
||
|
onClick={(e) => {
|
||
4 years ago
|
e.stopPropagation();
|
||
|
sendTokenEvent();
|
||
4 years ago
|
dispatch(
|
||
|
updateSendToken({
|
||
|
address: tokenAddress,
|
||
|
decimals: tokenDecimals,
|
||
|
symbol: tokenSymbol,
|
||
|
}),
|
||
4 years ago
|
);
|
||
|
history.push(SEND_ROUTE);
|
||
5 years ago
|
}}
|
||
|
>
|
||
|
{t('sendSpecifiedTokens', [tokenSymbol])}
|
||
|
</Button>
|
||
4 years ago
|
);
|
||
5 years ago
|
}, [
|
||
|
tokenSymbol,
|
||
|
sendTokenEvent,
|
||
|
tokenAddress,
|
||
|
tokenDecimals,
|
||
|
history,
|
||
|
t,
|
||
|
dispatch,
|
||
4 years ago
|
]);
|
||
5 years ago
|
|
||
5 years ago
|
return (
|
||
5 years ago
|
<ListItem
|
||
|
className={classnames('asset-list-item', className)}
|
||
5 years ago
|
data-testid={dataTestId}
|
||
4 years ago
|
title={
|
||
4 years ago
|
<button
|
||
|
className="asset-list-item__token-button"
|
||
|
onClick={onClick}
|
||
4 years ago
|
title={`${primary} ${tokenSymbol}`}
|
||
4 years ago
|
>
|
||
|
<h2>
|
||
|
<span className="asset-list-item__token-value">{primary}</span>
|
||
|
<span className="asset-list-item__token-symbol">{tokenSymbol}</span>
|
||
|
</h2>
|
||
|
</button>
|
||
4 years ago
|
}
|
||
5 years ago
|
titleIcon={titleIcon}
|
||
5 years ago
|
subtitle={<h3 title={secondary}>{secondary}</h3>}
|
||
5 years ago
|
onClick={onClick}
|
||
4 years ago
|
icon={
|
||
5 years ago
|
<Identicon
|
||
|
className={iconClassName}
|
||
|
diameter={32}
|
||
|
address={tokenAddress}
|
||
|
image={tokenImage}
|
||
4 years ago
|
alt={`${primary} ${tokenSymbol}`}
|
||
4 years ago
|
imageBorder={identiconBorder}
|
||
5 years ago
|
/>
|
||
4 years ago
|
}
|
||
5 years ago
|
midContent={midContent}
|
||
4 years ago
|
rightContent={
|
||
5 years ago
|
<>
|
||
|
<i className="fas fa-chevron-right asset-list-item__chevron-right" />
|
||
|
{sendTokenButton}
|
||
|
</>
|
||
4 years ago
|
}
|
||
5 years ago
|
/>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
AssetListItem.propTypes = {
|
||
4 years ago
|
'className': PropTypes.string,
|
||
5 years ago
|
'data-testid': PropTypes.string,
|
||
4 years ago
|
'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,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
AssetListItem.defaultProps = {
|
||
4 years ago
|
'className': undefined,
|
||
5 years ago
|
'data-testid': undefined,
|
||
4 years ago
|
'iconClassName': undefined,
|
||
|
'tokenAddress': undefined,
|
||
|
'tokenImage': undefined,
|
||
|
'warning': undefined,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
export default AssetListItem;
|