From e54adfb28e192893a28745a3c3732bcb8d024418 Mon Sep 17 00:00:00 2001 From: Noah Gundotra Date: Wed, 28 Aug 2024 23:13:46 -0400 Subject: [PATCH] Fix T22 Metadata Loadinng (#366) Closes #328 --- app/address/[address]/layout.tsx | 4 ++-- app/providers/compressed-nft.tsx | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/address/[address]/layout.tsx b/app/address/[address]/layout.tsx index 8d212a91..172b30d5 100644 --- a/app/address/[address]/layout.tsx +++ b/app/address/[address]/layout.tsx @@ -364,10 +364,10 @@ function Token22MintHeader({ }) { const tokenMetadata = create(metadataExtension.state, TokenMetadata); const { metadataAddress } = create(metadataPointerExtension.state, MetadataPointer); - const metadata = useMetadataJsonLink(tokenMetadata.uri); + const metadata = useMetadataJsonLink(tokenMetadata.uri, { suspense: true }); if (!metadata) { - throw new Error('Could not load metadata from given URI'); + throw new Error(`Could not load metadata from given URI: ${tokenMetadata.uri}`); } // Handles the basic case where MetadataPointer is referencing the Token Metadata extension directly diff --git a/app/providers/compressed-nft.tsx b/app/providers/compressed-nft.tsx index d118daa8..feb45e4f 100644 --- a/app/providers/compressed-nft.tsx +++ b/app/providers/compressed-nft.tsx @@ -1,9 +1,13 @@ import useSWRImmutable from 'swr/immutable'; -export function useMetadataJsonLink(url: string) { - const { data, error } = useSWRImmutable(url, async (url: string) => { - return fetch(url).then(response => response.json()); - }); +export function useMetadataJsonLink(url: string, options?: { suspense?: boolean }) { + const { data, error } = useSWRImmutable( + url, + async (url: string) => { + return fetch(url).then(response => response.json()); + }, + { suspense: options?.suspense } + ); return error ? null : data; }