Files

41 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2017-12-18 16:23:31 -05:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
2018-05-13 15:24:50 -04:00
import { isHexString } from 'ethereumjs-util';
2017-12-18 16:23:31 -05:00
import { AppState } from 'features/reducers';
import { transactionFieldsSelectors } from 'features/transaction';
import { CallBackProps } from 'components/DataFieldFactory';
import { Query } from 'components/renderCbs';
2017-12-18 16:23:31 -05:00
interface OwnProps {
withProps(props: CallBackProps): React.ReactElement<any> | null;
2017-12-19 17:46:34 -05:00
onChange(ev: React.FormEvent<HTMLInputElement>): void;
2017-12-18 16:23:31 -05:00
}
interface StateProps {
data: AppState['transaction']['fields']['data'];
2018-05-13 15:24:50 -04:00
validData: boolean;
2017-12-18 16:23:31 -05:00
}
type Props = OwnProps & StateProps;
class DataInputClass extends Component<Props> {
public render() {
2018-05-13 15:24:50 -04:00
const { data, onChange, validData } = this.props;
2017-12-18 16:23:31 -05:00
return (
<Query
params={['readOnly']}
withQuery={({ readOnly }) =>
2018-05-13 15:24:50 -04:00
this.props.withProps({ data, onChange, readOnly: !!readOnly, validData })
2017-12-18 16:23:31 -05:00
}
/>
);
}
}
export const DataInput = connect((state: AppState) => ({
data: transactionFieldsSelectors.getData(state),
validData:
transactionFieldsSelectors.getData(state).raw === '' ||
isHexString(transactionFieldsSelectors.getData(state).raw)
2017-12-18 16:23:31 -05:00
}))(DataInputClass);