Skip to content

Commit

Permalink
feat: loop queries better
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmerz committed Dec 15, 2023
1 parent 3ef79f5 commit 41da091
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/hooks/useAllMintedNFTsFromCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { AllianceContractConfig } from "config"
const fetchNFTs = async (
lcd: LCDClient,
contractAddresses: AllianceContractConfig,
start_after: number
start_after: string
): Promise<TokensResponse> => {
return lcd.wasm
.contractQuery<TokensResponse>(contractAddresses.collection, {
all_tokens: {
start_after: start_after.toString(),
start_after: start_after,
limit: 100,
},
})
Expand All @@ -26,7 +26,7 @@ const fetchNFTs = async (
const fetchAllNFTs = async (
lcd: LCDClient,
contractAddresses: AllianceContractConfig,
startAfter: number = 0,
startAfter: string = "",
allNFTs: string[] = []
): Promise<string[]> => {
const response = await fetchNFTs(lcd, contractAddresses, startAfter)
Expand All @@ -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))
}

Expand Down

0 comments on commit 41da091

Please sign in to comment.