From 24f0c8251b4dd3c6b0433ecfecbc56ef708c5a78 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Mon, 11 Nov 2024 07:42:33 +0000 Subject: [PATCH] fix(explorer): get block when transaction hashes are missing (#3369) --- .../[worldAddress]/observe/TransactionsWatcher.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx index a4d31bfe5c..e61e3ff8d0 100644 --- a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx +++ b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx @@ -12,7 +12,7 @@ import { } from "viem"; import { UserOperation, entryPoint07Abi, entryPoint07Address } from "viem/account-abstraction"; import { useConfig, useWatchBlocks } from "wagmi"; -import { getTransaction, simulateContract, waitForTransactionReceipt } from "wagmi/actions"; +import { getBlock, getTransaction, simulateContract, waitForTransactionReceipt } from "wagmi/actions"; import { useStore } from "zustand"; import { useCallback, useEffect } from "react"; import { store as observerStore } from "../../../../../../observer/store"; @@ -218,13 +218,17 @@ export function TransactionsWatcher() { }, [handleTransaction, observerWrites, transactions, worldAddress]); useWatchBlocks({ - onBlock(block) { - for (const hash of block.transactions) { + chainId, + async onBlock(block) { + // workaround for https://github.com/wevm/viem/issues/2995 + // TODO: remove once fixed and we upgrade viem + const blockTxs = + block.transactions ?? (await getBlock(wagmiConfig, { chainId, blockHash: block.hash })).transactions; + for (const hash of blockTxs) { if (transactions.find((transaction) => transaction.hash === hash)) continue; handleTransaction({ hash, timestamp: block.timestamp }); } }, - chainId, }); return null;