2020-07-09 06:06:29 +03:00
|
|
|
import { isAddress } from '../utils'
|
|
|
|
import useENSAddress from './useENSAddress'
|
|
|
|
import useENSName from './useENSName'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a name or address, does a lookup to resolve to an address and name
|
|
|
|
* @param nameOrAddress ENS name or address
|
|
|
|
*/
|
|
|
|
export default function useENS(
|
|
|
|
nameOrAddress?: string | null
|
|
|
|
): { loading: boolean; address: string | null; name: string | null } {
|
|
|
|
const validated = isAddress(nameOrAddress)
|
|
|
|
const reverseLookup = useENSName(validated ? validated : undefined)
|
|
|
|
const lookup = useENSAddress(nameOrAddress)
|
|
|
|
|
|
|
|
return {
|
|
|
|
loading: reverseLookup.loading || lookup.loading,
|
|
|
|
address: validated ? validated : lookup.address,
|
2021-02-16 11:26:53 +03:00
|
|
|
name: reverseLookup.ENSName ? reverseLookup.ENSName : !validated && lookup.address ? nameOrAddress || null : null
|
2020-07-09 06:06:29 +03:00
|
|
|
}
|
|
|
|
}
|