Merge branch 'feature/fix-optimize-missing-decorations' into develop

This commit is contained in:
Willian Mitsuda 2021-11-18 16:03:19 -03:00
commit d5e4fb3923
6 changed files with 111 additions and 97 deletions

View File

@ -6,25 +6,26 @@ import ValueHighlighter from "./components/ValueHighlighter";
import FormattedBalance from "./components/FormattedBalance";
import {
AddressContext,
ChecksummedAddress,
TokenMeta,
TokenTransfer,
TransactionData,
} from "./types";
import { ResolvedAddresses } from "./api/address-resolver";
import { Metadata } from "./useSourcify";
type TokenTransferItemProps = {
t: TokenTransfer;
txData: TransactionData;
tokenMeta?: TokenMeta | undefined;
resolvedAddresses: ResolvedAddresses | undefined;
metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
};
// TODO: handle partial
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t,
txData,
tokenMeta,
resolvedAddresses,
metadatas,
}) => (
<div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
<span className="text-gray-500">
@ -37,6 +38,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
address={t.from}
addressCtx={AddressContext.FROM}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.from]}
/>
</div>
<div className="flex space-x-1">
@ -45,6 +47,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
address={t.to}
addressCtx={AddressContext.TO}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.to]}
/>
</div>
<div className="col-span-3 flex space-x-1">
@ -60,6 +63,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
<TransactionAddress
address={t.token}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.token]}
/>
</div>
</div>

View File

@ -1,45 +1,44 @@
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
import TransactionAddress from "./TransactionAddress";
import AddressHighlighter from "./AddressHighlighter";
import DecoratedAddressLink from "./DecoratedAddressLink";
import { TransactionData, InternalOperation } from "../types";
import { InternalOperation } from "../types";
import { ResolvedAddresses } from "../api/address-resolver";
type InternalCreateProps = {
txData: TransactionData;
internalOp: InternalOperation;
resolvedAddresses: ResolvedAddresses | undefined;
};
const InternalCreate: React.FC<InternalCreateProps> = ({
txData,
internalOp,
}) => {
return (
<>
<div className="flex items-baseline space-x-1 text-xs">
resolvedAddresses,
}) => (
<div className="flex items-baseline space-x-1 whitespace-nowrap">
<span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> CREATE
</span>
<span>Contract</span>
<div className="flex items-baseline">
<AddressHighlighter address={internalOp.to}>
<DecoratedAddressLink address={internalOp.to} creation />
<DecoratedAddressLink
address={internalOp.to}
creation
resolvedAddresses={resolvedAddresses}
/>
</AddressHighlighter>
</div>
<span className="flex items-baseline text-gray-400">
(Creator:{" "}
<AddressHighlighter address={internalOp.from}>
<DecoratedAddressLink
<TransactionAddress
address={internalOp.from}
txFrom={internalOp.from === txData.from}
txTo={internalOp.from === txData.to}
resolvedAddresses={resolvedAddresses}
/>
</AddressHighlighter>
)
</span>
</div>
</>
);
};
export default React.memo(InternalCreate);
export default InternalCreate;

View File

