2021-09-25 18:11:57 +00:00
|
|
|
import React, { ReactNode } from "react";
|
2021-09-18 21:18:38 +00:00
|
|
|
import { ParamType } from "@ethersproject/abi";
|
2021-09-25 21:40:00 +00:00
|
|
|
import Uint256Decoder from "./Uint256Decoder";
|
2021-09-25 20:28:49 +00:00
|
|
|
import AddressDecoder from "./AddressDecoder";
|
|
|
|
import BooleanDecoder from "./BooleanDecoder";
|
|
|
|
import BytesDecoder from "./BytesDecoder";
|
2021-09-25 20:19:49 +00:00
|
|
|
import { TransactionData } from "../../types";
|
2021-09-18 21:18:38 +00:00
|
|
|
|
|
|
|
type DecodedParamRowProps = {
|
2021-09-25 18:11:57 +00:00
|
|
|
prefix?: ReactNode;
|
2021-09-18 21:18:38 +00:00
|
|
|
i?: number | undefined;
|
|
|
|
r: any;
|
|
|
|
paramType: ParamType;
|
|
|
|
txData: TransactionData;
|
2021-09-25 18:11:57 +00:00
|
|
|
arrayElem?: number | undefined;
|
2021-09-18 21:18:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const DecodedParamRow: React.FC<DecodedParamRowProps> = ({
|
2021-09-18 21:35:37 +00:00
|
|
|
prefix,
|
2021-09-18 21:18:38 +00:00
|
|
|
i,
|
|
|
|
r,
|
|
|
|
paramType,
|
|
|
|
txData,
|
2021-09-25 18:11:57 +00:00
|
|
|
arrayElem,
|
2021-09-25 20:28:49 +00:00
|
|
|
}) => (
|
|
|
|
<>
|
|
|
|
<tr className="grid grid-cols-12 gap-x-2 py-2 hover:bg-gray-100">
|
|
|
|
<td className="col-span-3 pl-1">
|
|
|
|
{prefix && <span className="text-gray-300">{prefix}</span>}
|
|
|
|
{arrayElem !== undefined ? (
|
|
|
|
<span className="text-gray-400">
|
|
|
|
{" "}
|
|
|
|
[<span className="text-black">{arrayElem}</span>]
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{paramType.name ?? <span className="italic">param_{i}</span>}{" "}
|
|
|
|
{i !== undefined && (
|
|
|
|
<span className="text-gray-400 text-xs">({i})</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
<td className="col-span-1 text-gray-500">{paramType.type}</td>
|
|
|
|
<td className="col-span-8 pr-1 font-code break-all">
|
2021-09-25 21:40:00 +00:00
|
|
|
{paramType.baseType === "uint256" ? (
|
|
|
|
<Uint256Decoder r={r} />
|
|
|
|
) : paramType.baseType === "address" ? (
|
2021-09-25 20:28:49 +00:00
|
|
|
<AddressDecoder r={r} txData={txData} />
|
|
|
|
) : paramType.baseType === "bool" ? (
|
|
|
|
<BooleanDecoder r={r} />
|
|
|
|
) : paramType.baseType === "bytes" ? (
|
|
|
|
<BytesDecoder r={r} />
|
|
|
|
) : paramType.baseType === "tuple" || paramType.baseType === "array" ? (
|
|
|
|
<></>
|
|
|
|
) : (
|
|
|
|
r.toString()
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{paramType.baseType === "tuple" &&
|
|
|
|
r.map((e: any, idx: number) => (
|
|
|
|
<DecodedParamRow
|
|
|
|
key={idx}
|
2021-09-25 22:37:14 +00:00
|
|
|
prefix={
|
|
|
|
paramType.name ? (
|
|
|
|
paramType.name + "."
|
|
|
|
) : (
|
|
|
|
<span className="italic">param_{i}.</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
i={idx}
|
2021-09-25 20:28:49 +00:00
|
|
|
r={e}
|
|
|
|
paramType={paramType.components[idx]}
|
|
|
|
txData={txData}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{paramType.baseType === "array" &&
|
|
|
|
r.map((e: any, idx: number) => (
|
|
|
|
<DecodedParamRow
|
|
|
|
key={idx}
|
|
|
|
prefix={paramType.name ?? <span className="italic">param_{i}</span>}
|
|
|
|
r={e}
|
|
|
|
paramType={paramType.arrayChildren}
|
|
|
|
txData={txData}
|
|
|
|
arrayElem={idx}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
2021-09-18 21:18:38 +00:00
|
|
|
|
|
|
|
export default React.memo(DecodedParamRow);
|