Skip to content

Commit

Permalink
improve getNFTs behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Feb 26, 2024
1 parent 76d48ae commit ab035bd
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/thirdweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"test:watch": "vitest -c ./test/vitest.config.ts dev",
"test": "CI=true vitest -c ./test/vitest.config.ts --coverage --retry=3 --bail=1 --pool=forks",
"test:cov": "vitest dev -c ./test/vitest.config.ts --coverage",
"test:dev": "vitest dev -c ./test/vitest.config.ts",
"typedoc": "node scripts/typedoc.mjs",
"update-version": "node scripts/version.mjs"
},
Expand Down
22 changes: 19 additions & 3 deletions packages/thirdweb/src/extensions/erc721/read/getNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,34 @@ export async function getNFT(
options: BaseTransactionOptions<GetNFTParams>,
): Promise<NFT<"ERC721">> {
const [uri, owner] = await Promise.all([
tokenURI(options),
tokenURI(options).catch(() => null),
options.includeOwner
? import("./ownerOf.js").then((m) => m.ownerOf(options))
? import("./ownerOf.js").then((m) => m.ownerOf(options)).catch(() => null)
: null,
]);

if (!uri) {
return parseNFT(
{
id: options.tokenId,
type: "ERC721",
uri: "",
},
{
tokenId: options.tokenId,
tokenUri: "",
type: "ERC721",
owner,
},
);
}

return parseNFT(
await fetchTokenMetadata({
client: options.contract.client,
tokenId: options.tokenId,
tokenUri: uri,
}),
}).catch(() => {}),
{
tokenId: options.tokenId,
tokenUri: uri,
Expand Down
Loading

0 comments on commit ab035bd

Please sign in to comment.