import { Token } from 'config/data'; import React from 'react'; import { TokenBalance } from 'selectors/wallet'; import translate from 'translations'; import AddCustomTokenForm from './AddCustomTokenForm'; import './index.scss'; import TokenRow from './TokenRow'; interface Props { tokens: TokenBalance[]; onAddCustomToken(token: Token): any; onRemoveCustomToken(symbol: string): any; } interface State { showAllTokens: boolean; showCustomTokenForm: boolean; } export default class TokenBalances extends React.Component { public state = { showAllTokens: false, showCustomTokenForm: false }; public render() { const { tokens } = this.props; const shownTokens = tokens.filter( token => !token.balance.eqn(0) || token.custom || this.state.showAllTokens ); return (
{translate('sidebar_TokenBal')}
{shownTokens.map(token => ( ))}
{' '}
{this.state.showCustomTokenForm && (
)}
); } public toggleShowAllTokens = () => { this.setState(state => { return { showAllTokens: !state.showAllTokens }; }); }; public toggleShowCustomTokenForm = () => { this.setState(state => { return { showCustomTokenForm: !state.showCustomTokenForm }; }); }; public addCustomToken = (token: Token) => { this.props.onAddCustomToken(token); this.setState({ showCustomTokenForm: false }); }; }