Add basic validation for contract execute values (#3118)
This commit is contained in:
@@ -19,7 +19,7 @@ import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
|
||||
import ContentClear from 'material-ui/svg-icons/content/clear';
|
||||
|
||||
import { BusyStep, CompletedStep, Button, IdentityIcon, Modal, TxHash } from '../../ui';
|
||||
import { validateAddress } from '../../util/validation';
|
||||
import { validateAddress, validateUint } from '../../util/validation';
|
||||
|
||||
import DetailsStep from './DetailsStep';
|
||||
|
||||
@@ -41,6 +41,7 @@ export default class ExecuteContract extends Component {
|
||||
state = {
|
||||
amount: '0',
|
||||
amountError: null,
|
||||
fromAddressError: null,
|
||||
func: null,
|
||||
funcError: null,
|
||||
values: [],
|
||||
@@ -77,7 +78,8 @@ export default class ExecuteContract extends Component {
|
||||
|
||||
renderDialogActions () {
|
||||
const { onClose, fromAddress } = this.props;
|
||||
const { sending, step } = this.state;
|
||||
const { sending, step, fromAddressError, valuesError } = this.state;
|
||||
const hasError = fromAddressError || valuesError.find((error) => error);
|
||||
const cancelBtn = (
|
||||
<Button
|
||||
key='cancel'
|
||||
@@ -92,7 +94,7 @@ export default class ExecuteContract extends Component {
|
||||
<Button
|
||||
key='postTransaction'
|
||||
label='post transaction'
|
||||
disabled={ sending }
|
||||
disabled={ sending || hasError }
|
||||
icon={ <IdentityIcon address={ fromAddress } button /> }
|
||||
onClick={ this.postTransaction } />
|
||||
];
|
||||
@@ -177,12 +179,16 @@ export default class ExecuteContract extends Component {
|
||||
let valueError = null;
|
||||
|
||||
switch (input.kind.type) {
|
||||
case 'address':
|
||||
valueError = validateAddress(_value).addressError;
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
value = _value === 'true';
|
||||
break;
|
||||
|
||||
case 'address':
|
||||
valueError = validateAddress(_value).addressError;
|
||||
case 'uint':
|
||||
valueError = validateUint(_value).valueError;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -190,8 +196,8 @@ export default class ExecuteContract extends Component {
|
||||
valuesError[index] = valueError;
|
||||
|
||||
this.setState({
|
||||
values,
|
||||
valuesError
|
||||
values: [].concat(values),
|
||||
valuesError: [].concat(valuesError)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user