otterscan/src/transaction/Details.tsx

207 lines
6.8 KiB
TypeScript
Raw Normal View History

2021-07-14 19:30:28 +00:00
import React from "react";
import { ethers } from "ethers";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faCheckCircle,
faTimesCircle,
} from "@fortawesome/free-solid-svg-icons";
import ContentFrame from "../ContentFrame";
import InfoRow from "../components/InfoRow";
import BlockLink from "../components/BlockLink";
2021-07-23 04:28:44 +00:00
import BlockConfirmations from "../components/BlockConfirmations";
2021-07-14 19:30:28 +00:00
import AddressHighlighter from "../components/AddressHighlighter";
import DecoratedAddressLink from "../components/DecoratedAddressLink";
2021-07-14 19:30:28 +00:00
import Copy from "../components/Copy";
import Timestamp from "../components/Timestamp";
2021-07-21 19:06:51 +00:00
import InternalTransactionOperation from "../components/InternalTransactionOperation";
2021-07-14 19:30:28 +00:00
import MethodName from "../components/MethodName";
import TransactionType from "../components/TransactionType";
2021-07-14 19:30:28 +00:00
import GasValue from "../components/GasValue";
import FormattedBalance from "../components/FormattedBalance";
import TokenTransferItem from "../TokenTransferItem";
2021-07-21 19:06:51 +00:00
import { TransactionData, InternalOperation } from "../types";
import PercentageBar from "../components/PercentageBar";
2021-07-14 19:30:28 +00:00
type DetailsProps = {
txData: TransactionData;
2021-07-21 19:06:51 +00:00
internalOps?: InternalOperation[];
2021-07-14 19:30:28 +00:00
sendsEthToMiner: boolean;
};
const Details: React.FC<DetailsProps> = ({
txData,
2021-07-21 19:06:51 +00:00
internalOps,
2021-07-14 19:30:28 +00:00
sendsEthToMiner,
}) => (
<ContentFrame tabs>
<InfoRow title="Transaction Hash">
<div className="flex items-baseline space-x-2">
<span className="font-hash">{txData.transactionHash}</span>
<Copy value={txData.transactionHash} />
</div>
</InfoRow>
<InfoRow title="Status">
{txData.status ? (
<span className="flex items-center w-min rounded-lg space-x-1 px-3 py-1 bg-green-50 text-green-500 text-xs">
<FontAwesomeIcon icon={faCheckCircle} size="1x" />
<span>Success</span>
</span>
) : (
<span className="flex items-center w-min rounded-lg space-x-1 px-3 py-1 bg-red-50 text-red-500 text-xs">
<FontAwesomeIcon icon={faTimesCircle} size="1x" />
<span>Fail</span>
</span>
)}
</InfoRow>
<InfoRow title="Block">
<div className="flex items-baseline space-x-2">
<BlockLink blockTag={txData.blockNumber} />
2021-07-23 04:28:44 +00:00
<BlockConfirmations confirmations={txData.confirmations} />
2021-07-14 19:30:28 +00:00
</div>
</InfoRow>
<InfoRow title="Timestamp">
<Timestamp value={txData.timestamp} />
</InfoRow>
<InfoRow title="From">
<div className="flex items-baseline space-x-2 -ml-1">
<AddressHighlighter address={txData.from}>
<DecoratedAddressLink
address={txData.from}
miner={txData.from === txData.miner}
txFrom
/>
2021-07-14 19:30:28 +00:00
</AddressHighlighter>
<Copy value={txData.from} />
</div>
</InfoRow>
<InfoRow title={txData.to ? "Interacted With (To)" : "Contract Created"}>
{txData.to ? (
<div className="flex items-baseline space-x-2 -ml-1">
<AddressHighlighter address={txData.to}>
<DecoratedAddressLink
address={txData.to}
miner={txData.to === txData.miner}
txTo
/>
</AddressHighlighter>
<Copy value={txData.to} />
</div>
) : (
<div className="flex items-baseline space-x-2 -ml-1">
<AddressHighlighter address={txData.createdContractAddress!}>
<DecoratedAddressLink
address={txData.createdContractAddress!}
creation
txTo
/>
</AddressHighlighter>
<Copy value={txData.createdContractAddress!} />
</div>
)}
2021-07-21 19:06:51 +00:00
{internalOps && (
<div className="mt-2 space-y-1">
2021-07-21 19:06:51 +00:00
{internalOps.map((op, i) => (
<InternalTransactionOperation
key={i}
txData={txData}
internalOp={op}
/>
))}
</div>
2021-07-14 19:30:28 +00:00
)}
</InfoRow>
<InfoRow title="Transaction Action">
<MethodName data={txData.data} />
</InfoRow>
{txData.tokenTransfers.length > 0 && (
<InfoRow title={`Tokens Transferred (${txData.tokenTransfers.length})`}>
<div>
2021-07-14 19:30:28 +00:00
{txData.tokenTransfers.map((t, i) => (
<TokenTransferItem
key={i}
t={t}
txData={txData}
tokenMetas={txData.tokenMetas}
/>
2021-07-14 19:30:28 +00:00
))}
</div>
</InfoRow>
)}
<InfoRow title="Value">
<span className="rounded bg-gray-100 px-2 py-1 text-xs">
{ethers.utils.formatEther(txData.value)} Ether
</span>
</InfoRow>
<InfoRow title="Type (EIP-2718)">
<TransactionType type={txData.type} />
</InfoRow>
{txData.type === 2 && (
<>
<InfoRow title="Max Fee Per Gas">
<span>
<FormattedBalance value={txData.maxFeePerGas!} /> Ether (
<FormattedBalance value={txData.maxFeePerGas!} decimals={9} /> Gwei)
</span>
</InfoRow>
<InfoRow title="Max Priority Fee Per Gas">
<span>
<FormattedBalance value={txData.maxPriorityFeePerGas!} /> Ether (
<FormattedBalance
value={txData.maxPriorityFeePerGas!}
decimals={9}
/>{" "}
Gwei)
</span>
</InfoRow>
</>
)}
2021-07-14 19:30:28 +00:00
<InfoRow title="Transaction Fee">
<FormattedBalance value={txData.fee} /> Ether
</InfoRow>
<InfoRow title="Gas Price">
<div className="flex items-baseline space-x-1">
<span>
<FormattedBalance value={txData.gasPrice} /> Ether (
<FormattedBalance value={txData.gasPrice} decimals={9} /> Gwei)
</span>
{sendsEthToMiner && (
<span className="rounded text-yellow-500 bg-yellow-100 text-xs px-2 py-1">
Flashbots
</span>
)}
</div>
</InfoRow>
2021-07-28 07:29:36 +00:00
<InfoRow title="Gas Used/Limit">
<div className="flex space-x-3 items-baseline">
<div>
<GasValue value={txData.gasUsed} /> /{" "}
<GasValue value={txData.gasLimit} />
</div>
2021-07-28 07:53:55 +00:00
<PercentageBar
perc={
Math.round(
(txData.gasUsed.toNumber() / txData.gasLimit.toNumber()) * 10000
) / 100
}
/>
</div>
2021-07-14 19:30:28 +00:00
</InfoRow>
2021-07-28 07:29:36 +00:00
<InfoRow title="Ether Price">N/A</InfoRow>
2021-07-14 19:30:28 +00:00
<InfoRow title="Nonce">{txData.nonce}</InfoRow>
<InfoRow title="Position in Block">
<span className="rounded px-2 py-1 bg-gray-100 text-gray-500 text-xs">
{txData.transactionIndex}
</span>
</InfoRow>
<InfoRow title="Input Data">
<textarea
className="w-full h-40 bg-gray-50 text-gray-500 font-mono focus:outline-none border rounded p-2"
value={txData.data}
readOnly
/>
</InfoRow>
</ContentFrame>
);
export default React.memo(Details);