diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js
index 67f350feb..e0462982d 100644
--- a/js/src/modals/ExecuteContract/executeContract.js
+++ b/js/src/modals/ExecuteContract/executeContract.js
@@ -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 = (
}
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)
});
}
diff --git a/js/src/util/validation.js b/js/src/util/validation.js
index 243217077..dd6e22911 100644
--- a/js/src/util/validation.js
+++ b/js/src/util/validation.js
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
+import BigNumber from 'bignumber.js';
+
import util from '../api/util';
export const ERRORS = {
@@ -22,7 +24,10 @@ export const ERRORS = {
invalidChecksum: 'address has failed the checksum formatting',
invalidName: 'name should not be blank and longer than 2',
invalidAbi: 'abi should be a valid JSON array',
- invalidCode: 'code should be the compiled hex string'
+ invalidCode: 'code should be the compiled hex string',
+ invalidNumber: 'invalid number format',
+ negativeNumber: 'input number should be positive',
+ decimalNumber: 'input number should not contain decimals'
};
export function validateAbi (abi, api) {
@@ -88,3 +93,23 @@ export function validateName (name) {
nameError
};
}
+
+export function validateUint (value) {
+ let valueError = null;
+
+ try {
+ const bn = new BigNumber(value);
+ if (bn.lt(0)) {
+ valueError = ERRORS.negativeNumber;
+ } else if (bn.toString().indexOf('.') !== -1) {
+ valueError = ERRORS.decimalNumber;
+ }
+ } catch (e) {
+ valueError = ERRORS.invalidNumber;
+ }
+
+ return {
+ value,
+ valueError
+ };
+}