Skip to content

Commit

Permalink
fix: Add ENSName and address check to Web3Status (#3040)
Browse files Browse the repository at this point in the history
* Add ENSName and address check to Web3Status

Issue #2838

* Update useENSName.ts

Do the forward ENSAddress check in useENSName

* Update index.tsx

Revert ENSAddress check, which has been moved into ENSName hook

* Update useENSName.ts

Correcting the equality check (was testing that things work, and made a wrong commit)

* add comment, change var names

Co-authored-by: Tina Zheng <[email protected]>
  • Loading branch information
uniyj and tinaszheng authored Dec 30, 2021
1 parent db8dab4 commit 5b7a80d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/hooks/useENSName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isAddress } from '../utils'
import isZero from '../utils/isZero'
import { useENSRegistrarContract, useENSResolverContract } from './useContract'
import useDebounce from './useDebounce'
import useENSAddress from './useENSAddress'

/**
* Does a reverse lookup for an address to find its ENS name.
Expand All @@ -24,14 +25,22 @@ export default function useENSName(address?: string): { ENSName: string | null;
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false
)
const name = useSingleCallResult(resolverContract, 'name', ensNodeArgument)
const nameCallRes = useSingleCallResult(resolverContract, 'name', ensNodeArgument)
const name = nameCallRes.result?.[0]

/* ENS does not enforce that an address owns a .eth domain before setting it as a reverse proxy
and recommends that you perform a match on the forward resolution
see: https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution
*/
const fwdAddr = useENSAddress(name)
const checkedName = address === fwdAddr?.address ? name : null

const changed = debouncedAddress !== address
return useMemo(
() => ({
ENSName: changed ? null : name.result?.[0] ?? null,
loading: changed || resolverAddress.loading || name.loading,
ENSName: changed ? null : checkedName,
loading: changed || resolverAddress.loading || nameCallRes.loading,
}),
[changed, name.loading, name.result, resolverAddress.loading]
[changed, nameCallRes.loading, checkedName, resolverAddress.loading]
)
}

0 comments on commit 5b7a80d

Please sign in to comment.