From 61786562e3dda59d39544a39189d408aa6d59932 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Sun, 28 Jan 2024 04:57:58 -0800 Subject: [PATCH] rewrite to async await for readability --- .../actions/wait-for-tx-receipt.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts b/packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts index 7b4558a56df..9fef1179070 100644 --- a/packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts +++ b/packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts @@ -41,24 +41,23 @@ export function waitForReceipt({ const unwatch = watchBlockNumber({ client: contract.client, chainId: contract.chainId, - onNewBlockNumber: () => { + onNewBlockNumber: async () => { blocksWaited++; if (blocksWaited >= MAX_BLOCKS_WAIT_TIME) { unwatch(); reject(new Error("Transaction not found after 10 blocks")); } - eth_getTransactionReceipt(request, { - hash: transactionHash as Hex, - }) - .then((receipt) => { - if (receipt) { - unwatch(); - return resolve(receipt); - } - }) - .catch(() => { - // noop, we'll try again on the next blocks + try { + const receipt = eth_getTransactionReceipt(request, { + hash: transactionHash as Hex, }); + if (receipt) { + unwatch(); + return resolve(receipt); + } + } catch { + // noop, we'll try again on the next blocks + } }, }); // remove the promise from the map when it's done (one way or the other)