From 41da09101b8a82ad88798ea451f635d9c5ecfeb5 Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Fri, 15 Dec 2023 08:21:59 -0500 Subject: [PATCH] feat: loop queries better --- frontend/src/hooks/useAllMintedNFTsFromCollection.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useAllMintedNFTsFromCollection.tsx b/frontend/src/hooks/useAllMintedNFTsFromCollection.tsx index 92845cc..f85df89 100644 --- a/frontend/src/hooks/useAllMintedNFTsFromCollection.tsx +++ b/frontend/src/hooks/useAllMintedNFTsFromCollection.tsx @@ -7,12 +7,12 @@ import { AllianceContractConfig } from "config" const fetchNFTs = async ( lcd: LCDClient, contractAddresses: AllianceContractConfig, - start_after: number + start_after: string ): Promise => { return lcd.wasm .contractQuery(contractAddresses.collection, { all_tokens: { - start_after: start_after.toString(), + start_after: start_after, limit: 100, }, }) @@ -26,7 +26,7 @@ const fetchNFTs = async ( const fetchAllNFTs = async ( lcd: LCDClient, contractAddresses: AllianceContractConfig, - startAfter: number = 0, + startAfter: string = "", allNFTs: string[] = [] ): Promise => { const response = await fetchNFTs(lcd, contractAddresses, startAfter) @@ -35,8 +35,10 @@ const fetchAllNFTs = async ( allNFTs = [...allNFTs, ...tokens] if (tokens.length === 100) { - return fetchAllNFTs(lcd, contractAddresses, startAfter + 100, allNFTs) + const lastToken = tokens[tokens.length - 1] + return fetchAllNFTs(lcd, contractAddresses, lastToken, allNFTs) } + return allNFTs.sort((a, b) => parseInt(a, 10) - parseInt(b, 10)) }