From cbcb7c57252def3bd7c6a07e1f8cef359f8d914b Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Tue, 23 Apr 2024 22:40:36 +0530 Subject: [PATCH 1/6] add generateStaticParam to blockexplorer [txHash] and [address] --- .../blockexplorer/address/[address]/page.tsx | 4 + .../transaction/[txHash]/page.tsx | 150 +----------------- .../_components/TransactionComp.tsx | 148 +++++++++++++++++ packages/nextjs/next.config.js | 1 + 4 files changed, 160 insertions(+), 143 deletions(-) create mode 100644 packages/nextjs/app/blockexplorer/transaction/_components/TransactionComp.tsx diff --git a/packages/nextjs/app/blockexplorer/address/[address]/page.tsx b/packages/nextjs/app/blockexplorer/address/[address]/page.tsx index dda48baf2..7e5567513 100644 --- a/packages/nextjs/app/blockexplorer/address/[address]/page.tsx +++ b/packages/nextjs/app/blockexplorer/address/[address]/page.tsx @@ -76,6 +76,10 @@ const getContractData = async (address: string) => { return { bytecode, assembly }; }; +export function generateStaticParams() { + return [{ address: "0x0000000000000000000000000000000000000000" }]; +} + const AddressPage = async ({ params }: PageProps) => { const address = params?.address as string; const contractData: { bytecode: string; assembly: string } | null = await getContractData(address); diff --git a/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx b/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx index f3e0431df..6f55ed3f3 100644 --- a/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx +++ b/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx @@ -1,153 +1,17 @@ -"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"; type PageProps = { params: { txHash?: Hash }; }; + +export function generateStaticParams() { + 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]); - - 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: - -