diff --git a/lib/hooks/useArweaveAddress.tsx b/lib/hooks/useArweaveAddress.tsx index 05fd3c6ff2..f06027d4bf 100644 --- a/lib/hooks/useArweaveAddress.tsx +++ b/lib/hooks/useArweaveAddress.tsx @@ -9,6 +9,7 @@ interface Props { const useArweaveAddress = ({ addressHash }: Props) => { const { data, isLoading } = useLambdaState(addressHash); const [ arweaveAddress, setArweaveAddress ] = useState(null); + const [ ANS, setANS ] = useState(null); // eslint-disable-next-line @typescript-eslint/no-explicit-any const searchArksByKey = (state: any, ethereumAddress: string) => { @@ -27,18 +28,40 @@ const useArweaveAddress = ({ addressHash }: Props) => { } }; + async function resolveANS(arweaveAddress: string) { + try { + if (!arweaveAddress) return null; + const ANS_RESOLVER_URL = 'https://ans-resolver.herokuapp.com/resolve/'; + const response = await fetch(`${ ANS_RESOLVER_URL }${ arweaveAddress }`); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json() as { domain: string }; + console.log(data ) + return data; + } catch (e) { + console.log((e as Error).message); + return null; + } + } + + useEffect(() => { const fetchArweaveAddress = async() => { if (addressHash && data) { const result = searchArksByKey(data, addressHash); - setArweaveAddress(result ? result.arweaveLinkings : null); + const arweaveAddress = result ? result.arweaveLinkings : null; + setArweaveAddress(arweaveAddress); + resolveANS(arweaveAddress).then((data) => { + if (data?.domain) setANS(data.domain); + }); } }; fetchArweaveAddress(); }, [ addressHash, data ]); - return { arweaveAddress, isLoading }; + return { arweaveAddress, ANS, isLoading }; }; export default useArweaveAddress; diff --git a/lib/hooks/useLambdaState.tsx b/lib/hooks/useLambdaState.tsx index 1c476371c4..9f2e0d8b95 100644 --- a/lib/hooks/useLambdaState.tsx +++ b/lib/hooks/useLambdaState.tsx @@ -8,7 +8,11 @@ export function useLambdaState(addressHash: string) { return null; } - const response = await fetch(`https://ark-lambda-api.vercel.app/api/ark-lambda/eth-info?hash=${ addressHash.toLowerCase() }`); + const response = await fetch(`https://ark-lambda-api.vercel.app/api/ark-lambda/eth-info?hash=${ addressHash.toLowerCase() }`, { + headers: { + 'Cache-Control': 'no-cache', + }, + }); if (!response.ok) { throw new Error('Network response was not ok'); } diff --git a/nextjs/csp/policies/ad.ts b/nextjs/csp/policies/ad.ts index 0431d54144..e77965b1b3 100644 --- a/nextjs/csp/policies/ad.ts +++ b/nextjs/csp/policies/ad.ts @@ -12,6 +12,7 @@ export function ad(): CspDev.DirectiveDescriptor { 'coinzilla.com', '*.coinzilla.com', 'https://ark-lambda-api.vercel.app', + 'https://ans-resolver.herokuapp.com/resolve/', 'https://ark-lambda-api.vercel.app/api', 'https://request-global.czilladx.com', diff --git a/ui/address/AddressDetails.tsx b/ui/address/AddressDetails.tsx index 9087e351e0..daa5be991c 100644 --- a/ui/address/AddressDetails.tsx +++ b/ui/address/AddressDetails.tsx @@ -35,7 +35,7 @@ const AddressDetails = ({ addressQuery, scrollRef }: Props) => { const router = useRouter(); const addressHash = getQueryParamString(router.query.hash); - const { arweaveAddress, isLoading: loadingArweaveAddress } = useArweaveAddress({ addressHash }); + const { arweaveAddress, ANS, isLoading: loadingArweaveAddress } = useArweaveAddress({ addressHash }); const countersQuery = useAddressCountersQuery({ hash: addressHash, @@ -196,7 +196,7 @@ const AddressDetails = ({ addressQuery, scrollRef }: Props) => { - { arweaveAddress } + { ANS || arweaveAddress }