diff --git a/packages/react-token-streams/src/hooks/useStreamTokensInCustody.ts b/packages/react-token-streams/src/hooks/useStreamTokensInCustody.ts index 3e28abdf..b913840d 100644 --- a/packages/react-token-streams/src/hooks/useStreamTokensInCustody.ts +++ b/packages/react-token-streams/src/hooks/useStreamTokensInCustody.ts @@ -111,8 +111,24 @@ export const useStreamTokensInCustody = (config: Config) => { setIsLoading(true); const finalData: BigNumberish[] = []; - // Enumerate allTokensInCustody first - if (allTokensInCustody && allTokensInCustody.length < 1000) { + // Enumerate to 20,000 + const custodyStatusesPromises = []; + + for ( + let i = 0, l = Number(totalSupply?.toString() || 20_000); + i <= l; + i = i + 500 + ) { + custodyStatusesPromises.push(fetchTokensInCustodyInRange(i, i + 500)); + } + + for (const tokens of await Promise.all(custodyStatusesPromises)) { + if (tokens && tokens.length) { + finalData.push(...tokens); + } + } + + if (!finalData.length && allTokensInCustody) { const custodyStatuses = await Promise.all( allTokensInCustody.map((token) => contract.tokensInCustody( @@ -130,25 +146,6 @@ export const useStreamTokensInCustody = (config: Config) => { finalData.push(allTokensInCustody[i].tokenId); } } - } else { - // Otherwise enumerate to 20,000 - const custodyStatusesPromises = []; - - for ( - let i = 0, l = Number(totalSupply?.toString() || 20000); - i <= l; - i = i + 500 - ) { - custodyStatusesPromises.push( - fetchTokensInCustodyInRange(i, i + 500), - ); - } - - for (const tokens of await Promise.all(custodyStatusesPromises)) { - if (tokens && tokens.length) { - finalData.push(...tokens); - } - } } setData(finalData);