From f612e4791a1ec589acd9f247bc0b62d518b4a353 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 25 Sep 2021 15:11:57 -0300 Subject: [PATCH] Better display of array tx input parameters --- src/transaction/DecodedParamRow.tsx | 34 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/transaction/DecodedParamRow.tsx b/src/transaction/DecodedParamRow.tsx index 5678ac8..aec65ce 100644 --- a/src/transaction/DecodedParamRow.tsx +++ b/src/transaction/DecodedParamRow.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { ReactNode } from "react"; import AddressHighlighter from "../components/AddressHighlighter"; import DecoratedAddressLink from "../components/DecoratedAddressLink"; import Copy from "../components/Copy"; @@ -6,11 +6,12 @@ import { ParamType } from "@ethersproject/abi"; import { TransactionData } from "../types"; type DecodedParamRowProps = { - prefix?: string; + prefix?: ReactNode; i?: number | undefined; r: any; paramType: ParamType; txData: TransactionData; + arrayElem?: number | undefined; }; const DecodedParamRow: React.FC = ({ @@ -19,15 +20,24 @@ const DecodedParamRow: React.FC = ({ r, paramType, txData, + arrayElem, }) => { return ( <> {prefix && {prefix}} - {paramType.name ?? param_{i}}{" "} - {i !== undefined && ( - ({i}) + {arrayElem !== undefined ? ( + {" "} + [{arrayElem}] + + ) : ( + <> + {paramType.name ?? param_{i}}{" "} + {i !== undefined && ( + ({i}) + )} + )} {paramType.type} @@ -56,7 +66,8 @@ const DecodedParamRow: React.FC = ({ {r.toString().length / 2 - 1 === 1 ? "byte" : "bytes"} - ) : paramType.baseType === "tuple" ? ( + ) : paramType.baseType === "tuple" || + paramType.baseType === "array" ? ( <> ) : ( r.toString() @@ -73,6 +84,17 @@ const DecodedParamRow: React.FC = ({ txData={txData} /> ))} + {paramType.baseType === "array" && + r.map((e: any, idx: number) => ( + param_{i}} + r={e} + paramType={paramType.arrayChildren} + txData={txData} + arrayElem={idx} + /> + ))} ); };