Trim spaces from InputAddress (#4126)

* Trim spaces for addresses

* onSubmit has only value, not event

* onSubmit (again)

* Length check on trimmed value
This commit is contained in:
Jaco Greeff 2017-01-12 14:25:41 +01:00 committed by GitHub
parent 81beec1352
commit 0de34774b1

View File

@ -57,7 +57,7 @@ class InputAddress extends Component {
render () { render () {
const { accountsInfo, allowCopy, className, disabled, error, focused, hint } = this.props; const { accountsInfo, allowCopy, className, disabled, error, focused, hint } = this.props;
const { hideUnderline, label, onClick, onFocus, onSubmit, readOnly, small } = this.props; const { hideUnderline, label, onClick, onFocus, readOnly, small } = this.props;
const { tabIndex, text, tokens, value } = this.props; const { tabIndex, text, tokens, value } = this.props;
const account = value && (accountsInfo[value] || tokens[value]); const account = value && (accountsInfo[value] || tokens[value]);
@ -90,10 +90,10 @@ class InputAddress extends Component {
hideUnderline={ hideUnderline } hideUnderline={ hideUnderline }
hint={ hint } hint={ hint }
label={ label } label={ label }
onChange={ this.handleInputChange } onChange={ this.onChange }
onClick={ onClick } onClick={ onClick }
onFocus={ onFocus } onFocus={ onFocus }
onSubmit={ onSubmit } onSubmit={ this.onSubmit }
readOnly={ readOnly } readOnly={ readOnly }
tabIndex={ tabIndex } tabIndex={ tabIndex }
value={ value={
@ -132,22 +132,34 @@ class InputAddress extends Component {
return ( return (
<div className={ classes.join(' ') }> <div className={ classes.join(' ') }>
<IdentityIcon <IdentityIcon
inline center address={ value }
address={ value } /> center
inline />
</div> </div>
); );
} }
handleInputChange = (event, value) => { onChange = (event, _value) => {
const isEmpty = (value.length === 0); let address = _value.trim();
const isEmpty = (address.length === 0);
this.setState({ isEmpty }); this.setState({ isEmpty });
if (!/^0x/.test(value) && util.isAddressValid(`0x${value}`)) { if (this.props.onChange) {
return this.props.onChange(event, `0x${value}`); if (!/^0x/.test(address) && util.isAddressValid(`0x${address}`)) {
} address = `0x${address}`;
}
this.props.onChange(event, value); this.props.onChange(event, address);
}
}
onSubmit = (_value) => {
const address = _value.trim();
if (this.props.onSubmit) {
this.props.onSubmit(address);
}
} }
} }