2018-06-01 20:06:27 +00:00
|
|
|
import web3 from 'Embark/web3'
|
2018-05-18 19:17:46 +00:00
|
|
|
import React from 'react';
|
2018-06-01 20:06:27 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { Nav, MenuItem, NavDropdown } from 'react-bootstrap';
|
2018-05-18 19:17:46 +00:00
|
|
|
import Blockies from 'react-blockies';
|
2018-06-01 20:06:27 +00:00
|
|
|
import { string, bool, func, arrayOf, shape } from 'prop-types';
|
|
|
|
import { getAccounts, getDefaultAccount, accountsIsLoading, actions as accountActions } from '../reducers/accounts';
|
2018-05-18 19:17:46 +00:00
|
|
|
import './accountlist.css';
|
|
|
|
|
2018-06-01 20:06:27 +00:00
|
|
|
const AccList = ({
|
|
|
|
accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown,
|
|
|
|
}) => (
|
|
|
|
<React.Fragment>
|
|
|
|
{!isLoading ?
|
|
|
|
<div className="accounts">
|
|
|
|
<div className="selectedIdenticon">
|
|
|
|
<Blockies seed={defaultAccount} />
|
|
|
|
</div>
|
|
|
|
<div className="accountList">
|
|
|
|
<Nav>
|
|
|
|
<NavDropdown key={1} title={defaultAccount} id="basic-nav-dropdown" className={classNameNavDropdown}>
|
|
|
|
{accounts.map(account => (
|
|
|
|
<MenuItem key={account.address} onClick={() => changeAccount(account.address)}>
|
|
|
|
<div className="account">
|
|
|
|
<div className="accountIdenticon">
|
|
|
|
<Blockies seed={account.address} />
|
2018-05-18 19:17:46 +00:00
|
|
|
</div>
|
2018-06-01 20:06:27 +00:00
|
|
|
<div className="accountHexString">
|
|
|
|
{account.address}
|
2018-05-18 19:17:46 +00:00
|
|
|
</div>
|
2018-06-01 20:06:27 +00:00
|
|
|
<div className="accountBalance">
|
|
|
|
Ξ {account.balance / (10 ** 18)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</NavDropdown>
|
|
|
|
</Nav>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
: <div>Loading...</div>}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
|
|
|
|
AccList.propTypes = {
|
|
|
|
accounts: arrayOf(shape({ address: string, balance: string })).isRequired,
|
|
|
|
defaultAccount: string,
|
|
|
|
changeAccount: func.isRequired,
|
|
|
|
isLoading: bool.isRequired,
|
|
|
|
classNameNavDropdown: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
accounts: getAccounts(state),
|
|
|
|
defaultAccount: getDefaultAccount(state),
|
|
|
|
isLoading: accountsIsLoading(state),
|
|
|
|
});
|
2018-05-18 19:17:46 +00:00
|
|
|
|
2018-06-01 20:06:27 +00:00
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
changeAccount(address) {
|
|
|
|
web3.eth.defaultAccount = address;
|
|
|
|
dispatch(accountActions.updateDefaultAccount(address));
|
|
|
|
},
|
|
|
|
});
|
2018-05-18 19:17:46 +00:00
|
|
|
|
2018-06-01 20:06:27 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AccList);
|