Skip to content

Commit

Permalink
[txHash].tsx page UI improvements (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
portdeveloper committed Jul 13, 2023
1 parent f454542 commit 12303f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions packages/nextjs/hooks/scaffold-eth/useFetchBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react";
import { Block, Transaction, TransactionReceipt } from "viem";
import { usePublicClient } from "wagmi";
import { hardhat } from "wagmi/chains";
import { decodeTransactionData } from "~~/utils/scaffold-eth";

const BLOCKS_PER_PAGE = 20;

Expand Down Expand Up @@ -41,6 +42,10 @@ export const useFetchBlocks = () => {
});
const fetchedBlocks = await Promise.all(blocksWithTransactions);

fetchedBlocks.forEach(block => {
block.transactions.forEach(tx => decodeTransactionData(tx as Transaction));
});

const txReceipts = await Promise.all(
fetchedBlocks.flatMap(block =>
block.transactions.map(async tx => {
Expand Down Expand Up @@ -74,6 +79,8 @@ export const useFetchBlocks = () => {
if (currentPage === 0) {
setBlocks(prevBlocks => [newBlock, ...prevBlocks.slice(0, BLOCKS_PER_PAGE - 1)]);

newBlock.transactions.forEach(tx => decodeTransactionData(tx as Transaction));

const receipts = await Promise.all(
newBlock.transactions.map(async tx => {
try {
Expand Down
22 changes: 12 additions & 10 deletions packages/nextjs/pages/blockexplorer/transaction/[txHash].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const TransactionPage: NextPage = () => {
Back
</button>
{transaction ? (
<div className="overflow-x-auto">
<div>
<h2 className="text-3xl font-bold mb-4 text-center text-primary-content">Transaction Details</h2>{" "}
<table className="table w-full shadow-lg">
<tbody>
Expand Down Expand Up @@ -94,14 +94,16 @@ const TransactionPage: NextPage = () => {
<strong>Function called:</strong>
</td>
<td>
{functionCalled === "0x" ? (
"This transaction did not call any function."
) : (
<>
<span className="mr-2">{getFunctionDetails(transaction)}</span>
<span className="badge badge-primary font-bold">{functionCalled}</span>
</>
)}
<div className="w-full md:max-w-[600px] lg:max-w-[800px] overflow-x-auto whitespace-nowrap">
{functionCalled === "0x" ? (
"This transaction did not call any function."
) : (
<>
<span className="mr-2">{getFunctionDetails(transaction)}</span>
<span className="badge badge-primary font-bold">{functionCalled}</span>
</>
)}
</div>
</td>
</tr>
<tr>
Expand All @@ -115,7 +117,7 @@ const TransactionPage: NextPage = () => {
<strong>Data:</strong>
</td>
<td className="form-control">
<textarea readOnly value={transaction.input} className="p-0 textarea-primary bg-inherit" />
<textarea readOnly value={transaction.input} className="p-0 textarea-primary bg-inherit h-[150px]" />
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/utils/scaffold-eth/decodeTxData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getFunctionDetails = (transaction: TransactionType) => {
transaction.functionArgs
) {
const details = transaction.functionArgNames.map(
(name, i) => `${transaction.functionArgTypes?.[i] || ""} ${name} = ${transaction.functionArgs?.[i] || ""}`,
(name, i) => `${transaction.functionArgTypes?.[i] || ""} ${name} = ${transaction.functionArgs?.[i] ?? ""}`,
);
return `${transaction.functionName}(${details.join(", ")})`;
}
Expand Down

0 comments on commit 12303f8

Please sign in to comment.