From 14d9a3a78fbd6f7e913f7c855c34d86da16d73e7 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Fri, 22 May 2020 14:33:08 +0400 Subject: [PATCH 1/3] fix required validator --- src/components/forms/validator.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/forms/validator.ts b/src/components/forms/validator.ts index a5bd54e6..93db7da9 100644 --- a/src/components/forms/validator.ts +++ b/src/components/forms/validator.ts @@ -13,14 +13,14 @@ export const simpleMemoize = (fn) => { } } -export const required = (value) => (value ? undefined : 'Required') +export const required = (value?: string) => (value && value.trim() !== '' ? undefined : 'Required') -export const mustBeInteger = (value) => +export const mustBeInteger = (value: string) => !Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined -export const mustBeFloat = (value) => (value && Number.isNaN(Number(value)) ? 'Must be a number' : undefined) +export const mustBeFloat = (value: string) => (value && Number.isNaN(Number(value)) ? 'Must be a number' : undefined) -export const greaterThan = (min) => (value) => { +export const greaterThan = (min: number | string) => (value: string) => { if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) { return undefined } @@ -30,7 +30,7 @@ export const greaterThan = (min) => (value) => { const regexQuery = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i const url = new RegExp(regexQuery) -export const mustBeUrl = (value) => { +export const mustBeUrl = (value: string) => { if (url.test(value)) { return undefined } @@ -38,7 +38,7 @@ export const mustBeUrl = (value) => { return 'Please, provide a valid url' } -export const minValue = (min) => (value) => { +export const minValue = (min: number | string) => (value: string) => { if (Number.isNaN(Number(value)) || Number.parseFloat(value) >= Number(min)) { return undefined } @@ -46,8 +46,8 @@ export const minValue = (min) => (value) => { return `Should be at least ${min}` } -export const maxValue = (max) => (value) => { - if (Number.isNaN(Number(value)) || parseFloat(value) <= parseFloat(max)) { +export const maxValue = (max: number | string) => (value: string) => { + if (Number.isNaN(Number(value)) || parseFloat(value) <= parseFloat(max.toString())) { return undefined } @@ -56,14 +56,14 @@ export const maxValue = (max) => (value) => { export const ok = () => undefined -export const mustBeEthereumAddress = simpleMemoize((address) => { +export const mustBeEthereumAddress = simpleMemoize((address: string) => { const startsWith0x = address.startsWith('0x') const isAddress = getWeb3().utils.isAddress(address) return startsWith0x && isAddress ? undefined : 'Address should be a valid Ethereum address or ENS name' }) -export const mustBeEthereumContractAddress = simpleMemoize(async (address) => { +export const mustBeEthereumContractAddress = simpleMemoize(async (address: string) => { const contractCode = await getWeb3().eth.getCode(address) return !contractCode || contractCode.replace('0x', '').replace(/0/g, '') === '' @@ -76,8 +76,8 @@ export const minMaxLength = (minLen, maxLen) => (value) => export const ADDRESS_REPEATED_ERROR = 'Address already introduced' -export const uniqueAddress = (addresses) => - simpleMemoize((value) => { +export const uniqueAddress = (addresses: string[]) => + simpleMemoize((value: string[]) => { const addressAlreadyExists = addresses.some((address) => sameAddress(value, address)) return addressAlreadyExists ? ADDRESS_REPEATED_ERROR : undefined }) @@ -95,7 +95,7 @@ export const inLimit = (limit, base, baseText, symbol = 'ETH') => (value) => { return `Should not exceed ${max} ${symbol} (amount to reach ${baseText})` } -export const differentFrom = (diffValue) => (value) => { +export const differentFrom = (diffValue: number | string) => (value: string) => { if (value === diffValue.toString()) { return `Value should be different than ${value}` } From c8e9ef9a3aeb7a24f3a070bff1db8668bb1b039c Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Mon, 25 May 2020 15:43:00 +0400 Subject: [PATCH 2/3] fix hooks import casing --- src/routes/safe/container/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/safe/container/index.jsx b/src/routes/safe/container/index.jsx index 927aff1c..92efece0 100644 --- a/src/routes/safe/container/index.jsx +++ b/src/routes/safe/container/index.jsx @@ -5,8 +5,8 @@ import { useSelector } from 'react-redux' import Page from 'src/components/layout/Page' import Layout from 'src/routes/safe/components/Layout' -import { useCheckForUpdates } from 'src/routes/safe/container/Hooks/useCheckForUpdates' -import { useLoadSafe } from 'src/routes/safe/container/Hooks/useLoadSafe' +import { useCheckForUpdates } from 'src/routes/safe/container/hooks/useCheckForUpdates' +import { useLoadSafe } from 'src/routes/safe/container/hooks/useLoadSafe' import { safeParamAddressFromStateSelector } from 'src/routes/safe/store/selectors' const INITIAL_STATE = { From 5803ca0ea48b2a34de737ed78a2ba80200837ea4 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Mon, 25 May 2020 16:07:40 +0400 Subject: [PATCH 3/3] fix hooks import casing --- src/routes/safe/components/Balances/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/safe/components/Balances/index.tsx b/src/routes/safe/components/Balances/index.tsx index 551b73d5..105404e6 100644 --- a/src/routes/safe/components/Balances/index.tsx +++ b/src/routes/safe/components/Balances/index.tsx @@ -18,7 +18,7 @@ import CurrencyDropdown from 'src/routes/safe/components/CurrencyDropdown' import { safeFeaturesEnabledSelector, safeParamAddressFromStateSelector } from 'src/routes/safe/store/selectors' import { history } from 'src/store/index' import { wrapInSuspense } from 'src/utils/wrapInSuspense' -import { useFetchTokens } from '../../container/Hooks/useFetchTokens' +import { useFetchTokens } from '../../container/hooks/useFetchTokens' const Collectibles = React.lazy(() => import('src/routes/safe/components/Balances/Collectibles')) const Coins = React.lazy(() => import('src/routes/safe/components/Balances/Coins'))