// Copyright 2015, 2016 Ethcore (UK) Ltd. // This file is part of Parity. // Parity is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Parity is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Parity. If not, see . import React, { Component, PropTypes } from 'react'; import { IdentityIcon, IdentityName } from '../../../../ui'; import AccountLink from './AccountLink'; import styles from './Account.css'; export default class Account extends Component { static propTypes = { className: PropTypes.string, address: PropTypes.string.isRequired, isTest: PropTypes.bool.isRequired, balance: PropTypes.object // eth BigNumber, not required since it mght take time to fetch }; state = { balanceDisplay: '?' }; componentWillMount () { this.updateBalanceDisplay(this.props.balance); } componentWillReceiveProps (nextProps) { if (nextProps.balance === this.props.balance) { return; } this.updateBalanceDisplay(nextProps.balance); } updateBalanceDisplay (balance) { this.setState({ balanceDisplay: balance ? balance.div(1e18).toFormat(3) : '?' }); } render () { const { address, isTest, className } = this.props; return (
{ this.renderName() } { this.renderBalance() }
); } renderBalance () { const { balanceDisplay } = this.state; return ( { balanceDisplay } ETH ); } renderName () { const { address, isTest } = this.props; const name = ; if (!name) { return ( [{ this.shortAddress(address) }] ); } return ( { name } [{ this.tinyAddress(address) }] ); } tinyAddress () { const { address } = this.props; const len = address.length; return address.slice(2, 4) + '..' + address.slice(len - 2); } shortAddress () { const { address } = this.props; const len = address.length; return address.slice(2, 8) + '..' + address.slice(len - 7); } }