diff --git a/src/components/forms/validator.js b/src/components/forms/validator.js index e5a54d22..ba609f24 100644 --- a/src/components/forms/validator.js +++ b/src/components/forms/validator.js @@ -5,7 +5,10 @@ type Field = boolean | string export const required = (value: Field) => (value ? undefined : 'Required') -export const mustBeNumber = (value: number) => +export const mustBeInteger = (value: string) => + (!Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined) + +export const mustBeFloat = (value: number) => (Number.isNaN(Number(value)) ? 'Must be a number' : undefined) export const greaterThan = (min: number) => (value: string) => { diff --git a/src/routes/open/components/SafeForm/Confirmations/index.jsx b/src/routes/open/components/SafeForm/Confirmations/index.jsx index 68f59761..b757faa6 100644 --- a/src/routes/open/components/SafeForm/Confirmations/index.jsx +++ b/src/routes/open/components/SafeForm/Confirmations/index.jsx @@ -2,7 +2,7 @@ import * as React from 'react' import { Field } from 'react-final-form' import TextField from '~/components/forms/TextField' -import { composeValidators, minValue, mustBeNumber, required } from '~/components/forms/validator' +import { composeValidators, minValue, mustBeInteger, required } from '~/components/forms/validator' import Block from '~/components/layout/Block' import { FIELD_CONFIRMATIONS } from '~/routes/open/components/fields' @@ -14,7 +14,7 @@ const Confirmations = () => ( type="text" validate={composeValidators( required, - mustBeNumber, + mustBeInteger, minValue(1), )} placeholder="Required confirmations*" diff --git a/src/routes/open/components/SafeForm/DailyLimit/index.jsx b/src/routes/open/components/SafeForm/DailyLimit/index.jsx index 34dbd153..6c26b035 100644 --- a/src/routes/open/components/SafeForm/DailyLimit/index.jsx +++ b/src/routes/open/components/SafeForm/DailyLimit/index.jsx @@ -2,7 +2,7 @@ import * as React from 'react' import Field from '~/components/forms/Field' import TextField from '~/components/forms/TextField' -import { composeValidators, mustBeNumber, required, minValue } from '~/components/forms/validator' +import { composeValidators, mustBeFloat, required, minValue } from '~/components/forms/validator' import Block from '~/components/layout/Block' import { FIELD_DAILY_LIMIT } from '~/routes/open/components/fields' @@ -12,7 +12,7 @@ const DailyLimit = () => ( name={FIELD_DAILY_LIMIT} component={TextField} type="text" - validate={composeValidators(required, mustBeNumber, minValue(0))} + validate={composeValidators(required, mustBeFloat, minValue(0))} placeholder="Daily Limit*" text="Daily Limit" /> diff --git a/src/routes/open/components/SafeForm/Owners/index.jsx b/src/routes/open/components/SafeForm/Owners/index.jsx index 71928dcf..fa51f1b3 100644 --- a/src/routes/open/components/SafeForm/Owners/index.jsx +++ b/src/routes/open/components/SafeForm/Owners/index.jsx @@ -6,7 +6,7 @@ import { composeValidators, minValue, maxValue, - mustBeNumber, + mustBeInteger, mustBeEthereumAddress, required, uniqueAddress, @@ -45,7 +45,7 @@ const Owners = (props: Props) => { name={FIELD_OWNERS} component={TextField} type="text" - validate={composeValidators(required, mustBeNumber, maxValue(MAX_NUMBER_OWNERS), minValue(1))} + validate={composeValidators(required, mustBeInteger, maxValue(MAX_NUMBER_OWNERS), minValue(1))} placeholder="Number of owners*" text="Number of owners" /> diff --git a/src/routes/safe/component/AddTransaction/MultisigForm/index.jsx b/src/routes/safe/component/AddTransaction/MultisigForm/index.jsx index f0393c33..20dcd466 100644 --- a/src/routes/safe/component/AddTransaction/MultisigForm/index.jsx +++ b/src/routes/safe/component/AddTransaction/MultisigForm/index.jsx @@ -2,7 +2,7 @@ import * as React from 'react' import Field from '~/components/forms/Field' import TextField from '~/components/forms/TextField' -import { composeValidators, inLimit, mustBeNumber, required, greaterThan, mustBeEthereumAddress } from '~/components/forms/validator' +import { composeValidators, inLimit, mustBeFloat, required, greaterThan, mustBeEthereumAddress } from '~/components/forms/validator' import Block from '~/components/layout/Block' import Heading from '~/components/layout/Heading' import { TX_NAME_PARAM, TX_DESTINATION_PARAM, TX_VALUE_PARAM } from '~/routes/safe/component/AddTransaction/createTransactions' @@ -56,7 +56,7 @@ const WithdrawnForm = ({ balance }: Props) => () => ( name={TX_VALUE_PARAM} component={TextField} type="text" - validate={composeValidators(required, mustBeNumber, greaterThan(0), inLimit(balance, 0, 'available balance'))} + validate={composeValidators(required, mustBeFloat, greaterThan(0), inLimit(balance, 0, 'available balance'))} placeholder="Amount in ETH*" text="Amount in ETH" /> diff --git a/src/routes/safe/component/Withdrawn/WithdrawnForm/index.jsx b/src/routes/safe/component/Withdrawn/WithdrawnForm/index.jsx index df5dbf39..12f0ae26 100644 --- a/src/routes/safe/component/Withdrawn/WithdrawnForm/index.jsx +++ b/src/routes/safe/component/Withdrawn/WithdrawnForm/index.jsx @@ -2,7 +2,7 @@ import * as React from 'react' import Field from '~/components/forms/Field' import TextField from '~/components/forms/TextField' -import { composeValidators, inLimit, mustBeNumber, required, greaterThan, mustBeEthereumAddress } from '~/components/forms/validator' +import { composeValidators, inLimit, mustBeFloat, required, greaterThan, mustBeEthereumAddress } from '~/components/forms/validator' import Block from '~/components/layout/Block' import Heading from '~/components/layout/Heading' import { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdrawn/withdrawn' @@ -37,7 +37,7 @@ const WithdrawnForm = ({ limit, spentToday }: Props) => () => ( name={VALUE_PARAM} component={TextField} type="text" - validate={composeValidators(required, mustBeNumber, greaterThan(0), inLimit(limit, spentToday, 'daily limit'))} + validate={composeValidators(required, mustBeFloat, greaterThan(0), inLimit(limit, spentToday, 'daily limit'))} placeholder="Amount in ETH*" text="Amount in ETH" />