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

Commit

Permalink
Trim spaces from InputAddress (#4126)
Browse files Browse the repository at this point in the history
* Trim spaces for addresses

* onSubmit has only value, not event

* onSubmit (again)

* Length check on trimmed value
  • Loading branch information
jacogr authored and arkpar committed Jan 12, 2017
1 parent fe70434 commit 13219f2
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions js/src/ui/Form/InputAddress/inputAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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]);
Expand Down Expand Up @@ -91,10 +91,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={
Expand Down Expand Up @@ -133,22 +133,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, address);
}
}

this.props.onChange(event, value);
onSubmit = (_value) => {
const address = _value.trim();

if (this.props.onSubmit) {
this.props.onSubmit(address);
}
}
}

Expand Down

0 comments on commit 13219f2

Please sign in to comment.