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