From ba09ab17bd10a1aa5b2158f8ee170f0151cd5cee Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 13 Jan 2025 12:35:44 -0500 Subject: [PATCH] better download logic --- src/hooks/useDydxClient.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hooks/useDydxClient.tsx b/src/hooks/useDydxClient.tsx index 39ff646d3..c7109dd1d 100644 --- a/src/hooks/useDydxClient.tsx +++ b/src/hooks/useDydxClient.tsx @@ -47,6 +47,10 @@ export const DydxProvider = ({ ...props }) => ( export const useDydxClient = () => useContext(DydxContext); +const DEFAULT_PAGE_SIZE_TARGET = 1000; +// parallel requests should be limited to prevent hitting 429 errors and failing the whole operation +const DEFAULT_MAX_REQUESTS = 15; + const useDydxClientContext = () => { // ------ Network ------ // @@ -256,7 +260,7 @@ const useDydxClientContext = () => { subaccountNumber, undefined, undefined, - 100, + DEFAULT_PAGE_SIZE_TARGET, undefined, undefined, 1 @@ -268,7 +272,7 @@ const useDydxClientContext = () => { length: Math.ceil(totalResults / pageSize) - 1, }, (_, index) => index + 2 - ); + ).slice(0, DEFAULT_MAX_REQUESTS); const results = await Promise.all( pages.map((page) => @@ -277,7 +281,7 @@ const useDydxClientContext = () => { subaccountNumber, undefined, undefined, - 100, + pageSize, undefined, undefined, page @@ -306,7 +310,7 @@ const useDydxClientContext = () => { } = await indexerClient.account.getParentSubaccountNumberTransfers( address, subaccountNumber, - 100, + DEFAULT_PAGE_SIZE_TARGET, undefined, undefined, 1 @@ -318,14 +322,14 @@ const useDydxClientContext = () => { length: Math.ceil(totalResults / pageSize) - 1, }, (_, index) => index + 2 - ); + ).slice(0, DEFAULT_MAX_REQUESTS); const results = await Promise.all( pages.map((page) => indexerClient.account.getParentSubaccountNumberTransfers( address, subaccountNumber, - 100, + pageSize, undefined, undefined, page