From 8c092d3ef9d9a0ee48f241212b75f0610c5c9e9d Mon Sep 17 00:00:00 2001 From: thibautbremand Date: Thu, 10 Aug 2023 11:38:35 +0200 Subject: [PATCH] Force sequential handling of bulk transactions --- .../contexts/LedgerContext/LedgerContext.tsx | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/extension/src/contexts/LedgerContext/LedgerContext.tsx b/packages/extension/src/contexts/LedgerContext/LedgerContext.tsx index 8e3b97dad..927f5d19c 100644 --- a/packages/extension/src/contexts/LedgerContext/LedgerContext.tsx +++ b/packages/extension/src/contexts/LedgerContext/LedgerContext.tsx @@ -804,6 +804,11 @@ const LedgerProvider: FC = ({ children }) => { ? await client.submit(signed.tx_blob) : await client.submitAndWait(signed.tx_blob); + if (payload.parallelize) { + // Throttle the requests + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + // Check transaction result if (payload.parallelize && !(tx as SubmitResponse).result.accepted) { throw new Error("Couldn't submit the transaction"); @@ -831,19 +836,17 @@ const LedgerProvider: FC = ({ children }) => { } }; - const results = await (payload.parallelize - ? Promise.all(payload.transactions.map((tx) => processTransaction(tx))) - : (async () => { - const sequentialResults = []; - for (const tx of payload.transactions) { - const result = await processTransaction(tx); - sequentialResults.push(result); - if (result.error && onError === 'abort') { - return sequentialResults; - } - } - return sequentialResults; - })()); + const results = await (async () => { + const results = []; + for (const tx of payload.transactions) { + const result = await processTransaction(tx); + results.push(result); + if (result.error && onError === 'abort') { + return results; + } + } + return results; + })(); const hasError = results.some((r) => r.error);