diff --git a/package.json b/package.json index 3e026f114..678ba343c 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "next:format": "yarn workspace @se-2/nextjs format", "next:check-types": "yarn workspace @se-2/nextjs check-types", "next:build": "yarn workspace @se-2/nextjs build", + "next:serve": "yarn workspace @se-2/nextjs serve", "postinstall": "husky install", "precommit": "lint-staged", "vercel": "yarn workspace @se-2/nextjs vercel", diff --git a/packages/nextjs/app/blockexplorer/address/[address]/page.tsx b/packages/nextjs/app/blockexplorer/address/[address]/page.tsx index dda48baf2..85a30d049 100644 --- a/packages/nextjs/app/blockexplorer/address/[address]/page.tsx +++ b/packages/nextjs/app/blockexplorer/address/[address]/page.tsx @@ -3,6 +3,7 @@ import path from "path"; import { hardhat } from "viem/chains"; import { AddressComponent } from "~~/app/blockexplorer/_components/AddressComponent"; import deployedContracts from "~~/contracts/deployedContracts"; +import { isZeroAddress } from "~~/utils/scaffold-eth/common"; import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; type PageProps = { @@ -76,8 +77,16 @@ const getContractData = async (address: string) => { return { bytecode, assembly }; }; +export function generateStaticParams() { + // An workaround to enable static exports in Next.js, generating single dummy page. + return [{ address: "0x0000000000000000000000000000000000000000" }]; +} + const AddressPage = async ({ params }: PageProps) => { const address = params?.address as string; + + if (isZeroAddress(address)) return null; + const contractData: { bytecode: string; assembly: string } | null = await getContractData(address); return ; }; diff --git a/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx b/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx index f3e0431df..3a49def6e 100644 --- a/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx +++ b/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx @@ -1,153 +1,22 @@ -"use client"; - -import { useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; +import TransactionComp from "../_components/TransactionComp"; import type { NextPage } from "next"; -import { Hash, Transaction, TransactionReceipt, formatEther, formatUnits } from "viem"; -import { hardhat } from "viem/chains"; -import { usePublicClient } from "wagmi"; -import { Address } from "~~/components/scaffold-eth"; -import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; -import { decodeTransactionData, getFunctionDetails } from "~~/utils/scaffold-eth"; -import { replacer } from "~~/utils/scaffold-eth/common"; +import { Hash } from "viem"; +import { isZeroAddress } from "~~/utils/scaffold-eth/common"; type PageProps = { params: { txHash?: Hash }; }; + +export function generateStaticParams() { + // An workaround to enable static exports in Next.js, generating single dummy page. + return [{ txHash: "0x0000000000000000000000000000000000000000" }]; +} const TransactionPage: NextPage = ({ params }: PageProps) => { - const client = usePublicClient({ chainId: hardhat.id }); const txHash = params?.txHash as Hash; - const router = useRouter(); - const [transaction, setTransaction] = useState(); - const [receipt, setReceipt] = useState(); - const [functionCalled, setFunctionCalled] = useState(); - - const { targetNetwork } = useTargetNetwork(); - - useEffect(() => { - if (txHash && client) { - const fetchTransaction = async () => { - const tx = await client.getTransaction({ hash: txHash }); - const receipt = await client.getTransactionReceipt({ hash: txHash }); - - const transactionWithDecodedData = decodeTransactionData(tx); - setTransaction(transactionWithDecodedData); - setReceipt(receipt); - - const functionCalled = transactionWithDecodedData.input.substring(0, 10); - setFunctionCalled(functionCalled); - }; - fetchTransaction(); - } - }, [client, txHash]); + if (isZeroAddress(txHash)) return null; - return ( -
- - {transaction ? ( -
-

Transaction Details

{" "} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Transaction Hash: - {transaction.hash}
- Block Number: - {Number(transaction.blockNumber)}
- From: - -
-
- To: - - {!receipt?.contractAddress ? ( - transaction.to &&
- ) : ( - - Contract Creation: -
- - )} -
- Value: - - {formatEther(transaction.value)} {targetNetwork.nativeCurrency.symbol} -
- Function called: - -
- {functionCalled === "0x" ? ( - "This transaction did not call any function." - ) : ( - <> - {getFunctionDetails(transaction)} - {functionCalled} - - )} -
-
- Gas Price: - {formatUnits(transaction.gasPrice || 0n, 9)} Gwei
- Data: - -