Skip to content

Commit

Permalink
fix: Use RHF isValidating instead of setting own state
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Aug 1, 2023
1 parent 8a2bb00 commit fe1c04c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/components/common/AddressInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactElement } from 'react'
import { useEffect, useCallback, useRef, useMemo, useState } from 'react'
import { useEffect, useCallback, useRef, useMemo } from 'react'
import {
InputAdornment,
TextField,
Expand Down Expand Up @@ -47,15 +47,14 @@ const AddressInput = ({
register,
setValue,
control,
formState: { errors },
formState: { errors, isValidating },
trigger,
} = useFormContext()

const currentChain = useCurrentChain()
const rawValueRef = useRef<string>('')
const watchedValue = useWatch({ name, control })
const currentShortName = currentChain?.shortName || ''
const [isValidating, setIsValidating] = useState<boolean>(false)

// Fetch an ENS resolution for the current address
const isDomainLookupEnabled = !!currentChain && hasFeature(currentChain, FEATURES.DOMAIN_LOOKUP)
Expand Down Expand Up @@ -154,17 +153,11 @@ const AddressInput = ({
return parsePrefixedAddress(cleanValue).address
},

validate: async (inputValue) => {
validate: async () => {
const value = rawValueRef.current

// Validation unmounts QR code otherwise
if (inputValue === value) return

if (value) {
setIsValidating(true)
const result = validatePrefixed(value) || (await validate?.(parsePrefixedAddress(value).address))
setIsValidating(false)
return result
return validatePrefixed(value) || (await validate?.(parsePrefixedAddress(value).address))
}
},

Expand Down

0 comments on commit fe1c04c

Please sign in to comment.