Skip to content

Commit

Permalink
fix(explorer): get block when transaction hashes are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Nov 11, 2024
1 parent f5f772b commit e1f4d5a
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e1f4d5a

Please sign in to comment.