Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-yaks-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Tweaked `watchBlockNumber` to work with genesis blocks
7 changes: 5 additions & 2 deletions src/actions/public/watchBlockNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function watchBlockNumber<
'getBlockNumber',
)({ cacheTime: 0 })

if (prevBlockNumber) {
if (prevBlockNumber !== undefined) {
// If the current block number is the same as the previous,
// we can skip.
if (blockNumber === prevBlockNumber) return
Expand All @@ -145,7 +145,10 @@ export function watchBlockNumber<

// If the next block number is greater than the previous,
// it is not in the past, and we can emit the new block number.
if (!prevBlockNumber || blockNumber > prevBlockNumber) {
if (
prevBlockNumber === undefined ||
blockNumber > prevBlockNumber
) {
emit.onBlockNumber(blockNumber, prevBlockNumber)
prevBlockNumber = blockNumber
}
Expand Down
Loading