HenryNguyen5 8d27d0ba4d Improve form validation (#1772)
* Change gas price validation to be string input based

* Change sanitization to use Nunber

* Have validators use Number over parseFloat

* Fix css validation class

* Add valid css to address field

* Add data field validation

* Remove unused import

* Fix button being hidden on inputs

* Dead code removal

* Unify textarea and input class validation

* Adjust validity styling to only apply after a value has been inputted

* Do not pass custom props to DOM
2018-05-13 14:24:50 -05:00

38 lines
1.1 KiB
TypeScript

import React, { Component } from 'react';
import { Query } from 'components/renderCbs';
import { getData } from 'selectors/transaction';
import { connect } from 'react-redux';
import { AppState } from 'reducers';
import { CallBackProps } from 'components/DataFieldFactory';
import { isHexString } from 'ethereumjs-util';
interface OwnProps {
withProps(props: CallBackProps): React.ReactElement<any> | null;
onChange(ev: React.FormEvent<HTMLInputElement>): void;
}
interface StateProps {
data: AppState['transaction']['fields']['data'];
validData: boolean;
}
type Props = OwnProps & StateProps;
class DataInputClass extends Component<Props> {
public render() {
const { data, onChange, validData } = this.props;
return (
<Query
params={['readOnly']}
withQuery={({ readOnly }) =>
this.props.withProps({ data, onChange, readOnly: !!readOnly, validData })
}
/>
);
}
}
export const DataInput = connect((state: AppState) => ({
data: getData(state),
validData: getData(state).raw === '' || isHexString(getData(state).raw)
}))(DataInputClass);