import React, { useContext, useMemo, useState } from "react"; import { Tab } from "@headlessui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle"; import { faCube } from "@fortawesome/free-solid-svg-icons/faCube"; import { faTimesCircle } from "@fortawesome/free-solid-svg-icons/faTimesCircle"; import ContentFrame from "../ContentFrame"; import InfoRow from "../components/InfoRow"; import BlockLink from "../components/BlockLink"; import ModeTab from "../components/ModeTab"; import ExpanderSwitch from "../components/ExpanderSwitch"; import BlockConfirmations from "../components/BlockConfirmations"; import TransactionAddress from "../components/TransactionAddress"; import Copy from "../components/Copy"; import Nonce from "../components/Nonce"; import NavNonce from "./NavNonce"; import Timestamp from "../components/Timestamp"; import InternalTransactionOperation from "../components/InternalTransactionOperation"; import MethodName from "../components/MethodName"; import TransactionType from "../components/TransactionType"; import RewardSplit from "./RewardSplit"; import GasValue from "../components/GasValue"; import USDValue from "../components/USDValue"; import FormattedBalance from "../components/FormattedBalance"; import ETH2USDValue from "../components/ETH2USDValue"; import TokenTransferItem from "../TokenTransferItem"; import { TransactionData } from "../types"; import PercentageBar from "../components/PercentageBar"; import ExternalLink from "../components/ExternalLink"; import RelativePosition from "../components/RelativePosition"; import PercentagePosition from "../components/PercentagePosition"; import DecodedParamsTable from "./decoder/DecodedParamsTable"; import InputDecoder from "./decoder/InputDecoder"; import { extract4Bytes, use4Bytes, useTransactionDescription, } from "../use4Bytes"; import { useAppConfigContext } from "../useAppConfig"; import { useError, useSourcifyMetadata, useTransactionDescription as useSourcifyTransactionDescription, } from "../sourcify/useSourcify"; import { RuntimeContext } from "../useRuntime"; import { useInternalOperations, useTransactionError } from "../useErigonHooks"; import { useChainInfo } from "../useChainInfo"; import { useETHUSDOracle } from "../usePriceOracle"; type DetailsProps = { txData: TransactionData; }; const Details: React.FC = ({ txData }) => { const { provider } = useContext(RuntimeContext); const hasEIP1559 = txData.confirmedData?.blockBaseFeePerGas !== undefined && txData.confirmedData?.blockBaseFeePerGas !== null; const fourBytes = txData.to !== null ? extract4Bytes(txData.data) ?? "0x" : "0x"; const fourBytesEntry = use4Bytes(fourBytes); const fourBytesTxDesc = useTransactionDescription( fourBytesEntry, txData.data, txData.value ); const internalOps = useInternalOperations(provider, txData); const sendsEthToMiner = useMemo(() => { if (!txData || !internalOps) { return false; } for (const t of internalOps) { if (t.to === txData.confirmedData?.miner) { return true; } } return false; }, [txData, internalOps]); const { sourcifySource } = useAppConfigContext(); const metadata = useSourcifyMetadata( txData?.to, provider?.network.chainId, sourcifySource ); const txDesc = useSourcifyTransactionDescription(metadata, txData); const userDoc = metadata?.output.userdoc; const devDoc = metadata?.output.devdoc; const resolvedTxDesc = txDesc ?? fourBytesTxDesc; const userMethod = txDesc ? userDoc?.methods[txDesc.signature] : undefined; const devMethod = txDesc ? devDoc?.methods[txDesc.signature] : undefined; const { nativeCurrency: { name, symbol }, } = useChainInfo(); const blockETHUSDPrice = useETHUSDOracle( provider, txData?.confirmedData?.blockNumber ); const [errorMsg, outputData, isCustomError] = useTransactionError( provider, txData.transactionHash ); const errorDescription = useError( metadata, isCustomError ? outputData : undefined ); const userError = errorDescription ? userDoc?.errors?.[errorDescription.signature]?.[0] : undefined; const devError = errorDescription ? devDoc?.errors?.[errorDescription.signature]?.[0] : undefined; const [expanded, setExpanded] = useState(false); return (
{txData.transactionHash}
{txData.confirmedData === undefined ? ( Pending ) : txData.confirmedData.status ? ( Success ) : ( <>
Fail {errorMsg && ( <> {" "} with revert message: ' {errorMsg}' )} {isCustomError && ( <> {" "} with custom error {errorDescription && ( <> {" '"} {errorDescription.name} {"'"} )} )}
{isCustomError && ( )}
{expanded && ( Decoded Raw {errorDescription === undefined ? ( <>Waiting for data... ) : errorDescription === null ? ( <>Can't decode data ) : errorDescription.args.length === 0 ? ( <>No parameters ) : ( )}