diff --git a/src/Transaction.tsx b/src/Transaction.tsx index 1857f72..2fc69a2 100644 --- a/src/Transaction.tsx +++ b/src/Transaction.tsx @@ -87,7 +87,7 @@ const Transaction: React.FC = () => { /> - + diff --git a/src/transaction/DecodedInput.tsx b/src/transaction/DecodedInput.tsx index f41406b..1e4bcd4 100644 --- a/src/transaction/DecodedInput.tsx +++ b/src/transaction/DecodedInput.tsx @@ -7,12 +7,14 @@ type DecodedInputProps = { const DecodedInput: React.FC = ({ txDesc }) => ( - - - param (index) - - type - value + + + + param (index) + + type + value + {txDesc.args.map((r, i) => ( diff --git a/src/transaction/DecodedLog.tsx b/src/transaction/DecodedLog.tsx new file mode 100644 index 0000000..a55da73 --- /dev/null +++ b/src/transaction/DecodedLog.tsx @@ -0,0 +1,34 @@ +import React from "react"; +import { LogDescription } from "@ethersproject/abi"; + +type DecodedLogProps = { + logDesc: LogDescription; +}; + +const DecodedLog: React.FC = ({ logDesc }) => ( + + + + + param (index) + + type + value + + + + {logDesc.args.map((r, i) => ( + + + {logDesc.eventFragment.inputs[i].name}{" "} + ({i}) + + {logDesc.eventFragment.inputs[i].type} + {r} + + ))} + + +); + +export default React.memo(DecodedLog); diff --git a/src/transaction/DecodedLogSignature.tsx b/src/transaction/DecodedLogSignature.tsx new file mode 100644 index 0000000..daceeee --- /dev/null +++ b/src/transaction/DecodedLogSignature.tsx @@ -0,0 +1,23 @@ +import React from "react"; +import { EventFragment } from "@ethersproject/abi"; + +type DecodedLogSignatureProps = { + event: EventFragment; +}; + +const DecodedLogSignature: React.FC = ({ event }) => { + return ( + + {event.name}( + {event.inputs.map((input, i) => ( + <> + {i > 0 ? ", " : ""} + {input.format("full")} + > + ))} + ){event.anonymous ? " anonymous" : ""} + + ); +}; + +export default React.memo(DecodedLogSignature); diff --git a/src/transaction/LogEntry.tsx b/src/transaction/LogEntry.tsx new file mode 100644 index 0000000..a41f070 --- /dev/null +++ b/src/transaction/LogEntry.tsx @@ -0,0 +1,75 @@ +import React from "react"; +import { Log } from "@ethersproject/abstract-provider"; +import { LogDescription } from "@ethersproject/abi"; +import DecoratedAddressLink from "../components/DecoratedAddressLink"; +import DecodedLog from "./DecodedLog"; +import DecodedLogSignature from "./DecodedLogSignature"; +import { TransactionData } from "../types"; + +type LogEntryProps = { + txData: TransactionData; + log: Log; + logDesc: LogDescription | null | undefined; +}; + +const LogEntry: React.FC = ({ txData, log, logDesc }) => ( + + + + {log.logIndex} + + + + + Address + + + + + {logDesc && ( + + Signature + + + + + )} + {logDesc && ( + + Name + + + + + )} + {log.topics.map((t, i) => ( + + {i === 0 && "Topics"} + + + {i} + + {t} + + + ))} + + Data + + + + + + +); + +export default React.memo(LogEntry); diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index e57dc6a..a727628 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -1,63 +1,45 @@ -import React from "react"; +import React, { useMemo } from "react"; +import { Interface } from "@ethersproject/abi"; import ContentFrame from "../ContentFrame"; -import DecoratedAddressLink from "../components/DecoratedAddressLink"; +import LogEntry from "./LogEntry"; import { TransactionData } from "../types"; +import { Metadata } from "../useSourcify"; type LogsProps = { txData: TransactionData; + metadata: Metadata | null | undefined; }; -const Logs: React.FC = ({ txData }) => ( - - Transaction Receipt Event Logs - {txData.confirmedData && - txData.confirmedData.logs.map((l, i) => ( - - - - {l.logIndex} - - - - - Address - - - - - {l.topics.map((t, i) => ( - - {i === 0 && "Topics"} - - - {i} - - {t} - - - ))} - - Data - - - - - - - ))} - -); +const Logs: React.FC = ({ txData, metadata }) => { + const logDesc = useMemo(() => { + if (!metadata || !txData) { + return undefined; + } + + const abi = metadata.output.abi; + const intf = new Interface(abi as any); + return txData.confirmedData?.logs.map((l) => + intf.parseLog({ + topics: l.topics, + data: l.data, + }) + ); + }, [metadata, txData]); + + return ( + + Transaction Receipt Event Logs + {txData.confirmedData && + txData.confirmedData.logs.map((l, i) => ( + + ))} + + ); +}; export default React.memo(Logs); diff --git a/src/useSourcify.ts b/src/useSourcify.ts index 61022c7..8c1d52f 100644 --- a/src/useSourcify.ts +++ b/src/useSourcify.ts @@ -133,7 +133,6 @@ export const useTransactionDescription = ( const abi = metadata.output.abi; const intf = new Interface(abi as any); - console.log(intf); return intf.parseTransaction({ data: txData.data, value: txData.value,