otterscan/src/transaction/TraceInput.tsx

96 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-11-06 18:54:34 +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";
2021-11-06 05:12:37 +00:00
import { TraceEntry } from "../useErigonHooks";
2021-11-06 18:54:34 +00:00
import {
extract4Bytes,
use4Bytes,
2021-11-06 18:54:34 +00:00
useTransactionDescription,
} from "../use4Bytes";
2021-11-06 05:12:37 +00:00
type TraceInputProps = {
t: TraceEntry;
};
const TraceInput: React.FC<TraceInputProps> = ({ t }) => {
2021-11-06 05:12:37 +00:00
const raw4Bytes = extract4Bytes(t.input);
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>
<TransactionAddress address={t.to} />
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-22 17:16:33 +00:00
{(!hasParams || !expanded) && <>)</>}
</span>
</>
)}
</>
)}
2021-11-06 18:54:34 +00:00
</div>
{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;