Skip to content

Commit

Permalink
Merge pull request #177 from ourzora/fix-create-dao-address-validaton
Browse files Browse the repository at this point in the history
Add debounce to address validation
  • Loading branch information
neokry authored Mar 28, 2023
2 parents 09d2ff0 + af2cd6c commit 4be1015
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { debounce } from 'lodash'
import * as Yup from 'yup'

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

const validateAddress = async (
value: string | undefined,
res: (value: boolean | PromiseLike<boolean>) => void
) => {
try {
res(!!value && (await isValidAddress(value, getProvider())))
} catch (err) {
res(false)
}
}

export const deboucedValidateAddress = debounce(validateAddress, 500)

export const allocationSchema = Yup.object().shape({
founderAddress: Yup.string()
.test(
'isValidAddress',
'invalid address',
(value: string | undefined) => !!value && isValidAddress(value, getProvider())
(value) => new Promise((res) => deboucedValidateAddress(value, res))
)
.required('*'),
allocationPercentage: Yup.number()
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/modules/create-dao/components/VetoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
defaultFormButtonWithPrev,
} from 'src/components/Fields/styles.css'
import { Icon } from 'src/components/Icon'
import { getEnsAddress, isValidAddress } from 'src/utils/ens'
import { getEnsAddress } from 'src/utils/ens'
import { isEmpty } from 'src/utils/helpers'
import { getProvider } from 'src/utils/provider'

import { useFormStore } from '../stores'
import { deboucedValidateAddress } from './AllocationForm/AllocationForm.schema'

interface VetoFormProps {
title: string
Expand Down Expand Up @@ -44,7 +44,7 @@ export const vetoValidationSchema = Yup.object().shape({
.test(
'isValidAddress',
'invalid address',
(value: string | undefined) => !!value && isValidAddress(value, getProvider())
(value) => new Promise((res) => deboucedValidateAddress(value, res))
),
}),
})
Expand Down

2 comments on commit 4be1015

@vercel
Copy link

@vercel vercel bot commented on 4be1015 Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 4be1015 Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

testnet-nouns-builder – ./apps/web

testnet-nouns-builder-git-main-ourzora.vercel.app
testnet-nouns-builder-ourzora.vercel.app
testnet.nouns.build

Please sign in to comment.