import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SendRowWrapper from '../send-row-wrapper';
import Identicon from '../../../../components/ui/identicon/identicon.component';
import TokenBalance from '../../../../components/ui/token-balance';
import UserPreferencedCurrencyDisplay from '../../../../components/app/user-preferenced-currency-display';
import { ERC20, PRIMARY } from '../../../../helpers/constants/common';
import { ASSET_TYPES } from '../../../../ducks/send';
export default class SendAssetRow extends Component {
static propTypes = {
tokens: PropTypes.arrayOf(
PropTypes.shape({
address: PropTypes.string,
decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
symbol: PropTypes.string,
}),
).isRequired,
accounts: PropTypes.object.isRequired,
assetImages: PropTypes.object,
selectedAddress: PropTypes.string.isRequired,
sendAssetAddress: PropTypes.string,
updateSendAsset: PropTypes.func.isRequired,
nativeCurrency: PropTypes.string,
nativeCurrencyImage: PropTypes.string,
};
static contextTypes = {
t: PropTypes.func,
metricsEvent: PropTypes.func,
};
state = {
isShowingDropdown: false,
sendableTokens: [],
};
async componentDidMount() {
const sendableTokens = this.props.tokens.filter((token) => !token.isERC721);
this.setState({ sendableTokens });
}
openDropdown = () => this.setState({ isShowingDropdown: true });
closeDropdown = () => this.setState({ isShowingDropdown: false });
selectToken = (type, token) => {
this.setState(
{
isShowingDropdown: false,
},
() => {
this.context.metricsEvent({
eventOpts: {
category: 'Transactions',
action: 'Send Screen',
name: 'User clicks "Assets" dropdown',
},
customVariables: {
assetSelected: token ? ERC20 : this.props.nativeCurrency,
},
});
this.props.updateSendAsset({
type,
details: type === ASSET_TYPES.NATIVE ? null : token,
});
},
);
};
render() {
const { t } = this.context;
return (