Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better tx/transfer download logic #1424

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/hooks/useDydxClient.tsx
Original file line number Diff line number Diff line change
@@ -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 = 20;

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
Loading