diff --git a/src/state/multicall/updater.tsx b/src/state/multicall/updater.tsx index d94c25aed7..fec4e256ae 100644 --- a/src/state/multicall/updater.tsx +++ b/src/state/multicall/updater.tsx @@ -8,7 +8,7 @@ import { useMulticallContract } from 'hooks/useContract' import useDebounce from 'hooks/useDebounce' import { useBlockNumber } from 'state/application/hooks' import { AppDispatch, AppState } from 'state/index' -import chunkArray from 'utils/chunkArray' +import { chunk } from 'utils/array' import { CancelledError, RetryableError, retry } from 'utils/retry' import { @@ -177,7 +177,7 @@ export default function Updater(): null { if (outdatedCallKeys.length === 0) return const calls = outdatedCallKeys.map(key => parseCallKey(key)) - const chunkedCalls = chunkArray(calls, CALL_CHUNK_SIZE) + const chunkedCalls = chunk(calls, CALL_CHUNK_SIZE) if (cancellations.current?.blockNumber !== latestBlockNumber) { cancellations.current?.cancellations?.forEach(c => c()) diff --git a/src/utils/array.ts b/src/utils/array.ts index 2a348bbb9f..65153700ed 100644 --- a/src/utils/array.ts +++ b/src/utils/array.ts @@ -1,4 +1,5 @@ export const chunk = (arr: readonly T[], chunkSize: number): T[][] => { + if (chunkSize < 1) throw new Error('chunkSize must be gte 1') const result = [] for (let i = 0; i < arr.length; i += chunkSize) { result.push(arr.slice(i, i + chunkSize)) diff --git a/src/utils/chunkArray.ts b/src/utils/chunkArray.ts deleted file mode 100644 index 8dabba5806..0000000000 --- a/src/utils/chunkArray.ts +++ /dev/null @@ -1,11 +0,0 @@ -// chunks array into chunks of maximum size -// evenly distributes items among the chunks -export default function chunkArray(items: T[], maxChunkSize: number): T[][] { - if (maxChunkSize < 1) throw new Error('maxChunkSize must be gte 1') - if (items.length <= maxChunkSize) return [items] - - const numChunks: number = Math.ceil(items.length / maxChunkSize) - const chunkSize = Math.ceil(items.length / numChunks) - - return [...Array(numChunks).keys()].map(ix => items.slice(ix * chunkSize, ix * chunkSize + chunkSize)) -}