"use client"; import { useEffect, useState } from "react"; import { PaginationButton, SearchBar, TransactionsTable } from "./_components"; import type { NextPage } from "next"; import { hardhat } from "viem/chains"; import { useFetchBlocks } from "~~/hooks/scaffold-eth"; import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; import { notification } from "~~/utils/scaffold-eth"; const BlockExplorer: NextPage = () => { const { blocks, transactionReceipts, currentPage, totalBlocks, setCurrentPage, error } = useFetchBlocks(); const { targetNetwork } = useTargetNetwork(); const [isLocalNetwork, setIsLocalNetwork] = useState(true); const [hasError, setHasError] = useState(false); useEffect(() => { if (targetNetwork.id !== hardhat.id) { setIsLocalNetwork(false); } }, [targetNetwork.id]); useEffect(() => { if (targetNetwork.id === hardhat.id && error) { setHasError(true); } }, [targetNetwork.id, error]); useEffect(() => { if (!isLocalNetwork) { notification.error( <>
targetNetwork is not localhost
- You are on {targetNetwork.name} .This
block explorer is only for localhost.
- You can use{" "} {targetNetwork.blockExplorers?.default.name} {" "} instead
>, ); } }, [ isLocalNetwork, targetNetwork.blockExplorers?.default.name, targetNetwork.blockExplorers?.default.url, targetNetwork.name, ]); useEffect(() => { if (hasError) { notification.error( <>Cannot connect to local provider
- Did you forget to run yarn chain ?
- Or you can change targetNetwork in{" "}
scaffold.config.ts