diff --git a/src/transaction/LogEntry.tsx b/src/transaction/LogEntry.tsx index e06c558..64ba207 100644 --- a/src/transaction/LogEntry.tsx +++ b/src/transaction/LogEntry.tsx @@ -1,6 +1,6 @@ -import React, { Fragment } from "react"; +import React, { useMemo } from "react"; import { Log } from "@ethersproject/abstract-provider"; -import { LogDescription } from "@ethersproject/abi"; +import { Fragment, Interface, LogDescription } from "@ethersproject/abi"; import { Tab } from "@headlessui/react"; import AddressHighlighter from "../components/AddressHighlighter"; import DecoratedAddressLink from "../components/DecoratedAddressLink"; @@ -9,6 +9,7 @@ import ModeTab from "../components/ModeTab"; import DecodedParamsTable from "./decoder/DecodedParamsTable"; import DecodedLogSignature from "./decoder/DecodedLogSignature"; import { TransactionData } from "../types"; +import { useTopic0 } from "../useTopic0"; type LogEntryProps = { txData: TransactionData; @@ -16,101 +17,126 @@ type LogEntryProps = { logDesc: LogDescription | null | undefined; }; -const LogEntry: React.FC = ({ txData, log, logDesc }) => ( -
-
- - {log.logIndex} - -
-
-
-
Address
-
-
- - - - +const LogEntry: React.FC = ({ txData, log, logDesc }) => { + const rawTopic0 = log.topics[0]; + const topic0 = useTopic0(rawTopic0); + + const topic0LogDesc = useMemo(() => { + if (!topic0?.signature) { + return undefined; + } + const sig = topic0.signature; + const logFragment = Fragment.fromString(`event ${sig}`); + const intf = new Interface([logFragment]); + try { + return intf.parseLog(log); + } catch (err) { + // TODO: try other indexed/non-indexed combinations? + console.error(err); + return undefined; + } + }, [topic0, log]); + + const resolvedLogDesc = logDesc ?? topic0LogDesc; + + return ( +
+
+ + {log.logIndex} + +
+
+
+
Address
+
+
+ + + + +
-
- - -
Parameters
-
- Decoded - Raw -
-
- - - {logDesc === undefined ? ( -
-
- Waiting for data... -
-
- ) : logDesc === null ? ( -
-
- No decoded data -
-
- ) : ( - <> -
-
- -
-
+ + +
Parameters
+
+ Decoded + Raw +
+
+ + + {resolvedLogDesc === undefined ? (
- + Waiting for data...
- - )} -
- - {log.topics.map((t, i) => ( -
-
{i === 0 && "Topics"}
-
- - {i} - - {t} + ) : resolvedLogDesc === null ? ( +
+
+ No decoded data +
+
+ ) : ( + <> +
+
+ +
+
+
+
+ +
+
+ + )} + + + {log.topics.map((t, i) => ( +
+
{i === 0 && "Topics"}
+
+ + {i} + + {t} +
+
+ ))} +
+
Data
+
+