diff --git a/packages/nextjs/app/blockexplorer/page.tsx b/packages/nextjs/app/blockexplorer/page.tsx index 80f481cac..61e6fc6de 100644 --- a/packages/nextjs/app/blockexplorer/page.tsx +++ b/packages/nextjs/app/blockexplorer/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { PaginationButton, SearchBar, TransactionsTable } from "./_components"; import type { NextPage } from "next"; import { hardhat } from "viem/chains"; @@ -11,24 +11,23 @@ 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) { - notification.error( - <> -
Cannot connect to local provider
-
- - Did you forget to run yarn chain
?
-
- - Or you can change targetNetwork
in{" "}
- scaffold.config.ts
-
@@ -48,7 +47,29 @@ const BlockExplorer: NextPage = () => { >, ); } - }, [error, targetNetwork]); + }, [ + 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
+