Skip to content

Commit

Permalink
rewrite to async await for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Jan 28, 2024
1 parent 9339e99 commit 6178656
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ export function waitForReceipt<abi extends Abi>({
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)
Expand Down

0 comments on commit 6178656

Please sign in to comment.