import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import TokenBalance from '../token-balance' import Identicon from '../identicon' import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display' import { PRIMARY, SECONDARY } from '../../constants/common' import { formatBalance } from '../../util' export default class Balance extends PureComponent { static propTypes = { account: PropTypes.object, assetImages: PropTypes.object, nativeCurrency: PropTypes.string, needsParse: PropTypes.bool, network: PropTypes.string, showFiat: PropTypes.bool, token: PropTypes.object, } static defaultProps = { needsParse: true, showFiat: true, } renderBalance () { const { account, nativeCurrency, needsParse, showFiat } = this.props const balanceValue = account && account.balance const formattedBalance = balanceValue ? formatBalance(balanceValue, 6, needsParse, nativeCurrency) : '...' if (formattedBalance === 'None' || formattedBalance === '...') { return (
{ formattedBalance }
) } return (
{ showFiat && ( ) }
) } renderTokenBalance () { const { token } = this.props return (
) } render () { const { token, network, assetImages } = this.props const address = token && token.address const image = assetImages && address ? assetImages[token.address] : undefined return (
{ token ? this.renderTokenBalance() : this.renderBalance() }
) } }