Add Sourcify decoration support to tx logs page

This commit is contained in:
Willian Mitsuda 2021-11-10 16:48:24 -03:00
parent 1794fff7f3
commit 0caf58ea29
4 changed files with 17 additions and 8 deletions

View File

@ -27,9 +27,7 @@ type TransactionItemProps = {
selectedAddress?: string; selectedAddress?: string;
feeDisplay: FeeDisplay; feeDisplay: FeeDisplay;
priceMap: Record<BlockTag, BigNumber>; priceMap: Record<BlockTag, BigNumber>;
metadatas: metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
| Record<ChecksummedAddress, Metadata | null | undefined>
| undefined;
}; };
const TransactionItem: React.FC<TransactionItemProps> = ({ const TransactionItem: React.FC<TransactionItemProps> = ({
@ -110,7 +108,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
miner={tx.miner === tx.to} miner={tx.miner === tx.to}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
metadata={metadatas?.[tx.to]} metadata={metadatas[tx.to]}
/> />
</AddressHighlighter> </AddressHighlighter>
) : ( ) : (
@ -120,7 +118,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
creation creation
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
metadata={metadatas?.[tx.createdContractAddress!]} metadata={metadatas[tx.createdContractAddress!]}
/> />
</AddressHighlighter> </AddressHighlighter>
)} )}

View File

@ -9,17 +9,21 @@ import DecodedParamsTable from "./decoder/DecodedParamsTable";
import DecodedLogSignature from "./decoder/DecodedLogSignature"; import DecodedLogSignature from "./decoder/DecodedLogSignature";
import { useTopic0 } from "../useTopic0"; import { useTopic0 } from "../useTopic0";
import { ResolvedAddresses } from "../api/address-resolver"; import { ResolvedAddresses } from "../api/address-resolver";
import { ChecksummedAddress } from "../types";
import { Metadata } from "../useSourcify";
type LogEntryProps = { type LogEntryProps = {
log: Log; log: Log;
logDesc: LogDescription | null | undefined; logDesc: LogDescription | null | undefined;
resolvedAddresses: ResolvedAddresses | undefined; resolvedAddresses: ResolvedAddresses | undefined;
metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
}; };
const LogEntry: React.FC<LogEntryProps> = ({ const LogEntry: React.FC<LogEntryProps> = ({
log, log,
logDesc, logDesc,
resolvedAddresses, resolvedAddresses,
metadatas,
}) => { }) => {
const rawTopic0 = log.topics[0]; const rawTopic0 = log.topics[0];
const topic0 = useTopic0(rawTopic0); const topic0 = useTopic0(rawTopic0);
@ -62,6 +66,7 @@ const LogEntry: React.FC<LogEntryProps> = ({
<TransactionAddress <TransactionAddress
address={log.address} address={log.address}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
metadata={metadatas[log.address]}
/> />
<Copy value={log.address} /> <Copy value={log.address} />
</div> </div>

View File

@ -1,4 +1,4 @@
import React, { useMemo } from "react"; import React, { useContext, useMemo } from "react";
import { Interface } from "@ethersproject/abi"; import { Interface } from "@ethersproject/abi";
import ContentFrame from "../ContentFrame"; import ContentFrame from "../ContentFrame";
import LogEntry from "./LogEntry"; import LogEntry from "./LogEntry";
@ -6,6 +6,7 @@ import { TransactionData } from "../types";
import { useAppConfigContext } from "../useAppConfig"; import { useAppConfigContext } from "../useAppConfig";
import { Metadata, useMultipleMetadata } from "../useSourcify"; import { Metadata, useMultipleMetadata } from "../useSourcify";
import { ResolvedAddresses } from "../api/address-resolver"; import { ResolvedAddresses } from "../api/address-resolver";
import { RuntimeContext } from "../useRuntime";
type LogsProps = { type LogsProps = {
txData: TransactionData; txData: TransactionData;
@ -24,15 +25,16 @@ const Logs: React.FC<LogsProps> = ({ txData, metadata, resolvedAddresses }) => {
return md; return md;
}, [txData.to, metadata]); }, [txData.to, metadata]);
const { sourcifySource } = useAppConfigContext();
const logAddresses = useMemo( const logAddresses = useMemo(
() => txData.confirmedData?.logs.map((l) => l.address) ?? [], () => txData.confirmedData?.logs.map((l) => l.address) ?? [],
[txData] [txData]
); );
const { provider } = useContext(RuntimeContext);
const { sourcifySource } = useAppConfigContext();
const metadatas = useMultipleMetadata( const metadatas = useMultipleMetadata(
baseMetadatas, baseMetadatas,
logAddresses, logAddresses,
1, provider?.network.chainId,
sourcifySource sourcifySource
); );
const logDescs = useMemo(() => { const logDescs = useMemo(() => {
@ -72,6 +74,7 @@ const Logs: React.FC<LogsProps> = ({ txData, metadata, resolvedAddresses }) => {
log={l} log={l}
logDesc={logDescs?.[i]} logDesc={logDescs?.[i]}
resolvedAddresses={resolvedAddresses} resolvedAddresses={resolvedAddresses}
metadatas={metadatas}
/> />
))} ))}
</> </>

View File

@ -147,6 +147,9 @@ export const useMultipleMetadata = (
} }
const results = await Promise.all(promises); const results = await Promise.all(promises);
if (abortController.signal.aborted) {
return;
}
const metadatas: Record<string, Metadata | null> = baseMetadatas const metadatas: Record<string, Metadata | null> = baseMetadatas
? { ...baseMetadatas } ? { ...baseMetadatas }
: {}; : {};