2022-03-24 18:20:54 +00:00
|
|
|
import React, { useState } from "react";
|
2021-11-21 11:52:37 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb";
|
2021-11-07 20:46:42 +00:00
|
|
|
import TransactionAddress from "../components/TransactionAddress";
|
2021-11-06 05:12:37 +00:00
|
|
|
import FormattedBalance from "../components/FormattedBalance";
|
|
|
|
import FunctionSignature from "./FunctionSignature";
|
2021-11-08 11:28:28 +00:00
|
|
|
import InputDecoder from "./decoder/InputDecoder";
|
2021-12-13 18:41:37 +00:00
|
|
|
import ExpanderSwitch from "../components/ExpanderSwitch";
|
2022-03-24 18:20:54 +00:00
|
|
|
import { TraceEntry } from "../useErigonHooks";
|
2021-11-06 18:54:34 +00:00
|
|
|
import {
|
|
|
|
extract4Bytes,
|
2021-12-19 00:13:35 +00:00
|
|
|
use4Bytes,
|
2021-11-06 18:54:34 +00:00
|
|
|
useTransactionDescription,
|
|
|
|
} from "../use4Bytes";
|
2022-03-02 02:51:22 +00:00
|
|
|
import { TransactionData } from "../types";
|
2021-11-06 05:12:37 +00:00
|
|
|
|
|
|
|
type TraceInputProps = {
|
|
|
|
t: TraceEntry;
|
2022-03-02 02:51:22 +00:00
|
|
|
txData: TransactionData;
|
2021-11-06 05:12:37 +00:00
|
|
|
};
|
|
|
|
|
2022-03-02 02:51:22 +00:00
|
|
|
const TraceInput: React.FC<TraceInputProps> = ({ t, txData }) => {
|
2021-11-06 05:12:37 +00:00
|
|
|
const raw4Bytes = extract4Bytes(t.input);
|
2021-12-19 00:13:35 +00:00
|
|
|
const fourBytes = use4Bytes(raw4Bytes);
|
2021-11-06 05:12:37 +00:00
|
|
|
const sigText =
|
2021-11-06 18:54:34 +00:00
|
|
|
raw4Bytes === null ? "<fallback>" : fourBytes?.name ?? raw4Bytes;
|
|
|
|
const hasParams = t.input.length > 10;
|
|
|
|
|
|
|
|
const fourBytesTxDesc = useTransactionDescription(
|
|
|
|
fourBytes,
|
|
|
|
t.input,
|
|
|
|
t.value
|
|
|
|
);
|
|
|
|
|
|
|
|
const [expanded, setExpanded] = useState<boolean>(false);
|
2021-11-06 05:12:37 +00:00
|
|
|
|
|
|
|
return (
|
2021-11-08 18:20:13 +00:00
|
|
|
<div
|
|
|
|
className={`ml-5 border hover:border-gray-500 rounded px-1 py-0.5 ${
|
|
|
|
expanded ? "w-full" : ""
|
|
|
|
}`}
|
|
|
|
>
|
2021-11-06 18:54:34 +00:00
|
|
|
<div className="flex items-baseline">
|
|
|
|
<span className="text-xs text-gray-400 lowercase">{t.type}</span>
|
2021-11-22 17:16:33 +00:00
|
|
|
{t.type === "SELFDESTRUCT" ? (
|
|
|
|
<span className="pl-2 text-red-800" title="Self destruct">
|
|
|
|
<FontAwesomeIcon icon={faBomb} size="1x" />
|
|
|
|
</span>
|
|
|
|
) : (
|
2021-11-21 11:52:37 +00:00
|
|
|
<>
|
2021-11-22 17:16:33 +00:00
|
|
|
<span>
|
2022-03-24 18:20:54 +00:00
|
|
|
<TransactionAddress address={t.to} showCodeIndicator />
|
2021-11-21 11:52:37 +00:00
|
|
|
</span>
|
2021-11-22 17:16:33 +00:00
|
|
|
{t.type !== "CREATE" && t.type !== "CREATE2" && (
|
|
|
|
<>
|
|
|
|
<span>.</span>
|
|
|
|
<FunctionSignature callType={t.type} sig={sigText} />
|
|
|
|
{t.value && !t.value.isZero() && (
|
|
|
|
<span className="text-red-700 whitespace-nowrap">
|
|
|
|
{"{"}value: <FormattedBalance value={t.value} /> ETH{"}"}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
<span className="whitespace-nowrap">
|
|
|
|
(
|
|
|
|
{hasParams && (
|
2021-12-13 18:41:37 +00:00
|
|
|
<ExpanderSwitch
|
|
|
|
expanded={expanded}
|
|
|
|
setExpanded={setExpanded}
|
|
|
|
/>
|
2021-11-19 20:26:57 +00:00
|
|
|
)}
|
2021-11-22 17:16:33 +00:00
|
|
|
{(!hasParams || !expanded) && <>)</>}
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
2021-11-19 18:39:53 +00:00
|
|
|
</>
|
|
|
|
)}
|
2021-11-06 18:54:34 +00:00
|
|
|
</div>
|
2021-11-08 17:53:23 +00:00
|
|
|
{hasParams && expanded && (
|
2021-11-06 18:54:34 +00:00
|
|
|
<>
|
2021-11-08 00:07:20 +00:00
|
|
|
<div className="ml-5 mr-1 my-2">
|
2021-11-08 11:28:28 +00:00
|
|
|
<InputDecoder
|
|
|
|
fourBytes={raw4Bytes ?? "0x"}
|
|
|
|
resolvedTxDesc={fourBytesTxDesc}
|
2021-11-06 18:54:34 +00:00
|
|
|
hasParamNames={false}
|
2021-11-08 11:28:28 +00:00
|
|
|
data={t.input}
|
|
|
|
userMethod={undefined}
|
|
|
|
devMethod={undefined}
|
2021-11-06 18:54:34 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>)</div>
|
|
|
|
</>
|
2021-11-06 05:12:37 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TraceInput;
|