@ -1,52 +1,57 @@
import React, { useContext } from "react";
import React from "react";
import { formatEther } from "@ethersproject/units";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
import AddressHighlighter from "./AddressHighlighter";
import DecoratedAddressLink from "./DecoratedAddressLink";
import { RuntimeContext } from "../useRuntime";
import { TransactionData, InternalOperation } from "../types";
const CHI_ADDRESS = "0x0000000000004946c0e9F43F4Dee607b0eF1fA1c";
const GST2_ADDRESS = "0x0000000000b3F879cb30FE243b4Dfee438691c04";
import { ResolvedAddresses } from "../api/address-resolver";
import TransactionAddress from "./TransactionAddress";
type InternalSelfDestructProps = {
txData: TransactionData;
internalOp: InternalOperation;
resolvedAddresses: ResolvedAddresses | undefined;
};
const InternalSelfDestruct: React.FC<InternalSelfDestructProps> = ({
txData,
internalOp,
resolvedAddresses,
}) => {
const { provider } = useContext(RuntimeContext);
const network = provider?.network;
const toMiner =
txData.confirmedData?.miner !== undefined &&
internalOp.to === txData.confirmedData.miner;
return (
<>
<div className="flex items-baseline space-x-1 text-xs">
<div className="flex items-baseline space-x-1 whitespace-nowrap">
<span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> SELF DESTRUCT
</span>
<span>Contract</span>
<div className="flex items-baseline">
<AddressHighlighter address={internalOp.from}>
<DecoratedAddressLink address={internalOp.from} selfDestruct />
<DecoratedAddressLink
address={internalOp.from}
selfDestruct
resolvedAddresses={resolvedAddresses}
/>
</AddressHighlighter>
</div>
{network?.chainId === 1 && internalOp.to === CHI_ADDRESS && (
<span className="text-gray-400">(Chi Gastoken)</span>
)}
{network?.chainId === 1 && internalOp.to === GST2_ADDRESS && (
<span className="text-gray-400">(GST2 Gastoken)</span>
{internalOp.value.isZero() && (
<div className="flex items-baseline text-gray-400">
(To:{" "}
<TransactionAddress
address={internalOp.to}
resolvedAddresses={resolvedAddresses}
/>
)
</div>
)}
</div>
{!internalOp.value.isZero() && (
<div className="ml-5 flex items-baseline space-x-1 text-xs">
<div className="ml-5 flex items-baseline space-x-1">
<span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
</span>
@ -59,7 +64,11 @@ const InternalSelfDestruct: React.FC<InternalSelfDestructProps> = ({
toMiner ? "rounded px-2 py-1 bg-yellow-100" : ""
}`}
>
<DecoratedAddressLink address={internalOp.to} miner={toMiner} />
<DecoratedAddressLink
address={internalOp.to}
miner={toMiner}
resolvedAddresses={resolvedAddresses}
/>
</div>
</AddressHighlighter>
</div>
@ -69,4 +78,4 @@ const InternalSelfDestruct: React.FC<InternalSelfDestructProps> = ({
);
};
export default React.memo(InternalSelfDestruct);
export default InternalSelfDestruct;

View File

@ -22,11 +22,18 @@ const InternalTransactionOperation: React.FC<InternalTransactionOperationProps>
/>
)}
{internalOp.type === OperationType.SELF_DESTRUCT && (
<InternalSelfDestruct txData={txData} internalOp={internalOp} />
<InternalSelfDestruct
txData={txData}
internalOp={internalOp}
resolvedAddresses={resolvedAddresses}
/>
)}
{(internalOp.type === OperationType.CREATE ||
internalOp.type === OperationType.CREATE2) && (
<InternalCreate txData={txData} internalOp={internalOp} />
<InternalCreate
internalOp={internalOp}
resolvedAddresses={resolvedAddresses}
/>
)}
</>
);

View File

@ -26,7 +26,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
internalOp.to === txData.confirmedData.miner;
return (
<div className="flex items-baseline space-x-1 text-xs">
<div className="flex items-baseline space-x-1 whitespace-nowrap">
<span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
</span>
@ -44,6 +44,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
miner={fromMiner}
txFrom={internalOp.from === txData.from}
txTo={internalOp.from === txData.to}
resolvedAddresses={resolvedAddresses}
/>
</div>
</AddressHighlighter>
@ -61,6 +62,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
miner={toMiner}
txFrom={internalOp.to === txData.from}
txTo={internalOp.to === txData.to}
resolvedAddresses={resolvedAddresses}
/>
</div>
</AddressHighlighter>
@ -69,4 +71,4 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
);
};
export default React.memo(InternalTransfer);
export default InternalTransfer;

View File

@ -95,6 +95,11 @@ const Details: React.FC<DetailsProps> = ({
if (txData.confirmedData?.createdContractAddress) {
_addresses.push(txData.confirmedData.createdContractAddress);
}
for (const t of txData.tokenTransfers) {
_addresses.push(t.from);
_addresses.push(t.to);
_addresses.push(t.token);
}
return _addresses;
}, [txData]);
const { sourcifySource } = useAppConfigContext();
@ -201,7 +206,7 @@ const Details: React.FC<DetailsProps> = ({
</div>
)}
{internalOps && internalOps.length > 0 && (
<div className="mt-2 space-y-1">
<div className="mt-2 space-y-1 overflow-x-auto">
{internalOps.map((op, i) => (
<InternalTransactionOperation
key={i}
@ -220,17 +225,15 @@ const Details: React.FC<DetailsProps> = ({
)}
{txData.tokenTransfers.length > 0 && (
<InfoRow title={`Tokens Transferred (${txData.tokenTransfers.length})`}>
<div>
{txData.tokenTransfers.map((t, i) => (
<TokenTransferItem
key={i}
t={t}
txData={txData}
tokenMeta={txData.tokenMetas[t.token]}
resolvedAddresses={resolvedAddresses}
metadatas={metadatas}
/>
))}
</div>
</InfoRow>
)}
<InfoRow title="Value">
@ -257,24 +260,16 @@ const Details: React.FC<DetailsProps> = ({
{txData.type === 2 && (
<>
<InfoRow title="Max Priority Fee Per Gas">
<span>
<FormattedBalance value={txData.maxPriorityFeePerGas!} /> Ether (
<FormattedBalance
value={txData.maxPriorityFeePerGas!}
decimals={9}
/>{" "}
Gwei)
</span>
</InfoRow>
<InfoRow title="Max Fee Per Gas">
<span>
<FormattedBalance value={txData.maxFeePerGas!} /> Ether (
<FormattedBalance
value={txData.maxFeePerGas!}
decimals={9}
/>{" "}
Gwei)
</span>
<FormattedBalance value={txData.maxFeePerGas!} decimals={9} /> Gwei)
</InfoRow>
</>
)}
@ -316,7 +311,6 @@ const Details: React.FC<DetailsProps> = ({
)}
{txData.confirmedData && hasEIP1559 && (
<InfoRow title="Block Base Fee">
<span>
<FormattedBalance
value={txData.confirmedData.blockBaseFeePerGas!}
decimals={9}
@ -327,7 +321,6 @@ const Details: React.FC<DetailsProps> = ({
decimals={0}
/>{" "}
wei)
</span>
</InfoRow>
)}
{txData.confirmedData && (