add validator for already existing owner address

This commit is contained in:
Mikhail Mikheev 2019-06-28 16:04:31 +04:00
parent 0c9717831a
commit 9cbc31b9ae
2 changed files with 12 additions and 6 deletions

View File

@ -123,7 +123,9 @@ const AddOwner = ({
paperClassName={classes.biggerModalWindow} paperClassName={classes.biggerModalWindow}
> >
<React.Fragment> <React.Fragment>
{activeScreen === 'selectOwner' && <OwnerForm onClose={onClose} onSubmit={ownerSubmitted} />} {activeScreen === 'selectOwner' && (
<OwnerForm onClose={onClose} onSubmit={ownerSubmitted} owners={owners} />
)}
{activeScreen === 'selectThreshold' && ( {activeScreen === 'selectThreshold' && (
<ThresholdForm <ThresholdForm
onClose={onClose} onClose={onClose}

View File

@ -13,6 +13,7 @@ import Block from '~/components/layout/Block'
import Hairline from '~/components/layout/Hairline' import Hairline from '~/components/layout/Hairline'
import Field from '~/components/forms/Field' import Field from '~/components/forms/Field'
import TextField from '~/components/forms/TextField' import TextField from '~/components/forms/TextField'
import { type Owner } from '~/routes/safe/store/models/owner'
import { import {
composeValidators, composeValidators,
required, required,
@ -26,13 +27,16 @@ type Props = {
onClose: () => void, onClose: () => void,
classes: Object, classes: Object,
onSubmit: Function, onSubmit: Function,
owners: List<string>, owners: List<Owner>,
} }
const OwnerForm = ({ classes, onClose, onSubmit }: Props) => { const OwnerForm = ({
classes, onClose, onSubmit, owners,
}: 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>
@ -72,7 +76,7 @@ const OwnerForm = ({ classes, onClose, onSubmit }: Props) => {
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}
@ -83,7 +87,7 @@ const OwnerForm = ({ classes, onClose, onSubmit }: Props) => {
<Hairline /> <Hairline />
<Row align="center" className={classes.buttonRow}> <Row align="center" className={classes.buttonRow}>
<Button className={classes.button} minWidth={140} onClick={onClose}> <Button className={classes.button} minWidth={140} onClick={onClose}>
Cancel Cancel
</Button> </Button>
<Button <Button
type="submit" type="submit"
@ -93,7 +97,7 @@ const OwnerForm = ({ classes, onClose, onSubmit }: Props) => {
color="primary" color="primary"
data-testid="review-tx-btn" data-testid="review-tx-btn"
> >
Next Next
</Button> </Button>
</Row> </Row>
</React.Fragment> </React.Fragment>