Display AccountCard name via IdentityName (#4235)

* Display AccountCard name via IdentityName

* Pass name through (catches registry reverse display)
This commit is contained in:
Jaco Greeff 2017-01-23 17:33:03 +01:00 committed by GitHub
parent f4149cc089
commit 183efe9d19
3 changed files with 153 additions and 41 deletions

View File

@ -19,6 +19,7 @@ import ReactDOM from 'react-dom';
import keycode from 'keycode'; import keycode from 'keycode';
import IdentityIcon from '~/ui/IdentityIcon'; import IdentityIcon from '~/ui/IdentityIcon';
import IdentityName from '~/ui/IdentityName';
import Tags from '~/ui/Tags'; import Tags from '~/ui/Tags';
import { fromWei } from '~/api/util/wei'; import { fromWei } from '~/api/util/wei';
@ -41,12 +42,8 @@ export default class AccountCard extends Component {
render () { render () {
const { account } = this.props; const { account } = this.props;
const { copied } = this.state; const { copied } = this.state;
const { address, description, meta = {}, name } = account;
const { address, name, description, meta = {} } = account;
const displayName = (name && name.toUpperCase()) || address;
const { tags = [] } = meta; const { tags = [] } = meta;
const classes = [ styles.account ]; const classes = [ styles.account ];
if (copied) { if (copied) {
@ -65,12 +62,16 @@ export default class AccountCard extends Component {
<IdentityIcon address={ address } /> <IdentityIcon address={ address } />
<div className={ styles.accountInfo }> <div className={ styles.accountInfo }>
<div className={ styles.accountName }> <div className={ styles.accountName }>
<span>{ displayName }</span> <IdentityName
address={ address }
name={ name }
unknown
/>
</div> </div>
{ this.renderTags(tags, address) } { this.renderTags(tags, address) }
{ this.renderDescription(description) } { this.renderDescription(description) }
{ this.renderAddress(displayName, address) } { this.renderAddress(address) }
{ this.renderBalance(address) } { this.renderBalance(address) }
</div> </div>
</div> </div>
@ -89,11 +90,7 @@ export default class AccountCard extends Component {
); );
} }
renderAddress (name, address) { renderAddress (address) {
if (name === address) {
return null;
}
return ( return (
<div className={ styles.addressContainer }> <div className={ styles.addressContainer }>
<span <span

View File

@ -0,0 +1,104 @@
// Copyright 2015, 2016 Parity Technologies (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 <http://www.gnu.org/licenses/>.
import { shallow } from 'enzyme';
import React from 'react';
import sinon from 'sinon';
import AccountCard from './';
const TEST_ADDRESS = '0x1234567890123456789012345678901234567890';
const TEST_NAME = 'Jimmy';
let component;
let onClick;
let onFocus;
function render (props = {}) {
if (!props.account) {
props.account = {
address: TEST_ADDRESS,
description: 'testDescription',
name: TEST_NAME,
meta: {}
};
}
onClick = sinon.stub();
onFocus = sinon.stub();
component = shallow(
<AccountCard
{ ...props }
onClick={ onClick }
onFocus={ onFocus }
/>
);
return component;
}
describe('ui/AccountCard', () => {
beforeEach(() => {
render();
});
it('renders defaults', () => {
expect(component).to.be.ok;
});
describe('components', () => {
describe('IdentityIcon', () => {
let icon;
beforeEach(() => {
icon = component.find('Connect(IdentityIcon)');
});
it('renders the icon', () => {
expect(icon.length).to.equal(1);
});
it('passes the address through', () => {
expect(icon.props().address).to.equal(TEST_ADDRESS);
});
});
describe('IdentityName', () => {
let name;
beforeEach(() => {
name = component.find('Connect(IdentityName)');
});
it('renders the name', () => {
expect(name.length).to.equal(1);
});
it('passes the address through', () => {
expect(name.props().address).to.equal(TEST_ADDRESS);
});
it('passes the name through', () => {
expect(name.props().name).to.equal(TEST_NAME);
});
it('renders unknown (no name)', () => {
expect(name.props().unknown).to.be.true;
});
});
});
});

View File

@ -25,6 +25,7 @@ const ADDR_A = '0x123456789abcdef0123456789A';
const ADDR_B = '0x123456789abcdef0123456789B'; const ADDR_B = '0x123456789abcdef0123456789B';
const ADDR_C = '0x123456789abcdef0123456789C'; const ADDR_C = '0x123456789abcdef0123456789C';
const ADDR_NULL = '0x0000000000000000000000000000000000000000'; const ADDR_NULL = '0x0000000000000000000000000000000000000000';
const NAME_JIMMY = 'Jimmy Test';
const STORE = { const STORE = {
dispatch: sinon.stub(), dispatch: sinon.stub(),
subscribe: sinon.stub(), subscribe: sinon.stub(),
@ -53,7 +54,6 @@ function render (props) {
} }
describe('ui/IdentityName', () => { describe('ui/IdentityName', () => {
describe('rendering', () => {
it('renders defaults', () => { it('renders defaults', () => {
expect(render({ address: ADDR_A })).to.be.ok; expect(render({ address: ADDR_A })).to.be.ok;
}); });
@ -79,8 +79,20 @@ describe('ui/IdentityName', () => {
it('renders unknown with flag', () => { it('renders unknown with flag', () => {
expect( expect(
render({ address: ADDR_C, unknown: true } render({ address: ADDR_C, unknown: true }).find('FormattedMessage').props().id
).find('FormattedMessage').props().id).to.equal('ui.identityName.unnamed'); ).to.equal('ui.identityName.unnamed');
});
it('renders name when not found and passed', () => {
expect(
render({ address: ADDR_C, name: NAME_JIMMY }).text()
).to.equal(NAME_JIMMY.toUpperCase());
});
it('renders name when not found, unknown and passed', () => {
expect(
render({ address: ADDR_C, name: NAME_JIMMY, unknown: true }).text()
).to.equal(NAME_JIMMY.toUpperCase());
}); });
it('renders 0x000...000 as null', () => { it('renders 0x000...000 as null', () => {
@ -90,4 +102,3 @@ describe('ui/IdentityName', () => {
}); });
}); });
}); });
});