Display Wallet Owners in Accounts list (#3741)

This commit is contained in:
Nicolas Gotchac 2016-12-08 15:53:46 +01:00 committed by Jaco Greeff
parent 715761a714
commit d38da1f3b4
4 changed files with 67 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import styles from './list.css';
export default class List extends Component { export default class List extends Component {
static propTypes = { static propTypes = {
accounts: PropTypes.object, accounts: PropTypes.object,
walletsOwners: PropTypes.object,
balances: PropTypes.object, balances: PropTypes.object,
link: PropTypes.string, link: PropTypes.string,
search: PropTypes.array, search: PropTypes.array,
@ -42,7 +43,7 @@ export default class List extends Component {
} }
renderAccounts () { renderAccounts () {
const { accounts, balances, link, empty, handleAddSearchToken } = this.props; const { accounts, balances, link, empty, handleAddSearchToken, walletsOwners } = this.props;
if (empty) { if (empty) {
return ( return (
@ -60,6 +61,8 @@ export default class List extends Component {
const account = accounts[address] || {}; const account = accounts[address] || {};
const balance = balances[address] || {}; const balance = balances[address] || {};
const owners = walletsOwners && walletsOwners[address] || null;
return ( return (
<div <div
className={ styles.item } className={ styles.item }
@ -68,6 +71,7 @@ export default class List extends Component {
link={ link } link={ link }
account={ account } account={ account }
balance={ balance } balance={ balance }
owners={ owners }
handleAddSearchToken={ handleAddSearchToken } /> handleAddSearchToken={ handleAddSearchToken } />
</div> </div>
); );

View File

@ -17,8 +17,12 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router'; import { Link } from 'react-router';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import ReactTooltip from 'react-tooltip';
import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags, Input } from '~/ui'; import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags, Input } from '~/ui';
import { nullableProptype } from '~/util/proptypes';
import styles from '../accounts.css';
export default class Summary extends Component { export default class Summary extends Component {
static contextTypes = { static contextTypes = {
@ -31,7 +35,8 @@ export default class Summary extends Component {
link: PropTypes.string, link: PropTypes.string,
name: PropTypes.string, name: PropTypes.string,
noLink: PropTypes.bool, noLink: PropTypes.bool,
handleAddSearchToken: PropTypes.func handleAddSearchToken: PropTypes.func,
owners: nullableProptype(PropTypes.array)
}; };
static defaultProps = { static defaultProps = {
@ -100,11 +105,41 @@ export default class Summary extends Component {
title={ this.renderLink() } title={ this.renderLink() }
byline={ addressComponent } /> byline={ addressComponent } />
{ this.renderOwners() }
{ this.renderBalance() } { this.renderBalance() }
</Container> </Container>
); );
} }
renderOwners () {
const { owners } = this.props;
if (!owners || owners.length === 0) {
return null;
}
return (
<div className={ styles.owners }>
{
owners.map((owner) => (
<div key={ owner.address }>
<div
data-tip
data-for={ `owner_${owner.address}` }
data-effect='solid'
>
<IdentityIcon address={ owner.address } button />
</div>
<ReactTooltip id={ `owner_${owner.address}` }>
<strong>{ owner.name } </strong><small> (owner)</small>
</ReactTooltip>
</div>
))
}
</div>
);
}
renderLink () { renderLink () {
const { link, noLink, account, name } = this.props; const { link, noLink, account, name } = this.props;

View File

@ -22,6 +22,12 @@
left: 7em; left: 7em;
} }
.owners {
margin-top: 1em;
display: flex;
margin-bottom: -0.5em;
}
.toolbar { .toolbar {
position: relative; position: relative;
} }

View File

@ -37,6 +37,7 @@ class Accounts extends Component {
accounts: PropTypes.object.isRequired, accounts: PropTypes.object.isRequired,
hasAccounts: PropTypes.bool.isRequired, hasAccounts: PropTypes.bool.isRequired,
wallets: PropTypes.object.isRequired, wallets: PropTypes.object.isRequired,
walletsOwners: PropTypes.object.isRequired,
hasWallets: PropTypes.bool.isRequired, hasWallets: PropTypes.bool.isRequired,
balances: PropTypes.object balances: PropTypes.object
@ -137,7 +138,7 @@ class Accounts extends Component {
return this.renderLoading(this.props.wallets); return this.renderLoading(this.props.wallets);
} }
const { wallets, hasWallets, balances } = this.props; const { wallets, hasWallets, balances, walletsOwners } = this.props;
const { searchValues, sortOrder } = this.state; const { searchValues, sortOrder } = this.state;
if (!wallets || Object.keys(wallets).length === 0) { if (!wallets || Object.keys(wallets).length === 0) {
@ -153,6 +154,7 @@ class Accounts extends Component {
empty={ !hasWallets } empty={ !hasWallets }
order={ sortOrder } order={ sortOrder }
handleAddSearchToken={ this.onAddSearchToken } handleAddSearchToken={ this.onAddSearchToken }
walletsOwners={ walletsOwners }
/> />
); );
} }
@ -285,13 +287,29 @@ class Accounts extends Component {
} }
function mapStateToProps (state) { function mapStateToProps (state) {
const { accounts, hasAccounts, wallets, hasWallets } = state.personal; const { accounts, hasAccounts, wallets, hasWallets, accountsInfo } = state.personal;
const { balances } = state.balances; const { balances } = state.balances;
const walletsInfo = state.wallet.wallets;
const walletsOwners = Object
.keys(walletsInfo)
.map((wallet) => ({
owners: walletsInfo[wallet].owners.map((owner) => ({
address: owner,
name: accountsInfo[owner] && accountsInfo[owner].name || owner
})),
address: wallet
}))
.reduce((walletsOwners, wallet) => {
walletsOwners[wallet.address] = wallet.owners;
return walletsOwners;
}, {});
return { return {
accounts, accounts,
hasAccounts, hasAccounts,
wallets, wallets,
walletsOwners,
hasWallets, hasWallets,
balances balances
}; };