2021-09-17 22:42:19 +00:00
|
|
|
import React, { useMemo } from "react";
|
|
|
|
import { Interface } from "@ethersproject/abi";
|
2021-07-14 19:30:28 +00:00
|
|
|
import ContentFrame from "../ContentFrame";
|
2021-09-17 22:42:19 +00:00
|
|
|
import LogEntry from "./LogEntry";
|
2021-07-14 19:30:28 +00:00
|
|
|
import { TransactionData } from "../types";
|
2021-09-20 21:15:00 +00:00
|
|
|
import { Metadata, useMultipleMetadata } from "../useSourcify";
|
|
|
|
import { SourcifySource } from "../url";
|
2021-07-14 19:30:28 +00:00
|
|
|
|
|
|
|
type LogsProps = {
|
|
|
|
txData: TransactionData;
|
2021-09-17 22:42:19 +00:00
|
|
|
metadata: Metadata | null | undefined;
|
2021-07-14 19:30:28 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 22:42:19 +00:00
|
|
|
const Logs: React.FC<LogsProps> = ({ txData, metadata }) => {
|
2021-09-20 21:15:00 +00:00
|
|
|
const baseMetadatas = useMemo((): Record<string, Metadata | null> => {
|
|
|
|
if (!txData.to || metadata === undefined) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const md: Record<string, Metadata | null> = {};
|
|
|
|
md[txData.to] = metadata;
|
|
|
|
return md;
|
|
|
|
}, [txData.to, metadata]);
|
|
|
|
|
|
|
|
const logAddresses = useMemo(
|
|
|
|
() => txData.confirmedData?.logs.map((l) => l.address) ?? [],
|
|
|
|
[txData]
|
|
|
|
);
|
|
|
|
const metadatas = useMultipleMetadata(
|
|
|
|
baseMetadatas,
|
|
|
|
logAddresses,
|
|
|
|
1,
|
2021-09-22 18:11:13 +00:00
|
|
|
SourcifySource.CENTRAL_SERVER // TODO: use dynamic selector
|
2021-09-20 21:15:00 +00:00
|
|
|
);
|
2021-09-17 22:42:19 +00:00
|
|
|
const logDesc = useMemo(() => {
|
2021-09-22 18:11:13 +00:00
|
|
|
if (!txData) {
|
2021-09-17 22:42:19 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-09-20 21:15:00 +00:00
|
|
|
return txData.confirmedData?.logs.map((l) => {
|
|
|
|
const mt = metadatas[l.address];
|
|
|
|
if (!mt) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const abi = mt.output.abi;
|
|
|
|
const intf = new Interface(abi as any);
|
2021-09-22 18:11:13 +00:00
|
|
|
try {
|
|
|
|
return intf.parseLog({
|
|
|
|
topics: l.topics,
|
|
|
|
data: l.data,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.warn("Couldn't find function signature", err);
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-20 21:15:00 +00:00
|
|
|
});
|
2021-09-22 18:11:13 +00:00
|
|
|
}, [metadatas, txData]);
|
2021-09-17 22:42:19 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ContentFrame tabs>
|
|
|
|
<div className="text-sm py-4">Transaction Receipt Event Logs</div>
|
|
|
|
{txData.confirmedData &&
|
|
|
|
txData.confirmedData.logs.map((l, i) => (
|
2021-09-18 22:38:35 +00:00
|
|
|
<LogEntry key={i} txData={txData} log={l} logDesc={logDesc?.[i]} />
|
2021-09-17 22:42:19 +00:00
|
|
|
))}
|
|
|
|
</ContentFrame>
|
|
|
|
);
|
|
|
|
};
|
2021-07-14 19:30:28 +00:00
|
|
|
|
|
|
|
export default React.memo(Logs);
|