From f662a8c72ef8ce746efdedfa5cb48d34e80b8fb0 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 18 Sep 2021 17:41:00 -0300 Subject: [PATCH] Refactor and extract common component --- src/transaction/DecodedInput.tsx | 57 ------------------- ...{DecodedLog.tsx => DecodedParamsTable.tsx} | 23 +++++--- src/transaction/Details.tsx | 8 ++- src/transaction/LogEntry.tsx | 8 ++- 4 files changed, 26 insertions(+), 70 deletions(-) delete mode 100644 src/transaction/DecodedInput.tsx rename src/transaction/{DecodedLog.tsx => DecodedParamsTable.tsx} (76%) diff --git a/src/transaction/DecodedInput.tsx b/src/transaction/DecodedInput.tsx deleted file mode 100644 index 9764c8f..0000000 --- a/src/transaction/DecodedInput.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from "react"; -import { TransactionDescription } from "@ethersproject/abi"; -import AddressHighlighter from "../components/AddressHighlighter"; -import DecoratedAddressLink from "../components/DecoratedAddressLink"; -import Copy from "../components/Copy"; -import { TransactionData } from "../types"; - -type DecodedInputProps = { - txData: TransactionData; - txDesc: TransactionDescription; -}; - -const DecodedInput: React.FC = ({ txData, txDesc }) => ( - - - - - - - - - - {txDesc.args.map((r, i) => ( - - - - - - ))} - -
- param (index) - typevalue
- {txDesc.functionFragment.inputs[i].name}{" "} - ({i}) - - {txDesc.functionFragment.inputs[i].type} - - {txDesc.functionFragment.inputs[i].type === "address" ? ( -
- - - - -
- ) : ( - r.toString() - )} -
-); - -export default React.memo(DecodedInput); diff --git a/src/transaction/DecodedLog.tsx b/src/transaction/DecodedParamsTable.tsx similarity index 76% rename from src/transaction/DecodedLog.tsx rename to src/transaction/DecodedParamsTable.tsx index c4a904f..cbed748 100644 --- a/src/transaction/DecodedLog.tsx +++ b/src/transaction/DecodedParamsTable.tsx @@ -1,16 +1,21 @@ import React from "react"; -import { LogDescription } from "@ethersproject/abi"; +import { LogDescription, ParamType, Result } from "@ethersproject/abi"; import AddressHighlighter from "../components/AddressHighlighter"; import DecoratedAddressLink from "../components/DecoratedAddressLink"; import Copy from "../components/Copy"; import { TransactionData } from "../types"; -type DecodedLogProps = { +type DecodedParamsTableProps = { + args: Result; + paramTypes: ParamType[]; txData: TransactionData; - logDesc: LogDescription; }; -const DecodedLog: React.FC = ({ txData, logDesc }) => ( +const DecodedParamsTable: React.FC = ({ + args, + paramTypes, + txData, +}) => ( @@ -22,15 +27,15 @@ const DecodedLog: React.FC = ({ txData, logDesc }) => ( - {logDesc.args.map((r, i) => ( + {args.map((r, i) => ( - +
- {logDesc.eventFragment.inputs[i].name}{" "} + {paramTypes[i].name}{" "} ({i}) {logDesc.eventFragment.inputs[i].type}{paramTypes[i].type} - {logDesc.eventFragment.inputs[i].type === "address" ? ( + {paramTypes[i].type === "address" ? (
= ({ txData, logDesc }) => (
); -export default React.memo(DecodedLog); +export default React.memo(DecodedParamsTable); diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 9328e41..bea1587 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -31,7 +31,7 @@ import ExternalLink from "../components/ExternalLink"; import RelativePosition from "../components/RelativePosition"; import PercentagePosition from "../components/PercentagePosition"; import ModeTab from "../components/ModeTab"; -import DecodedInput from "./DecodedInput"; +import DecodedParamsTable from "./DecodedParamsTable"; type DetailsProps = { txData: TransactionData; @@ -327,7 +327,11 @@ const Details: React.FC = ({ ) : txDesc === null ? ( <>No decoded data ) : ( - + )} diff --git a/src/transaction/LogEntry.tsx b/src/transaction/LogEntry.tsx index 7e78ff7..438cb6f 100644 --- a/src/transaction/LogEntry.tsx +++ b/src/transaction/LogEntry.tsx @@ -4,7 +4,7 @@ import { LogDescription } from "@ethersproject/abi"; import { Tab } from "@headlessui/react"; import DecoratedAddressLink from "../components/DecoratedAddressLink"; import ModeTab from "../components/ModeTab"; -import DecodedLog from "./DecodedLog"; +import DecodedParamsTable from "./DecodedParamsTable"; import DecodedLogSignature from "./DecodedLogSignature"; import { TransactionData } from "../types"; @@ -53,7 +53,11 @@ const LogEntry: React.FC = ({ txData, log, logDesc }) => (
Name
- +