Generalize attribute type

This commit is contained in:
Willian Mitsuda 2021-11-06 05:15:27 -03:00
parent 9954c8ac02
commit 8c46eaabb1
6 changed files with 40 additions and 20 deletions

View File

@ -29,7 +29,11 @@ import USDValue from "../components/USDValue";
import FormattedBalance from "../components/FormattedBalance"; import FormattedBalance from "../components/FormattedBalance";
import ETH2USDValue from "../components/ETH2USDValue"; import ETH2USDValue from "../components/ETH2USDValue";
import TokenTransferItem from "../TokenTransferItem"; import TokenTransferItem from "../TokenTransferItem";
import { TransactionData, InternalOperation } from "../types"; import {
TransactionData,
InternalOperation,
toTransactionContext,
} from "../types";
import PercentageBar from "../components/PercentageBar"; import PercentageBar from "../components/PercentageBar";
import ExternalLink from "../components/ExternalLink"; import ExternalLink from "../components/ExternalLink";
import RelativePosition from "../components/RelativePosition"; import RelativePosition from "../components/RelativePosition";
@ -371,7 +375,7 @@ const Details: React.FC<DetailsProps> = ({
<DecodedParamsTable <DecodedParamsTable
args={resolvedTxDesc.args} args={resolvedTxDesc.args}
paramTypes={resolvedTxDesc.functionFragment.inputs} paramTypes={resolvedTxDesc.functionFragment.inputs}
txData={txData} txContext={toTransactionContext(txData)}
hasParamNames={resolvedTxDesc === txDesc} hasParamNames={resolvedTxDesc === txDesc}
userMethod={userMethod} userMethod={userMethod}
devMethod={devMethod} devMethod={devMethod}

View File

@ -8,7 +8,7 @@ import Copy from "../components/Copy";
import ModeTab from "../components/ModeTab"; import ModeTab from "../components/ModeTab";
import DecodedParamsTable from "./decoder/DecodedParamsTable"; import DecodedParamsTable from "./decoder/DecodedParamsTable";
import DecodedLogSignature from "./decoder/DecodedLogSignature"; import DecodedLogSignature from "./decoder/DecodedLogSignature";
import { TransactionData } from "../types"; import { toTransactionContext, TransactionData } from "../types";
import { useTopic0 } from "../useTopic0"; import { useTopic0 } from "../useTopic0";
import { ResolvedAddresses } from "../api/address-resolver"; import { ResolvedAddresses } from "../api/address-resolver";
@ -112,7 +112,7 @@ const LogEntry: React.FC<LogEntryProps> = ({
<DecodedParamsTable <DecodedParamsTable
args={resolvedLogDesc.args} args={resolvedLogDesc.args}
paramTypes={resolvedLogDesc.eventFragment.inputs} paramTypes={resolvedLogDesc.eventFragment.inputs}
txData={txData} txContext={toTransactionContext(txData)}
hasParamNames={resolvedLogDesc === logDesc} hasParamNames={resolvedLogDesc === logDesc}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
/> />

View File

@ -2,27 +2,27 @@ import React from "react";
import AddressHighlighter from "../../components/AddressHighlighter"; import AddressHighlighter from "../../components/AddressHighlighter";
import DecoratedAddressLink from "../../components/DecoratedAddressLink"; import DecoratedAddressLink from "../../components/DecoratedAddressLink";
import Copy from "../../components/Copy"; import Copy from "../../components/Copy";
import { TransactionData } from "../../types"; import { SelectedTransactionContext } from "../../types";
import { ResolvedAddresses } from "../../api/address-resolver"; import { ResolvedAddresses } from "../../api/address-resolver";
type AddressDecoderProps = { type AddressDecoderProps = {
r: string; r: string;
txData: TransactionData; txContext: SelectedTransactionContext;
resolvedAddresses?: ResolvedAddresses | undefined; resolvedAddresses?: ResolvedAddresses | undefined;
}; };
const AddressDecoder: React.FC<AddressDecoderProps> = ({ const AddressDecoder: React.FC<AddressDecoderProps> = ({
r, r,
txData, txContext,
resolvedAddresses, resolvedAddresses,
}) => ( }) => (
<div className="flex items-baseline space-x-2 -ml-1 mr-3"> <div className="flex items-baseline space-x-2 -ml-1 mr-3">
<AddressHighlighter address={r}> <AddressHighlighter address={r}>
<DecoratedAddressLink <DecoratedAddressLink
address={r} address={r}
miner={r === txData.confirmedData?.miner} miner={r === txContext.miner}
txFrom={r === txData.from} txFrom={r === txContext.from}
txTo={r === txData.to} txTo={r === txContext.to}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>

View File

@ -8,7 +8,7 @@ import Uint256Decoder from "./Uint256Decoder";
import AddressDecoder from "./AddressDecoder"; import AddressDecoder from "./AddressDecoder";
import BooleanDecoder from "./BooleanDecoder"; import BooleanDecoder from "./BooleanDecoder";
import BytesDecoder from "./BytesDecoder"; import BytesDecoder from "./BytesDecoder";
import { TransactionData } from "../../types"; import { SelectedTransactionContext } from "../../types";
import { ResolvedAddresses } from "../../api/address-resolver"; import { ResolvedAddresses } from "../../api/address-resolver";
type DecodedParamRowProps = { type DecodedParamRowProps = {
@ -16,7 +16,7 @@ type DecodedParamRowProps = {
i?: number | undefined; i?: number | undefined;
r: any; r: any;
paramType: ParamType; paramType: ParamType;
txData: TransactionData; txContext: SelectedTransactionContext;
arrayElem?: number | undefined; arrayElem?: number | undefined;
help?: string | undefined; help?: string | undefined;
resolvedAddresses?: ResolvedAddresses | undefined; resolvedAddresses?: ResolvedAddresses | undefined;
@ -27,7 +27,7 @@ const DecodedParamRow: React.FC<DecodedParamRowProps> = ({
i, i,
r, r,
paramType, paramType,
txData, txContext,
arrayElem, arrayElem,
help, help,
resolvedAddresses, resolvedAddresses,
@ -77,7 +77,7 @@ const DecodedParamRow: React.FC<DecodedParamRowProps> = ({
) : paramType.baseType === "address" ? ( ) : paramType.baseType === "address" ? (
<AddressDecoder <AddressDecoder
r={r.toString()} r={r.toString()}
txData={txData} txContext={txContext}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
/> />
) : paramType.baseType === "bool" ? ( ) : paramType.baseType === "bool" ? (
@ -106,7 +106,7 @@ const DecodedParamRow: React.FC<DecodedParamRowProps> = ({
i={idx} i={idx}
r={e} r={e}
paramType={paramType.components[idx]} paramType={paramType.components[idx]}
txData={txData} txContext={txContext}
/> />
))} ))}
{paramType.baseType === "array" && {paramType.baseType === "array" &&
@ -116,7 +116,7 @@ const DecodedParamRow: React.FC<DecodedParamRowProps> = ({
prefix={paramType.name ?? <span className="italic">param_{i}</span>} prefix={paramType.name ?? <span className="italic">param_{i}</span>}
r={e} r={e}
paramType={paramType.arrayChildren} paramType={paramType.arrayChildren}
txData={txData} txContext={txContext}
arrayElem={idx} arrayElem={idx}
/> />
))} ))}

View File

@ -1,14 +1,14 @@
import React from "react"; import React from "react";
import { ParamType, Result } from "@ethersproject/abi"; import { ParamType, Result } from "@ethersproject/abi";
import DecodedParamRow from "./DecodedParamRow"; import DecodedParamRow from "./DecodedParamRow";
import { TransactionData } from "../../types"; import { SelectedTransactionContext } from "../../types";
import { DevMethod, UserMethod } from "../../useSourcify"; import { DevMethod, UserMethod } from "../../useSourcify";
import { ResolvedAddresses } from "../../api/address-resolver"; import { ResolvedAddresses } from "../../api/address-resolver";
type DecodedParamsTableProps = { type DecodedParamsTableProps = {
args: Result; args: Result;
paramTypes: ParamType[]; paramTypes: ParamType[];
txData: TransactionData; txContext: SelectedTransactionContext;
hasParamNames?: boolean; hasParamNames?: boolean;
userMethod?: UserMethod | undefined; userMethod?: UserMethod | undefined;
devMethod?: DevMethod | undefined; devMethod?: DevMethod | undefined;
@ -18,7 +18,7 @@ type DecodedParamsTableProps = {
const DecodedParamsTable: React.FC<DecodedParamsTableProps> = ({ const DecodedParamsTable: React.FC<DecodedParamsTableProps> = ({
args, args,
paramTypes, paramTypes,
txData, txContext,
hasParamNames = true, hasParamNames = true,
devMethod, devMethod,
resolvedAddresses, resolvedAddresses,
@ -49,7 +49,7 @@ const DecodedParamsTable: React.FC<DecodedParamsTableProps> = ({
i={i} i={i}
r={r} r={r}
paramType={paramTypes[i]} paramType={paramTypes[i]}
txData={txData} txContext={txContext}
help={devMethod?.params?.[paramTypes[i].name]} help={devMethod?.params?.[paramTypes[i].name]}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
/> />

View File

@ -64,6 +64,22 @@ export type ConfirmedTransactionData = {
logs: Log[]; logs: Log[];
}; };
export type SelectedTransactionContext = {
from: string;
to: string | undefined;
miner: string | undefined;
};
export const toTransactionContext = (
txData: TransactionData
): SelectedTransactionContext => {
return {
from: txData.from,
to: txData.to,
miner: txData.confirmedData?.miner,
};
};
// The VOID... // The VOID...
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"; export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";