Skip to content

SDK: Fallback to insight response if RPC request fails in getNFTs extensions #7234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
5 changes: 5 additions & 0 deletions .changeset/shaggy-tables-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fallback to insight response if RPC request fails in ERC721 & ERC1155 `getNFTs` extension
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const MarketplaceTable: React.FC<MarketplaceTableProps> = ({
</Th>
))}
{/* // Need to add an empty header for the drawer button */}
<Th border="none" />
<Th border="none" key="drawer" />
</Tr>
))}
</Thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const NFTGetAllTable: React.FC<ContractOverviewNFTGetAllProps> = ({
</Th>
))}
{/* Need to add an empty header for the drawer button */}
<Th border="none" />
<Th border="none" key="drawer" />
</Tr>
))}
</Thead>
Expand Down
10 changes: 8 additions & 2 deletions packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@
Math.max(0, Number(supply) - currentOffset),
);
if (result.length < expectedResultLength) {
// fresh contracts might be delayed in indexing, so we fallback to RPC
return getNFTsFromRPC(options);
try {

Check warning on line 87 in packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts#L87

Added line #L87 was not covered by tests
// fresh contracts might be delayed in indexing, so we fallback to RPC
// must use await here
return await getNFTsFromRPC(options);
} catch {

Check warning on line 91 in packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts#L90-L91

Added lines #L90 - L91 were not covered by tests
// if RPC fails, we return the result from insight
return result;
}

Check warning on line 94 in packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/getNFTs.ts#L93-L94

Added lines #L93 - L94 were not covered by tests
}
return result;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/thirdweb/src/extensions/erc721/read/getNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@
),
);
if (result.length < expectedResultLength) {
// fresh contracts might be delayed in indexing, so we fallback to RPC
return getNFTsFromRPC(options);
try {

Check warning on line 135 in packages/thirdweb/src/extensions/erc721/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/getNFTs.ts#L135

Added line #L135 was not covered by tests
// fresh contracts might be delayed in indexing, so we fallback to RPC
// must use await here
return await getNFTsFromRPC(options);
} catch {

Check warning on line 139 in packages/thirdweb/src/extensions/erc721/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/getNFTs.ts#L138-L139

Added lines #L138 - L139 were not covered by tests
// if RPC fails, we return the result from insight
return result;
}

Check warning on line 142 in packages/thirdweb/src/extensions/erc721/read/getNFTs.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/getNFTs.ts#L141-L142

Added lines #L141 - L142 were not covered by tests
}

return result;
Expand Down
Loading