Skip to content

Commit

Permalink
better download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Jan 13, 2025
1 parent fcb8990 commit ba09ab1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/hooks/useDydxClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------ //

Expand Down Expand Up @@ -256,7 +260,7 @@ const useDydxClientContext = () => {
subaccountNumber,
undefined,
undefined,
100,
DEFAULT_PAGE_SIZE_TARGET,
undefined,
undefined,
1
Expand All @@ -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) =>
Expand All @@ -277,7 +281,7 @@ const useDydxClientContext = () => {
subaccountNumber,
undefined,
undefined,
100,
pageSize,
undefined,
undefined,
page
Expand Down Expand Up @@ -306,7 +310,7 @@ const useDydxClientContext = () => {
} = await indexerClient.account.getParentSubaccountNumberTransfers(
address,
subaccountNumber,
100,
DEFAULT_PAGE_SIZE_TARGET,
undefined,
undefined,
1
Expand All @@ -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
Expand Down

0 comments on commit ba09ab1

Please sign in to comment.