Comparing version 0.0.5 to 0.0.6
@@ -5,2 +5,3 @@ import { ResolvedENS } from 'get-ens'; | ||
provider: Provider; | ||
chainId: number; | ||
domain: string; | ||
@@ -12,6 +13,4 @@ fetchOptions?: RequestInit; | ||
* A React hook to fetch ENS records from a domain. | ||
* @param provider Ethers.js provider | ||
* @param domain ENS domain to fetch data from | ||
* @returns | ||
*/ | ||
export declare const useENS: ({ provider, domain, fetchOptions, contractAddress }: UseENSOptions) => ResolvedENS; | ||
export declare const useENS: ({ provider, domain, fetchOptions, contractAddress, chainId }: UseENSOptions) => ResolvedENS; |
@@ -6,11 +6,9 @@ import { useState, useEffect } from 'react'; | ||
* A React hook to fetch ENS records from a domain. | ||
* @param provider Ethers.js provider | ||
* @param domain ENS domain to fetch data from | ||
* @returns | ||
*/ | ||
const useENS = ({ provider, domain, fetchOptions, contractAddress }) => { | ||
const useENS = ({ provider, domain, fetchOptions, contractAddress, chainId }) => { | ||
const [data, set] = useState({ address: null, owner: null, records: {}, domain: '' }); | ||
useEffect(() => { | ||
if (provider && domain) { | ||
provider.getNetwork().then(({ chainId }) => { | ||
if (provider && domain && data.address !== null) { | ||
if (chainId) { | ||
if (contractAddress || chainId === 1) { | ||
@@ -21,3 +19,12 @@ getENS(provider, contractAddress)(domain, fetchOptions).then((data) => { | ||
} | ||
}); | ||
} | ||
else { | ||
provider.getNetwork().then(({ chainId }) => { | ||
if (contractAddress || chainId === 1) { | ||
getENS(provider, contractAddress)(domain, fetchOptions).then((data) => { | ||
set(data); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -24,0 +31,0 @@ }, [contractAddress, domain, fetchOptions]); |
{ | ||
"name": "use-ens", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A React hook to fetch ENS records from a domain.", | ||
@@ -5,0 +5,0 @@ "files": [ |
3386
45