Skip to content

Commit

Permalink
Fix T22 Metadata Loadinng (#366)
Browse files Browse the repository at this point in the history
Closes #328
  • Loading branch information
ngundotra authored Aug 29, 2024
1 parent 7a9c150 commit e54adfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions app/providers/compressed-nft.tsx
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down

0 comments on commit e54adfb

Please sign in to comment.