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
|
|
|
|
*/
|
2021-05-21 04:14:55 +03:00
|
|
|
export default function useENS(nameOrAddress?: string | null): {
|
2021-05-21 04:11:32 +03:00
|
|
|
loading: boolean
|
|
|
|
address: string | null
|
|
|
|
name: string | null
|
|
|
|
} {
|
2020-07-09 06:06:29 +03:00
|
|
|
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:46:17 +03:00
|
|
|
name: reverseLookup.ENSName ? reverseLookup.ENSName : !validated && lookup.address ? nameOrAddress || null : null,
|
2020-07-09 06:06:29 +03:00
|
|
|
}
|
|
|
|
}
|