From 0de34774b1f9c3c47d7f7ee8146fbca30b4fbdf1 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 12 Jan 2017 14:25:41 +0100 Subject: [PATCH] Trim spaces from InputAddress (#4126) * Trim spaces for addresses * onSubmit has only value, not event * onSubmit (again) * Length check on trimmed value --- js/src/ui/Form/InputAddress/inputAddress.js | 34 ++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/js/src/ui/Form/InputAddress/inputAddress.js b/js/src/ui/Form/InputAddress/inputAddress.js index 79bb24c8d..3cdac2a2e 100644 --- a/js/src/ui/Form/InputAddress/inputAddress.js +++ b/js/src/ui/Form/InputAddress/inputAddress.js @@ -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 (
+ address={ value } + center + inline />
); } - 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); + } } }