From d2dad7467d5deb054382de331d42dee275b1c0bd Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Tue, 3 Sep 2019 14:00:26 +0400 Subject: [PATCH] Fix unique address validator, eslint fixes for settings --- src/components/forms/validator.js | 7 ++++++- .../Settings/ManageOwners/AddOwnerModal/index.jsx | 12 ++++++------ .../AddOwnerModal/screens/OwnerForm/index.jsx | 15 ++++++--------- .../ReplaceOwnerModal/screens/OwnerForm/index.jsx | 15 ++++++--------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/components/forms/validator.js b/src/components/forms/validator.js index decf8710..d688a828 100644 --- a/src/components/forms/validator.js +++ b/src/components/forms/validator.js @@ -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) => 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) diff --git a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx index 98ae7d59..1ace6021 100644 --- a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx @@ -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 ( - + <> {({ openSnackbar }) => { const onAddOwner = async () => { @@ -120,7 +120,7 @@ const AddOwner = ({ open={isOpen} paperClassName={classes.biggerModalWindow} > - + <> {activeScreen === 'selectOwner' && ( )} @@ -144,12 +144,12 @@ const AddOwner = ({ onSubmit={onAddOwner} /> )} - + ) }} - + ) } diff --git a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/OwnerForm/index.jsx b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/OwnerForm/index.jsx index 0cdf09b7..4193af95 100644 --- a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/OwnerForm/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/OwnerForm/index.jsx @@ -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 ( - + <> Add new owner @@ -65,7 +62,7 @@ const OwnerForm = ({ const mutators = args[3] return ( - + <> Add a new owner to the active Safe @@ -114,11 +111,11 @@ const OwnerForm = ({ Next - + ) }} - + ) } diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx index 4892a679..35929396 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx @@ -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 ( - + <> Replace owner @@ -79,7 +76,7 @@ const OwnerForm = ({ const mutators = args[3] return ( - + <> @@ -162,11 +159,11 @@ const OwnerForm = ({ Next - + ) }} - + ) }