Fix unique address validator, eslint fixes for settings
This commit is contained in:
parent
c0220ed135
commit
d2dad7467d
|
@ -1,6 +1,8 @@
|
|||
// @flow
|
||||
import { type FieldValidator } from 'final-form'
|
||||
import { List } from 'immutable'
|
||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||
import { sameAddress } from '~/logic/wallets/ethAddresses'
|
||||
|
||||
export const simpleMemoize = (fn: Function) => {
|
||||
let lastArg
|
||||
|
@ -68,7 +70,10 @@ export const minMaxLength = (minLen: string | number, maxLen: string | number) =
|
|||
|
||||
export const ADDRESS_REPEATED_ERROR = 'Address already introduced'
|
||||
|
||||
export const uniqueAddress = (addresses: string[]) => simpleMemoize((value: string) => (addresses.includes(value) ? ADDRESS_REPEATED_ERROR : undefined))
|
||||
export const uniqueAddress = (addresses: string[] | List<string>) => simpleMemoize((value: string) => {
|
||||
const addressAlreadyExists = addresses.some((address) => sameAddress(value, address))
|
||||
return addressAlreadyExists ? ADDRESS_REPEATED_ERROR : undefined
|
||||
})
|
||||
|
||||
export const composeValidators = (...validators: Function[]): FieldValidator => (value: Field) => validators.reduce((error, validator) => error || validator(value), undefined)
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ const AddOwner = ({
|
|||
}
|
||||
|
||||
const ownerSubmitted = (newValues: Object) => {
|
||||
setValues(stateValues => ({
|
||||
setValues((stateValues) => ({
|
||||
...stateValues,
|
||||
ownerName: newValues.ownerName,
|
||||
ownerAddress: newValues.ownerAddress,
|
||||
|
@ -91,7 +91,7 @@ const AddOwner = ({
|
|||
}
|
||||
|
||||
const thresholdSubmitted = (newValues: Object) => {
|
||||
setValues(stateValues => ({
|
||||
setValues((stateValues) => ({
|
||||
...stateValues,
|
||||
threshold: newValues.threshold,
|
||||
}))
|
||||
|
@ -99,7 +99,7 @@ const AddOwner = ({
|
|||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<>
|
||||
<SharedSnackbarConsumer>
|
||||
{({ openSnackbar }) => {
|
||||
const onAddOwner = async () => {
|
||||
|
@ -120,7 +120,7 @@ const AddOwner = ({
|
|||
open={isOpen}
|
||||
paperClassName={classes.biggerModalWindow}
|
||||
>
|
||||
<React.Fragment>
|
||||
<>
|
||||
{activeScreen === 'selectOwner' && (
|
||||
<OwnerForm onClose={onClose} onSubmit={ownerSubmitted} owners={owners} />
|
||||
)}
|
||||
|
@ -144,12 +144,12 @@ const AddOwner = ({
|
|||
onSubmit={onAddOwner}
|
||||
/>
|
||||
)}
|
||||
</React.Fragment>
|
||||
</>
|
||||
</Modal>
|
||||
)
|
||||
}}
|
||||
</SharedSnackbarConsumer>
|
||||
</React.Fragment>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,7 @@ import Field from '~/components/forms/Field'
|
|||
import TextField from '~/components/forms/TextField'
|
||||
import { type Owner } from '~/routes/safe/store/models/owner'
|
||||
import {
|
||||
composeValidators,
|
||||
required,
|
||||
minMaxLength,
|
||||
uniqueAddress,
|
||||
composeValidators, required, minMaxLength, uniqueAddress,
|
||||
} from '~/components/forms/validator'
|
||||
import { styles } from './style'
|
||||
|
||||
|
@ -46,10 +43,10 @@ const OwnerForm = ({
|
|||
const handleSubmit = (values) => {
|
||||
onSubmit(values)
|
||||
}
|
||||
const ownerDoesntExist = uniqueAddress(owners.map(o => o.address))
|
||||
const ownerDoesntExist = uniqueAddress(owners.map((o) => o.address))
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<>
|
||||
<Row align="center" grow className={classes.heading}>
|
||||
<Paragraph weight="bolder" className={classes.manage} noMargin>
|
||||
Add new owner
|
||||
|
@ -65,7 +62,7 @@ const OwnerForm = ({
|
|||
const mutators = args[3]
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<>
|
||||
<Block className={classes.formContainer}>
|
||||
<Row margin="md">
|
||||
<Paragraph>Add a new owner to the active Safe</Paragraph>
|
||||
|
@ -114,11 +111,11 @@ const OwnerForm = ({
|
|||
Next
|
||||
</Button>
|
||||
</Row>
|
||||
</React.Fragment>
|
||||
</>
|
||||
)
|
||||
}}
|
||||
</GnoForm>
|
||||
</React.Fragment>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,7 @@ import Link from '~/components/layout/Link'
|
|||
import { getEtherScanLink } from '~/logic/wallets/getWeb3'
|
||||
import { type Owner } from '~/routes/safe/store/models/owner'
|
||||
import {
|
||||
composeValidators,
|
||||
required,
|
||||
minMaxLength,
|
||||
uniqueAddress,
|
||||
composeValidators, required, minMaxLength, uniqueAddress,
|
||||
} from '~/components/forms/validator'
|
||||
import { styles } from './style'
|
||||
import { secondary } from '~/theme/variables'
|
||||
|
@ -60,10 +57,10 @@ const OwnerForm = ({
|
|||
const handleSubmit = (values) => {
|
||||
onSubmit(values)
|
||||
}
|
||||
const ownerDoesntExist = uniqueAddress(owners.map(o => o.address))
|
||||
const ownerDoesntExist = uniqueAddress(owners.map((o) => o.address))
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<>
|
||||
<Row align="center" grow className={classes.heading}>
|
||||
<Paragraph weight="bolder" className={classes.manage} noMargin>
|
||||
Replace owner
|
||||
|
@ -79,7 +76,7 @@ const OwnerForm = ({
|
|||
const mutators = args[3]
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<>
|
||||
<Block className={classes.formContainer}>
|
||||
<Row>
|
||||
<Paragraph>
|
||||
|
@ -162,11 +159,11 @@ const OwnerForm = ({
|
|||
Next
|
||||
</Button>
|
||||
</Row>
|
||||
</React.Fragment>
|
||||
</>
|
||||
)
|
||||
}}
|
||||
</GnoForm>
|
||||
</React.Fragment>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue