File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
apps/web/src/modules/create-dao/components Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1+ import { debounce } from 'lodash'
12import * as Yup from 'yup'
23
34import { isValidAddress } from 'src/utils/ens'
45import { 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+
620export 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 ( )
Original file line number Diff line number Diff line change @@ -11,11 +11,11 @@ import {
1111 defaultFormButtonWithPrev ,
1212} from 'src/components/Fields/styles.css'
1313import { Icon } from 'src/components/Icon'
14- import { getEnsAddress , isValidAddress } from 'src/utils/ens'
14+ import { getEnsAddress } from 'src/utils/ens'
1515import { isEmpty } from 'src/utils/helpers'
16- import { getProvider } from 'src/utils/provider'
1716
1817import { useFormStore } from '../stores'
18+ import { deboucedValidateAddress } from './AllocationForm/AllocationForm.schema'
1919
2020interface 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} )
You can’t perform that action at this time.
0 commit comments