Skip to content

Commit 4e93539

Browse files
authored
SDK: Fallback to insight response if RPC request fails in getNFTs extensions (#7234)
1 parent f44d6ba commit 4e93539

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.changeset/shaggy-tables-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fallback to insight response if RPC request fails in ERC721 & ERC1155 `getNFTs` extension

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/marketplace-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export const MarketplaceTable: React.FC<MarketplaceTableProps> = ({
237237
</Th>
238238
))}
239239
{/* // Need to add an empty header for the drawer button */}
240-
<Th border="none" />
240+
<Th border="none" key="drawer" />
241241
</Tr>
242242
))}
243243
</Thead>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export const NFTGetAllTable: React.FC<ContractOverviewNFTGetAllProps> = ({
278278
</Th>
279279
))}
280280
{/* Need to add an empty header for the drawer button */}
281-
<Th border="none" />
281+
<Th border="none" key="drawer" />
282282
</Tr>
283283
))}
284284
</Thead>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ async function getNFTsFromInsight(
8484
Math.max(0, Number(supply) - currentOffset),
8585
);
8686
if (result.length < expectedResultLength) {
87-
// fresh contracts might be delayed in indexing, so we fallback to RPC
88-
return getNFTsFromRPC(options);
87+
try {
88+
// fresh contracts might be delayed in indexing, so we fallback to RPC
89+
// must use await here
90+
return await getNFTsFromRPC(options);
91+
} catch {
92+
// if RPC fails, we return the result from insight
93+
return result;
94+
}
8995
}
9096
return result;
9197
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ async function getNFTsFromInsight(
132132
),
133133
);
134134
if (result.length < expectedResultLength) {
135-
// fresh contracts might be delayed in indexing, so we fallback to RPC
136-
return getNFTsFromRPC(options);
135+
try {
136+
// fresh contracts might be delayed in indexing, so we fallback to RPC
137+
// must use await here
138+
return await getNFTsFromRPC(options);
139+
} catch {
140+
// if RPC fails, we return the result from insight
141+
return result;
142+
}
137143
}
138144

139145
return result;

0 commit comments

Comments
 (0)