WA-232 Fix Flow errors regarding final form validator Field

This commit is contained in:
apanizo 2018-06-26 13:46:17 +02:00
parent f0cde75151
commit 847033a5c8
6 changed files with 15 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import FormStep from '@material-ui/core/Step'
import StepLabel from '@material-ui/core/StepLabel' import StepLabel from '@material-ui/core/StepLabel'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import * as React from 'react' import * as React from 'react'
import type { FormApi } from 'react-final-form'
import GnoForm from '~/components/forms/GnoForm' import GnoForm from '~/components/forms/GnoForm'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import Col from '~/components/layout/Col' import Col from '~/components/layout/Col'
@ -21,7 +20,7 @@ type Props = {
initialValues?: Object, initialValues?: Object,
children: React$Node, children: React$Node,
onReset?: () => void, onReset?: () => void,
onSubmit: (values: Object, form: FormApi, callback: ?(errors: ?Object) => void) => ?Object | Promise<?Object> | void, onSubmit: (values: Object) => Promise<void>,
} }
type State = { type State = {

View File

@ -3,12 +3,14 @@ import * as React from 'react'
import { type FormApi } from 'final-form' import { type FormApi } from 'final-form'
import { Form } from 'react-final-form' import { Form } from 'react-final-form'
type Props = { export type OnSubmit = (
onSubmit: (
values: Object, values: Object,
form: FormApi, form: FormApi,
callback: ?(errors: ?Object) => ?Object callback: ?(errors: ?Object) => ?Object
) => ?Object | Promise<?Object> | void, ) => ?Object | Promise<?Object> | void
type Props = {
onSubmit: OnSubmit,
children: Function, children: Function,
padding: number, padding: number,
validation?: (values: Object) => Object | Promise<Object>, validation?: (values: Object) => Object | Promise<Object>,

View File

@ -1,7 +1,8 @@
// @flow // @flow
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { type FieldValidator } from 'final-form'
type Field = boolean | string type Field = boolean | string | null | typeof undefined
export const required = (value: Field) => (value ? undefined : 'Required') export const required = (value: Field) => (value ? undefined : 'Required')
@ -48,7 +49,7 @@ export const ADDRESS_REPEATED_ERROR = 'Address already introduced'
export const uniqueAddress = (addresses: string[]) => (value: string) => export const uniqueAddress = (addresses: string[]) => (value: string) =>
(addresses.includes(value) ? ADDRESS_REPEATED_ERROR : undefined) (addresses.includes(value) ? ADDRESS_REPEATED_ERROR : undefined)
export const composeValidators = (...validators: Function[]) => (value: Field) => export const composeValidators = (...validators: Function[]): FieldValidator => (value: Field) =>
validators.reduce((error, validator) => error || validator(value), undefined) validators.reduce((error, validator) => error || validator(value), undefined)
export const inLimit = (limit: number, base: number, baseText: string) => (value: string) => { export const inLimit = (limit: number, base: number, baseText: string) => (value: string) => {

View File

@ -1,6 +1,5 @@
// @flow // @flow
import * as React from 'react' import * as React from 'react'
import type { FormApi } from 'react-final-form'
import Stepper from '~/components/Stepper' import Stepper from '~/components/Stepper'
import Confirmation from '~/routes/open/components/FormConfirmation' import Confirmation from '~/routes/open/components/FormConfirmation'
import Review from '~/routes/open/components/ReviewInformation' import Review from '~/routes/open/components/ReviewInformation'
@ -21,8 +20,7 @@ type Props = {
userAccount: string, userAccount: string,
safeAddress: string, safeAddress: string,
safeTx: string, safeTx: string,
onCallSafeContractSubmit: (values: Object, form: FormApi, callback: ?(errors: ?Object) => void) onCallSafeContractSubmit: (values: Object) => Promise<void>,
=> ?Object | Promise<?Object> | void,
} }
const Layout = ({ const Layout = ({

View File

@ -26,7 +26,7 @@ storiesOf('Routes /open', module)
getProviderInfo() getProviderInfo()
const provider = 'METAMASK' const provider = 'METAMASK'
const userAccount = '0x03db1a8b26d08df23337e9276a36b474510f0023' const userAccount = '0x03db1a8b26d08df23337e9276a36b474510f0023'
const onCallSafeContractSubmit = async (values: Object) => { const onCallSafeContractSubmit = async (values: Object): Promise<void> => {
const accounts = getAccountsFrom(values) const accounts = getAccountsFrom(values)
const numConfirmations = getThresholdFrom(values) const numConfirmations = getThresholdFrom(values)
const data = { const data = {

View File

@ -8,7 +8,7 @@ import { getProviderInfo } from '~/wallets/getWeb3'
import Wrapper from '~/test/utils/Wrapper' import Wrapper from '~/test/utils/Wrapper'
import { CONFIRMATIONS_ERROR } from '~/routes/open/components/SafeForm' import { CONFIRMATIONS_ERROR } from '~/routes/open/components/SafeForm'
const obSubmitMock = () => {} const onSubmitMock = async (): Promise<void> => {}
describe('React DOM TESTS > Create Safe form', () => { describe('React DOM TESTS > Create Safe form', () => {
let open let open
@ -25,7 +25,7 @@ describe('React DOM TESTS > Create Safe form', () => {
userAccount="foo" userAccount="foo"
safeAddress="" safeAddress=""
safeTx="" safeTx=""
onCallSafeContractSubmit={obSubmitMock} onCallSafeContractSubmit={onSubmitMock}
/> />
</Wrapper> </Wrapper>
)) ))