WA-238 Implementing mustBeInteger validator on threshold and num of owners

This commit is contained in:
apanizo 2018-05-29 09:01:04 +02:00
parent 547f14474e
commit a7076b9a1a
6 changed files with 14 additions and 11 deletions

View File

@ -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) => {

View File

@ -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*"

View File

@ -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"
/>

View File

@ -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"
/>

View File

@ -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"
/>

View File

@ -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"
/>