Validate owner address when it is replaced

This commit is contained in:
Germán Martínez 2019-07-04 08:57:27 +02:00
parent efff7ce388
commit 01e212d9fe
1 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,7 @@
// @flow // @flow
import React from 'react' import React from 'react'
import classNames from 'classnames/bind' import classNames from 'classnames/bind'
import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import Close from '@material-ui/icons/Close' import Close from '@material-ui/icons/Close'
import IconButton from '@material-ui/core/IconButton' import IconButton from '@material-ui/core/IconButton'
@ -17,8 +18,13 @@ import TextField from '~/components/forms/TextField'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import Link from '~/components/layout/Link' import Link from '~/components/layout/Link'
import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { type Owner } from '~/routes/safe/store/models/owner'
import { import {
composeValidators, required, mustBeEthereumAddress, minMaxLength, composeValidators,
required,
mustBeEthereumAddress,
minMaxLength,
uniqueAddress,
} from '~/components/forms/validator' } from '~/components/forms/validator'
import { styles } from './style' import { styles } from './style'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
@ -35,14 +41,16 @@ type Props = {
ownerName: string, ownerName: string,
network: string, network: string,
onSubmit: Function, onSubmit: Function,
owners: List<Owner>,
} }
const OwnerForm = ({ const OwnerForm = ({
classes, onClose, ownerAddress, ownerName, network, onSubmit, classes, onClose, ownerAddress, ownerName, network, onSubmit, owners,
}: Props) => { }: Props) => {
const handleSubmit = (values) => { const handleSubmit = (values) => {
onSubmit(values) onSubmit(values)
} }
const ownerDoesntExist = uniqueAddress(owners.map(o => o.address))
return ( return (
<React.Fragment> <React.Fragment>
@ -111,7 +119,7 @@ const OwnerForm = ({
name="ownerAddress" name="ownerAddress"
component={TextField} component={TextField}
type="text" type="text"
validate={composeValidators(required, mustBeEthereumAddress)} validate={composeValidators(required, mustBeEthereumAddress, ownerDoesntExist)}
placeholder="Owner address*" placeholder="Owner address*"
text="Owner address*" text="Owner address*"
className={classes.addressInput} className={classes.addressInput}
@ -130,7 +138,6 @@ const OwnerForm = ({
variant="contained" variant="contained"
minWidth={140} minWidth={140}
color="primary" color="primary"
data-testid="review-tx-btn"
> >
Next Next
</Button> </Button>