Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/thirdweb/src/extensions/erc1155/read/getNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,23 @@ async function getNFTFromRPC(
client: options.contract.client,
tokenId: options.tokenId,
tokenUri,
}).catch(() => ({
id: options.tokenId,
type: "ERC1155",
uri: tokenUri,
})),
})
.then((metadata) => {
// if the metadata is null-ish, return a default metadata object
if (!metadata) {
return {
id: options.tokenId,
type: "ERC1155",
uri: tokenUri,
};
}
return metadata;
})
.catch(() => ({
id: options.tokenId,
type: "ERC1155",
uri: tokenUri,
})),
{
chainId: options.contract.chain.id,
owner: null,
Expand Down
12 changes: 3 additions & 9 deletions packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@ export async function getNFTs(
const { useIndexer = true } = options;
if (useIndexer) {
try {
return await getNFTsFromInsight(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromInsight(options);
} catch {
return await getNFTsFromRPC(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromRPC(options);
}
}
return await getNFTsFromRPC(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromRPC(options);
}

async function getNFTsFromInsight(
Expand Down
22 changes: 17 additions & 5 deletions packages/thirdweb/src/extensions/erc721/read/getNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,23 @@ async function getNFTFromRPC(
client: options.contract.client,
tokenId,
tokenUri: uri,
}).catch(() => ({
id: tokenId,
type: "ERC721",
uri,
})),
})
.then((metadata) => {
// if the metadata is null-ish, return a default metadata object
if (!metadata) {
return {
id: tokenId,
type: "ERC721",
uri,
};
}
return metadata;
})
.catch(() => ({
id: tokenId,
type: "ERC721",
uri,
})),
{
chainId: options.contract.chain.id,
owner,
Expand Down
12 changes: 3 additions & 9 deletions packages/thirdweb/src/extensions/erc721/read/getNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,12 @@ export async function getNFTs(
const { useIndexer = true } = options;
if (useIndexer) {
try {
return await getNFTsFromInsight(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromInsight(options);
} catch {
return await getNFTsFromRPC(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromRPC(options);
}
}
return await getNFTsFromRPC(options).then((nfts) =>
nfts.filter((nft) => nft?.id !== undefined && nft?.id !== null),
);
return await getNFTsFromRPC(options);
}

/**
Expand Down
Loading