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-23 21:25:52 +00:00
|
|
|
import { useAppConfigContext } from "../useAppConfig";
|
2021-09-20 21:15:00 +00:00
|
|
|
import { Metadata, useMultipleMetadata } from "../useSourcify";
|
2021-10-31 01:44:33 +00:00
|
|
|
import { ResolvedAddresses } from "../api/address-resolver";
|
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-10-31 01:44:33 +00:00
|
|
|
resolvedAddresses: ResolvedAddresses | undefined;
|
2021-07-14 19:30:28 +00:00
|
|
|
};
|
|
|
|
|
2021-10-31 01:44:33 +00:00
|
|
|
const Logs: React.FC<LogsProps> = ({ txData, metadata, resolvedAddresses }) => {
|
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]);
|
|
|
|
|
2021-09-23 21:25:52 +00:00
|
|
|
const { sourcifySource } = useAppConfigContext();
|
2021-09-20 21:15:00 +00:00
|
|
|
const logAddresses = useMemo(
|
|
|
|
() => txData.confirmedData?.logs.map((l) => l.address) ?? [],
|
|
|
|
[txData]
|
|
|
|
);
|
|
|
|
const metadatas = useMultipleMetadata(
|
|
|
|
baseMetadatas,
|
|
|
|
logAddresses,
|
|
|
|
1,
|
2021-09-23 21:25:52 +00:00
|
|
|
sourcifySource
|
2021-09-20 21:15:00 +00:00
|
|
|
);
|
2021-09-23 21:46:08 +00:00
|
|
|
const logDescs = 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) {
|
2021-09-23 21:46:08 +00:00
|
|
|
return mt;
|
2021-09-20 21:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
2021-09-23 21:33:20 +00:00
|
|
|
{txData.confirmedData && (
|
|
|
|
<>
|
|
|
|
{txData.confirmedData.logs.length > 0 ? (
|
|
|
|
<>
|
|
|
|
{txData.confirmedData.logs.map((l, i) => (
|
|
|
|
<LogEntry
|
|
|
|
key={i}
|
|
|
|
log={l}
|
2021-09-23 21:46:08 +00:00
|
|
|
logDesc={logDescs?.[i]}
|
2021-10-31 01:44:33 +00:00
|
|
|
resolvedAddresses={resolvedAddresses}
|
2021-09-23 21:33:20 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div className="text-sm py-4">Transaction didn't emit any logs</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2021-09-17 22:42:19 +00:00
|
|
|
</ContentFrame>
|
|
|
|
);
|
|
|
|
};
|
2021-07-14 19:30:28 +00:00
|
|
|
|
|
|
|
export default React.memo(Logs);
|