Skip to content

Commit 4be1015

Browse files
authored
Merge pull request #177 from ourzora/fix-create-dao-address-validaton
Add debounce to address validation
2 parents 09d2ff0 + af2cd6c commit 4be1015

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
import { debounce } from 'lodash'
12
import * as Yup from 'yup'
23

34
import { isValidAddress } from 'src/utils/ens'
45
import { getProvider } from 'src/utils/provider'
56

7+
const validateAddress = async (
8+
value: string | undefined,
9+
res: (value: boolean | PromiseLike<boolean>) => void
10+
) => {
11+
try {
12+
res(!!value && (await isValidAddress(value, getProvider())))
13+
} catch (err) {
14+
res(false)
15+
}
16+
}
17+
18+
export const deboucedValidateAddress = debounce(validateAddress, 500)
19+
620
export const allocationSchema = Yup.object().shape({
721
founderAddress: Yup.string()
822
.test(
923
'isValidAddress',
1024
'invalid address',
11-
(value: string | undefined) => !!value && isValidAddress(value, getProvider())
25+
(value) => new Promise((res) => deboucedValidateAddress(value, res))
1226
)
1327
.required('*'),
1428
allocationPercentage: Yup.number()

apps/web/src/modules/create-dao/components/VetoForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
defaultFormButtonWithPrev,
1212
} from 'src/components/Fields/styles.css'
1313
import { Icon } from 'src/components/Icon'
14-
import { getEnsAddress, isValidAddress } from 'src/utils/ens'
14+
import { getEnsAddress } from 'src/utils/ens'
1515
import { isEmpty } from 'src/utils/helpers'
16-
import { getProvider } from 'src/utils/provider'
1716

1817
import { useFormStore } from '../stores'
18+
import { deboucedValidateAddress } from './AllocationForm/AllocationForm.schema'
1919

2020
interface VetoFormProps {
2121
title: string
@@ -44,7 +44,7 @@ export const vetoValidationSchema = Yup.object().shape({
4444
.test(
4545
'isValidAddress',
4646
'invalid address',
47-
(value: string | undefined) => !!value && isValidAddress(value, getProvider())
47+
(value) => new Promise((res) => deboucedValidateAddress(value, res))
4848
),
4949
}),
5050
})

0 commit comments

Comments
 (0)