Display AccountCard name via IdentityName (#4235)
* Display AccountCard name via IdentityName * Pass name through (catches registry reverse display)
This commit is contained in:
		
							parent
							
								
									f4149cc089
								
							
						
					
					
						commit
						183efe9d19
					
				@ -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
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										104
									
								
								js/src/ui/AccountCard/accountCard.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								js/src/ui/AccountCard/accountCard.spec.js
									
									
									
									
									
										Normal 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;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@ -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,41 +54,51 @@ 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;
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe('account not found', () => {
 | 
				
			||||||
 | 
					    it('renders null with empty', () => {
 | 
				
			||||||
 | 
					      expect(
 | 
				
			||||||
 | 
					        render({ address: ADDR_C, empty: true }).html()
 | 
				
			||||||
 | 
					      ).to.be.null;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe('account not found', () => {
 | 
					    it('renders address without empty', () => {
 | 
				
			||||||
      it('renders null with empty', () => {
 | 
					      expect(
 | 
				
			||||||
        expect(
 | 
					        render({ address: ADDR_C }).text()
 | 
				
			||||||
          render({ address: ADDR_C, empty: true }).html()
 | 
					      ).to.equal(ADDR_C);
 | 
				
			||||||
        ).to.be.null;
 | 
					    });
 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it('renders address without empty', () => {
 | 
					    it('renders short address with shorten', () => {
 | 
				
			||||||
        expect(
 | 
					      expect(
 | 
				
			||||||
          render({ address: ADDR_C }).text()
 | 
					        render({ address: ADDR_C, shorten: true }).find('ShortenedHash').props().data
 | 
				
			||||||
        ).to.equal(ADDR_C);
 | 
					      ).to.equal(ADDR_C);
 | 
				
			||||||
      });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it('renders short address with shorten', () => {
 | 
					    it('renders unknown with flag', () => {
 | 
				
			||||||
        expect(
 | 
					      expect(
 | 
				
			||||||
          render({ address: ADDR_C, shorten: true }).find('ShortenedHash').props().data
 | 
					        render({ address: ADDR_C, unknown: true }).find('FormattedMessage').props().id
 | 
				
			||||||
        ).to.equal(ADDR_C);
 | 
					      ).to.equal('ui.identityName.unnamed');
 | 
				
			||||||
      });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it('renders unknown with flag', () => {
 | 
					    it('renders name when not found and passed', () => {
 | 
				
			||||||
        expect(
 | 
					      expect(
 | 
				
			||||||
          render({ address: ADDR_C, unknown: true }
 | 
					        render({ address: ADDR_C, name: NAME_JIMMY }).text()
 | 
				
			||||||
        ).find('FormattedMessage').props().id).to.equal('ui.identityName.unnamed');
 | 
					      ).to.equal(NAME_JIMMY.toUpperCase());
 | 
				
			||||||
      });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it('renders 0x000...000 as null', () => {
 | 
					    it('renders name when not found, unknown and passed', () => {
 | 
				
			||||||
        expect(
 | 
					      expect(
 | 
				
			||||||
          render({ address: ADDR_NULL }).find('FormattedMessage').props().id
 | 
					        render({ address: ADDR_C, name: NAME_JIMMY, unknown: true }).text()
 | 
				
			||||||
        ).to.equal('ui.identityName.null');
 | 
					      ).to.equal(NAME_JIMMY.toUpperCase());
 | 
				
			||||||
      });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('renders 0x000...000 as null', () => {
 | 
				
			||||||
 | 
					      expect(
 | 
				
			||||||
 | 
					        render({ address: ADDR_NULL }).find('FormattedMessage').props().id
 | 
				
			||||||
 | 
					      ).to.equal('ui.identityName.null');
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user