From 716ec73478275b542edd3b27395c9b09c9c205a7 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 1 Mar 2022 23:51:22 -0300 Subject: [PATCH] Add eoa/contract legend support to trace page --- src/transaction/Trace.tsx | 7 ++++++- src/transaction/TraceInput.tsx | 23 +++++++++++++++++++---- src/transaction/TraceItem.tsx | 29 +++++++++++++++++------------ 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/transaction/Trace.tsx b/src/transaction/Trace.tsx index a04bcdb..5a2a4f9 100644 --- a/src/transaction/Trace.tsx +++ b/src/transaction/Trace.tsx @@ -24,7 +24,12 @@ const Trace: React.FC = ({ txData }) => {
{traces.map((t, i, a) => ( - + ))}
diff --git a/src/transaction/TraceInput.tsx b/src/transaction/TraceInput.tsx index 0524501..68cca6c 100644 --- a/src/transaction/TraceInput.tsx +++ b/src/transaction/TraceInput.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useContext, useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb"; import TransactionAddress from "../components/TransactionAddress"; @@ -6,18 +6,21 @@ import FormattedBalance from "../components/FormattedBalance"; import FunctionSignature from "./FunctionSignature"; import InputDecoder from "./decoder/InputDecoder"; import ExpanderSwitch from "../components/ExpanderSwitch"; -import { TraceEntry } from "../useErigonHooks"; +import { RuntimeContext } from "../useRuntime"; +import { TraceEntry, useHasCode } from "../useErigonHooks"; import { extract4Bytes, use4Bytes, useTransactionDescription, } from "../use4Bytes"; +import { TransactionData } from "../types"; type TraceInputProps = { t: TraceEntry; + txData: TransactionData; }; -const TraceInput: React.FC = ({ t }) => { +const TraceInput: React.FC = ({ t, txData }) => { const raw4Bytes = extract4Bytes(t.input); const fourBytes = use4Bytes(raw4Bytes); const sigText = @@ -32,6 +35,15 @@ const TraceInput: React.FC = ({ t }) => { const [expanded, setExpanded] = useState(false); + const { provider } = useContext(RuntimeContext); + const toHasCode = useHasCode( + provider, + t.to, + txData.confirmedData !== undefined + ? txData.confirmedData.blockNumber - 1 + : undefined + ); + return (
= ({ t }) => { ) : ( <> - + {t.type !== "CREATE" && t.type !== "CREATE2" && ( <> diff --git a/src/transaction/TraceItem.tsx b/src/transaction/TraceItem.tsx index d6a4d7d..5dd4a3d 100644 --- a/src/transaction/TraceItem.tsx +++ b/src/transaction/TraceItem.tsx @@ -5,13 +5,15 @@ import { faMinusSquare } from "@fortawesome/free-regular-svg-icons/faMinusSquare import { Switch } from "@headlessui/react"; import { TraceGroup } from "../useErigonHooks"; import TraceInput from "./TraceInput"; +import { TransactionData } from "../types"; type TraceItemProps = { t: TraceGroup; last: boolean; + txData: TransactionData; }; -const TraceItem: React.FC = ({ t, last }) => { +const TraceItem: React.FC = ({ t, last, txData }) => { const [expanded, setExpanded] = useState(true); return ( @@ -33,7 +35,7 @@ const TraceItem: React.FC = ({ t, last }) => { /> )} - +
{t.children && (
= ({ t, last }) => { expanded ? "" : "hidden" }`} > - +
)} @@ -50,16 +52,19 @@ const TraceItem: React.FC = ({ t, last }) => { type TraceChildrenProps = { c: TraceGroup[]; + txData: TransactionData; }; -const TraceChildren: React.FC = React.memo(({ c }) => { - return ( - <> - {c.map((tc, i, a) => ( - - ))} - - ); -}); +const TraceChildren: React.FC = React.memo( + ({ c, txData }) => { + return ( + <> + {c.map((tc, i, a) => ( + + ))} + + ); + } +); export default TraceItem;