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

Trim spaces from InputAddress #4126

Merged
merged 4 commits into from
Jan 12, 2017
Merged
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
39 changes: 23 additions & 16 deletions js/src/ui/Form/InputAddress/inputAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import util from '~/api/util';
import { nodeOrStringProptype } from '~/util/proptypes';
Expand Down Expand Up @@ -58,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]);
Expand Down Expand Up @@ -91,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={
Expand Down Expand Up @@ -133,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, address);
}
}

onSubmit = (_value) => {
const address = _value.trim();

this.props.onChange(event, value);
if (this.props.onSubmit) {
this.props.onSubmit(address);
}
}
}

Expand All @@ -162,11 +173,7 @@ function mapStateToProps (state) {
};
}

function mapDispatchToProps (dispatch) {
return bindActionCreators({}, dispatch);
}

export default connect(
mapStateToProps,
mapDispatchToProps
null
)(InputAddress);