-
Notifications
You must be signed in to change notification settings - Fork 23
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
Submit transactions in bulk #219
Conversation
6833341
to
b0c736a
Compare
ea475e3
to
56a97c1
Compare
d5d5da1
to
7a89736
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job I left a few comments but I can have another look later. Let me know.
packages/api/src/submitTransactionsBulk/submitTransactionsBulk.ts
Outdated
Show resolved
Hide resolved
packages/extension/src/contexts/LedgerContext/LedgerContext.tsx
Outdated
Show resolved
Hide resolved
}; | ||
|
||
const results: TransactionBulkResponse[] = []; | ||
for (const tx of payload.transactions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop will send the requests one by one which is slow.
Have you thought about using Promise.all
or Promise.allSettled()
to send them in parallel and make the whole process faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with Promise.all
but it was only really submitting the first transaction of each batch. My assumption was that I needed to throttle
packages/extension/src/contexts/LedgerContext/LedgerContext.tsx
Outdated
Show resolved
Hide resolved
}); | ||
}; | ||
|
||
export const loadFromChromeLocalStorage = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about sth like this? You can also implement your delete logic
/**
* Retrieve an item from the local storage.
*
* @param {string} key
* @returns Any value.
*/
export const getLocalStorageItem = <T = unknown>(
key: string,
): T | undefined => {
const value = localStorage.getItem(key)
if (value === null || value === 'undefined') {
return undefined
}
try {
return JSON.parse(value) as T
} catch (_err) {
return value as unknown as T
}
}
3c78650
to
c47d0b3
Compare
a4734a0
to
1ff76bc
Compare
28cf7f9
to
7a68728
Compare
26cea1e
to
546ff07
Compare
noWait (boolean)
andonError (string)
in the submitTransactionsBulk route to control if we want to wait for the tx hashes or not, and if we want to continue or abort when one tx fails