2021-11-03 00:24:19 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { faPlusSquare } from "@fortawesome/free-regular-svg-icons/faPlusSquare";
|
|
|
|
|
import { faMinusSquare } from "@fortawesome/free-regular-svg-icons/faMinusSquare";
|
|
|
|
|
import { Switch } from "@headlessui/react";
|
2021-10-27 01:10:37 +00:00
|
|
|
import AddressHighlighter from "../components/AddressHighlighter";
|
|
|
|
|
import DecoratedAddressLink from "../components/DecoratedAddressLink";
|
2021-10-27 08:14:46 +00:00
|
|
|
import FormattedBalance from "../components/FormattedBalance";
|
2021-10-28 05:54:36 +00:00
|
|
|
import FunctionSignature from "./FunctionSignature";
|
2021-10-27 01:10:37 +00:00
|
|
|
import { TransactionData } from "../types";
|
2021-10-28 20:39:10 +00:00
|
|
|
import { extract4Bytes, FourBytesEntry } from "../use4Bytes";
|
2021-10-27 01:10:37 +00:00
|
|
|
import { TraceGroup } from "../useErigonHooks";
|
2021-11-01 20:09:47 +00:00
|
|
|
import { ResolvedAddresses } from "../api/address-resolver";
|
2021-10-27 01:10:37 +00:00
|
|
|
|
|
|
|
|
type TraceItemProps = {
|
|
|
|
|
t: TraceGroup;
|
|
|
|
|
txData: TransactionData;
|
|
|
|
|
last: boolean;
|
2021-10-28 20:21:01 +00:00
|
|
|
fourBytesMap: Record<string, FourBytesEntry | null | undefined>;
|
2021-11-01 20:09:47 +00:00
|
|
|
resolvedAddresses: ResolvedAddresses | undefined;
|
2021-10-27 01:10:37 +00:00
|
|
|
};
|
|
|
|
|
|
2021-10-28 20:21:01 +00:00
|
|
|
const TraceItem: React.FC<TraceItemProps> = ({
|
|
|
|
|
t,
|
|
|
|
|
txData,
|
|
|
|
|
last,
|
|
|
|
|
fourBytesMap,
|
2021-11-01 20:09:47 +00:00
|
|
|
resolvedAddresses,
|
2021-10-28 20:21:01 +00:00
|
|
|
}) => {
|
2021-11-03 00:24:19 +00:00
|
|
|
const [expanded, setExpanded] = useState<boolean>(true);
|
2021-10-28 20:39:10 +00:00
|
|
|
const raw4Bytes = extract4Bytes(t.input);
|
|
|
|
|
const sigText =
|
|
|
|
|
raw4Bytes === null
|
|
|
|
|
? "<fallback>"
|
|
|
|
|
: fourBytesMap[raw4Bytes]?.name ?? raw4Bytes;
|
2021-10-27 04:08:26 +00:00
|
|
|
|
2021-10-27 01:10:37 +00:00
|
|
|
return (
|
|
|
|
|
<>
|
2021-11-03 00:24:19 +00:00
|
|
|
<div className="flex relative items-center">
|
2021-10-30 01:31:16 +00:00
|
|
|
<div className="absolute border-l border-b w-5 h-full transform -translate-y-1/2"></div>
|
|
|
|
|
{!last && (
|
|
|
|
|
<div className="absolute left-0 border-l w-5 h-full transform translate-y-1/2"></div>
|
|
|
|
|
)}
|
2021-11-03 00:24:19 +00:00
|
|
|
{t.children && (
|
|
|
|
|
<Switch
|
|
|
|
|
className="absolute left-0 bg-white transform -translate-x-1/2 text-gray-500"
|
|
|
|
|
checked={expanded}
|
|
|
|
|
onChange={setExpanded}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={expanded ? faMinusSquare : faPlusSquare}
|
|
|
|
|
size="1x"
|
|
|
|
|
/>
|
|
|
|
|
</Switch>
|
|
|
|
|
)}
|
2021-10-30 01:31:16 +00:00
|
|
|
<div className="ml-5 flex items-baseline border rounded px-1 py-px">
|
2021-10-27 01:10:37 +00:00
|
|
|
<span className="text-xs text-gray-400 lowercase">{t.type}</span>
|
|
|
|
|
<span>
|
|
|
|
|
<AddressHighlighter address={t.to}>
|
|
|
|
|
<DecoratedAddressLink
|
|
|
|
|
address={t.to}
|
|
|
|
|
miner={t.to === txData.confirmedData?.miner}
|
|
|
|
|
txFrom={t.to === txData.from}
|
|
|
|
|
txTo={t.to === txData.to}
|
2021-11-01 20:09:47 +00:00
|
|
|
resolvedAddresses={resolvedAddresses}
|
2021-10-27 01:10:37 +00:00
|
|
|
/>
|
|
|
|
|
</AddressHighlighter>
|
|
|
|
|
</span>
|
|
|
|
|
<span>.</span>
|
2021-10-28 20:39:10 +00:00
|
|
|
<FunctionSignature callType={t.type} sig={sigText} />
|
2021-10-27 08:14:46 +00:00
|
|
|
{t.value && !t.value.isZero() && (
|
|
|
|
|
<span className="text-red-700 whitespace-nowrap">
|
|
|
|
|
{"{"}value: <FormattedBalance value={t.value} /> ETH{"}"}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2021-10-30 01:31:16 +00:00
|
|
|
<span className="whitespace-nowrap">
|
|
|
|
|
({t.input.length > 10 && <>input=[0x{t.input.slice(10)}]</>})
|
|
|
|
|
</span>
|
2021-10-27 01:10:37 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-11-03 00:54:25 +00:00
|
|
|
{t.children && (
|
|
|
|
|
<div
|
|
|
|
|
className={`pl-10 ${last ? "" : "border-l"} space-y-3 ${
|
|
|
|
|
expanded ? "" : "hidden"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2021-10-30 01:31:16 +00:00
|
|
|
{t.children.map((tc, i, a) => (
|
|
|
|
|
<TraceItem
|
|
|
|
|
key={i}
|
|
|
|
|
t={tc}
|
|
|
|
|
txData={txData}
|
|
|
|
|
last={i === a.length - 1}
|
|
|
|
|
fourBytesMap={fourBytesMap}
|
2021-11-01 20:09:47 +00:00
|
|
|
resolvedAddresses={resolvedAddresses}
|
2021-10-30 01:31:16 +00:00
|
|
|
/>
|
|
|
|
|
))}
|
2021-10-27 01:10:37 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-27 20:19:20 +00:00
|
|
|
export default TraceItem;
|