From 8c46eaabb18e81fdde8a64e7dcac7ef89d25e393 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 6 Nov 2021 05:15:27 -0300 Subject: [PATCH] Generalize attribute type --- src/transaction/Details.tsx | 8 ++++++-- src/transaction/LogEntry.tsx | 4 ++-- src/transaction/decoder/AddressDecoder.tsx | 12 ++++++------ src/transaction/decoder/DecodedParamRow.tsx | 12 ++++++------ src/transaction/decoder/DecodedParamsTable.tsx | 8 ++++---- src/types.ts | 16 ++++++++++++++++ 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 85cb2fc..7f95594 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -29,7 +29,11 @@ import USDValue from "../components/USDValue"; import FormattedBalance from "../components/FormattedBalance"; import ETH2USDValue from "../components/ETH2USDValue"; import TokenTransferItem from "../TokenTransferItem"; -import { TransactionData, InternalOperation } from "../types"; +import { + TransactionData, + InternalOperation, + toTransactionContext, +} from "../types"; import PercentageBar from "../components/PercentageBar"; import ExternalLink from "../components/ExternalLink"; import RelativePosition from "../components/RelativePosition"; @@ -371,7 +375,7 @@ const Details: React.FC = ({ = ({ diff --git a/src/transaction/decoder/AddressDecoder.tsx b/src/transaction/decoder/AddressDecoder.tsx index a8b5edf..3e74790 100644 --- a/src/transaction/decoder/AddressDecoder.tsx +++ b/src/transaction/decoder/AddressDecoder.tsx @@ -2,27 +2,27 @@ import React from "react"; import AddressHighlighter from "../../components/AddressHighlighter"; import DecoratedAddressLink from "../../components/DecoratedAddressLink"; import Copy from "../../components/Copy"; -import { TransactionData } from "../../types"; +import { SelectedTransactionContext } from "../../types"; import { ResolvedAddresses } from "../../api/address-resolver"; type AddressDecoderProps = { r: string; - txData: TransactionData; + txContext: SelectedTransactionContext; resolvedAddresses?: ResolvedAddresses | undefined; }; const AddressDecoder: React.FC = ({ r, - txData, + txContext, resolvedAddresses, }) => (
diff --git a/src/transaction/decoder/DecodedParamRow.tsx b/src/transaction/decoder/DecodedParamRow.tsx index 9384ea1..83fe0ac 100644 --- a/src/transaction/decoder/DecodedParamRow.tsx +++ b/src/transaction/decoder/DecodedParamRow.tsx @@ -8,7 +8,7 @@ import Uint256Decoder from "./Uint256Decoder"; import AddressDecoder from "./AddressDecoder"; import BooleanDecoder from "./BooleanDecoder"; import BytesDecoder from "./BytesDecoder"; -import { TransactionData } from "../../types"; +import { SelectedTransactionContext } from "../../types"; import { ResolvedAddresses } from "../../api/address-resolver"; type DecodedParamRowProps = { @@ -16,7 +16,7 @@ type DecodedParamRowProps = { i?: number | undefined; r: any; paramType: ParamType; - txData: TransactionData; + txContext: SelectedTransactionContext; arrayElem?: number | undefined; help?: string | undefined; resolvedAddresses?: ResolvedAddresses | undefined; @@ -27,7 +27,7 @@ const DecodedParamRow: React.FC = ({ i, r, paramType, - txData, + txContext, arrayElem, help, resolvedAddresses, @@ -77,7 +77,7 @@ const DecodedParamRow: React.FC = ({ ) : paramType.baseType === "address" ? ( ) : paramType.baseType === "bool" ? ( @@ -106,7 +106,7 @@ const DecodedParamRow: React.FC = ({ i={idx} r={e} paramType={paramType.components[idx]} - txData={txData} + txContext={txContext} /> ))} {paramType.baseType === "array" && @@ -116,7 +116,7 @@ const DecodedParamRow: React.FC = ({ prefix={paramType.name ?? param_{i}} r={e} paramType={paramType.arrayChildren} - txData={txData} + txContext={txContext} arrayElem={idx} /> ))} diff --git a/src/transaction/decoder/DecodedParamsTable.tsx b/src/transaction/decoder/DecodedParamsTable.tsx index 8f4a562..136b169 100644 --- a/src/transaction/decoder/DecodedParamsTable.tsx +++ b/src/transaction/decoder/DecodedParamsTable.tsx @@ -1,14 +1,14 @@ import React from "react"; import { ParamType, Result } from "@ethersproject/abi"; import DecodedParamRow from "./DecodedParamRow"; -import { TransactionData } from "../../types"; +import { SelectedTransactionContext } from "../../types"; import { DevMethod, UserMethod } from "../../useSourcify"; import { ResolvedAddresses } from "../../api/address-resolver"; type DecodedParamsTableProps = { args: Result; paramTypes: ParamType[]; - txData: TransactionData; + txContext: SelectedTransactionContext; hasParamNames?: boolean; userMethod?: UserMethod | undefined; devMethod?: DevMethod | undefined; @@ -18,7 +18,7 @@ type DecodedParamsTableProps = { const DecodedParamsTable: React.FC = ({ args, paramTypes, - txData, + txContext, hasParamNames = true, devMethod, resolvedAddresses, @@ -49,7 +49,7 @@ const DecodedParamsTable: React.FC = ({ i={i} r={r} paramType={paramTypes[i]} - txData={txData} + txContext={txContext} help={devMethod?.params?.[paramTypes[i].name]} resolvedAddresses={resolvedAddresses} /> diff --git a/src/types.ts b/src/types.ts index f54f94a..947aa51 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,6 +64,22 @@ export type ConfirmedTransactionData = { 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... export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";