Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Display 0x00..00 as null #3950

Merged
merged 2 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion js/src/ui/Form/InputAddress/inputAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
Expand Down Expand Up @@ -62,6 +63,7 @@ class InputAddress extends Component {
classes.push(!icon ? styles.inputEmpty : styles.input);

const containerClasses = [ styles.container ];
const nullName = new BigNumber(value).eq(0) ? 'null' : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer isNull or isZero here.


if (small) {
containerClasses.push(styles.small);
Expand All @@ -82,7 +84,7 @@ class InputAddress extends Component {
value={
text && account
? account.name
: value
: (nullName || value)
} />
{ icon }
</div>
Expand Down
2 changes: 2 additions & 0 deletions js/src/ui/Icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import AddIcon from 'material-ui/svg-icons/content/add';
import CancelIcon from 'material-ui/svg-icons/content/clear';
import ContractIcon from 'material-ui/svg-icons/action/code';
import DoneIcon from 'material-ui/svg-icons/action/done-all';
import PrevIcon from 'material-ui/svg-icons/navigation/arrow-back';
import NextIcon from 'material-ui/svg-icons/navigation/arrow-forward';
Expand All @@ -24,6 +25,7 @@ import SnoozeIcon from 'material-ui/svg-icons/av/snooze';
export {
AddIcon,
CancelIcon,
ContractIcon,
DoneIcon,
PrevIcon,
NextIcon,
Expand Down
18 changes: 15 additions & 3 deletions js/src/ui/IdentityIcon/identityIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ContractIcon from 'material-ui/svg-icons/action/code';

import { createIdentityImg } from '~/api/util/identity';
import ContractIcon from '../Icons';

import styles from './identityIcon.css';

Expand Down Expand Up @@ -108,9 +109,20 @@ class IdentityIcon extends Component {
<ContractIcon
className={ classes }
style={ {
width: size,
background: '#eee',
height: size,
background: '#eee'
width: size
} } />
);
} else if (new BigNumber(address).eq(0)) {
return (
<div
Copy link
Contributor

@derhuerst derhuerst Dec 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black-hole

I'd consider something more helpful here, e.g. material-ui/svg-icons/content/clear. cc @gavofyork #3908

clear

className={ classes }
style={ {
background: '#333',
display: 'inline-block',
height: size,
width: size
} } />
);
}
Expand Down
27 changes: 17 additions & 10 deletions js/src/ui/IdentityName/identityName.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
Expand All @@ -24,35 +25,41 @@ const defaultName = 'UNNAMED';

class IdentityName extends Component {
static propTypes = {
className: PropTypes.string,
address: PropTypes.string,
accountsInfo: PropTypes.object,
tokens: PropTypes.object,
address: PropTypes.string,
className: PropTypes.string,
empty: PropTypes.bool,
name: PropTypes.string,
shorten: PropTypes.bool,
unknown: PropTypes.bool,
name: PropTypes.string
tokens: PropTypes.object,
unknown: PropTypes.bool
}

render () {
const { address, accountsInfo, tokens, empty, name, shorten, unknown, className } = this.props;
const { address, accountsInfo, className, empty, name, shorten, tokens, unknown } = this.props;
const account = accountsInfo[address] || tokens[address];

if (!account && empty) {
return null;
}

const addressFallback = shorten ? (<ShortenedHash data={ address } />) : address;
const nullName = new BigNumber(address).eq(0) ? 'null' : null;
const addressFallback = nullName || (shorten ? (<ShortenedHash data={ address } />) : address);
const fallback = unknown ? defaultName : addressFallback;
const isUuid = account && account.name === account.uuid;
const displayName = (name && name.toUpperCase().trim()) ||
(account && !isUuid
? account.name.toUpperCase().trim()
: fallback);
? account.name.toUpperCase().trim()
: fallback
);

return (
<span className={ className }>
{ displayName && displayName.length ? displayName : fallback }
{
displayName && displayName.length
? displayName
: fallback
}
</span>
);
}
Expand Down
7 changes: 6 additions & 1 deletion js/src/ui/IdentityName/identityName.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import IdentityName from './identityName';
const ADDR_A = '0x123456789abcdef0123456789A';
const ADDR_B = '0x123456789abcdef0123456789B';
const ADDR_C = '0x123456789abcdef0123456789C';
const ADDR_NULL = '0x0000000000000000000000000000000000000000';
const STORE = {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
Expand Down Expand Up @@ -52,7 +53,7 @@ function render (props) {
describe('ui/IdentityName', () => {
describe('rendering', () => {
it('renders defaults', () => {
expect(render()).to.be.ok;
expect(render({ address: ADDR_A })).to.be.ok;
});

describe('account not found', () => {
Expand All @@ -71,6 +72,10 @@ describe('ui/IdentityName', () => {
it('renders unknown with flag', () => {
expect(render({ address: ADDR_C, unknown: true }).text()).to.equal('UNNAMED');
});

it('renders 0x000...000 as null', () => {
expect(render({ address: ADDR_NULL }).text()).to.equal('null');
});
});
});
});