Skip to content

Commit

Permalink
fix: resolves #2258
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed May 20, 2024
1 parent cd612fc commit 438ecff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-tools-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed hanging `waitForTransactionReceipt`
17 changes: 13 additions & 4 deletions src/actions/public/waitForTransactionReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export async function waitForTransactionReceipt<
): Promise<WaitForTransactionReceiptReturnType<TChain>> {
const observerId = stringify(['waitForTransactionReceipt', client.uid, hash])

let count = 0
let transaction: GetTransactionReturnType<TChain> | undefined
let replacedTransaction: GetTransactionReturnType<TChain> | undefined
let receipt: GetTransactionReceiptReturnType<TChain>
Expand All @@ -167,16 +168,22 @@ export async function waitForTransactionReceipt<
poll: true,
pollingInterval,
async onBlockNumber(blockNumber_) {
if (retrying) return

let blockNumber = blockNumber_

const done = (fn: () => void) => {
_unwatch()
fn()
_unobserve()
}

let blockNumber = blockNumber_

if (retrying) return
if (count > retryCount)
done(() =>
emit.reject(
new WaitForTransactionReceiptTimeoutError({ hash }),
),
)

try {
// If we already have a valid receipt, let's check if we have enough
// confirmations. If we do, then we can resolve.
Expand Down Expand Up @@ -325,6 +332,8 @@ export async function waitForTransactionReceipt<
} else {
done(() => emit.reject(err))
}
} finally {
count++
}
},
})
Expand Down

0 comments on commit 438ecff

Please sign in to comment.