Add generic resolvers support to internal ops

This commit is contained in:
Willian Mitsuda 2021-11-18 15:46:09 -03:00
parent 5b203bc8d4
commit c9f7f46ebc
5 changed files with 50 additions and 20 deletions

View File

@ -4,26 +4,33 @@ import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
import AddressHighlighter from "./AddressHighlighter"; import AddressHighlighter from "./AddressHighlighter";
import DecoratedAddressLink from "./DecoratedAddressLink"; import DecoratedAddressLink from "./DecoratedAddressLink";
import { TransactionData, InternalOperation } from "../types"; import { TransactionData, InternalOperation } from "../types";
import { ResolvedAddresses } from "../api/address-resolver";
type InternalCreateProps = { type InternalCreateProps = {
txData: TransactionData; txData: TransactionData;
internalOp: InternalOperation; internalOp: InternalOperation;
resolvedAddresses: ResolvedAddresses | undefined;
}; };
const InternalCreate: React.FC<InternalCreateProps> = ({ const InternalCreate: React.FC<InternalCreateProps> = ({
txData, txData,
internalOp, internalOp,
resolvedAddresses,
}) => { }) => {
return ( 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"> <span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> CREATE <FontAwesomeIcon icon={faAngleRight} size="1x" /> CREATE
</span> </span>
<span>Contract</span> <span>Contract</span>
<div className="flex items-baseline"> <div className="flex items-baseline">
<AddressHighlighter address={internalOp.to}> <AddressHighlighter address={internalOp.to}>
<DecoratedAddressLink address={internalOp.to} creation /> <DecoratedAddressLink
address={internalOp.to}
creation
resolvedAddresses={resolvedAddresses}
/>
</AddressHighlighter> </AddressHighlighter>
</div> </div>
<span className="flex items-baseline text-gray-400"> <span className="flex items-baseline text-gray-400">
@ -33,6 +40,7 @@ const InternalCreate: React.FC<InternalCreateProps> = ({
address={internalOp.from} address={internalOp.from}
txFrom={internalOp.from === txData.from} txFrom={internalOp.from === txData.from}
txTo={internalOp.from === txData.to} txTo={internalOp.from === txData.to}
resolvedAddresses={resolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>
) )

View File

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

View File

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

View File

@ -26,7 +26,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
internalOp.to === txData.confirmedData.miner; internalOp.to === txData.confirmedData.miner;
return ( 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"> <span className="text-gray-500">
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER <FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
</span> </span>
@ -44,6 +44,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
miner={fromMiner} miner={fromMiner}
txFrom={internalOp.from === txData.from} txFrom={internalOp.from === txData.from}
txTo={internalOp.from === txData.to} txTo={internalOp.from === txData.to}
resolvedAddresses={resolvedAddresses}
/> />
</div> </div>
</AddressHighlighter> </AddressHighlighter>
@ -61,6 +62,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
miner={toMiner} miner={toMiner}
txFrom={internalOp.to === txData.from} txFrom={internalOp.to === txData.from}
txTo={internalOp.to === txData.to} txTo={internalOp.to === txData.to}
resolvedAddresses={resolvedAddresses}
/> />
</div> </div>
</AddressHighlighter> </AddressHighlighter>

View File

@ -206,7 +206,7 @@ const Details: React.FC<DetailsProps> = ({
</div> </div>
)} )}
{internalOps && internalOps.length > 0 && ( {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) => ( {internalOps.map((op, i) => (
<InternalTransactionOperation <InternalTransactionOperation
key={i} key={i}