From c3dfcfeee385f49ec36bd330d09cb4dff7b42eb6 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 30 Nov 2021 16:31:39 -0300 Subject: [PATCH 1/4] Add still unoptimized check for addresses with code --- src/address/AddressTransactionResults.tsx | 10 ++++-- src/block/BlockTransactionResults.tsx | 10 ++++-- src/sourcify/useSourcify.ts | 44 +++++++++++++---------- src/transaction/Details.tsx | 12 +++++-- src/transaction/Logs.tsx | 11 ++++-- src/useErigonHooks.ts | 40 +++++++++++++++++++++ 6 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index b13bbd2..4c85c6c 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -8,7 +8,11 @@ import TransactionItem from "../search/TransactionItem"; import UndefinedPageControl from "../search/UndefinedPageControl"; import { useFeeToggler } from "../search/useFeeToggler"; import { SelectionContext, useSelection } from "../useSelection"; -import { useMultipleMetadata } from "../sourcify/useSourcify"; +import { + useDedupedAddresses, + useMultipleMetadata, +} from "../sourcify/useSourcify"; +import { useAddressCodes } from "../useErigonHooks"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; import { RuntimeContext } from "../useRuntime"; import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses"; @@ -120,9 +124,11 @@ const AddressTransactionResults: React.FC = ({ return _addresses; }, [address, page]); const { sourcifySource } = useAppConfigContext(); + const deduped = useDedupedAddresses(addresses); + const checked = useAddressCodes(provider, deduped); const metadatas = useMultipleMetadata( undefined, - addresses, + checked, provider?.network.chainId, sourcifySource ); diff --git a/src/block/BlockTransactionResults.tsx b/src/block/BlockTransactionResults.tsx index f2d8d08..891637b 100644 --- a/src/block/BlockTransactionResults.tsx +++ b/src/block/BlockTransactionResults.tsx @@ -13,7 +13,11 @@ import { ChecksummedAddress, ProcessedTransaction } from "../types"; import { PAGE_SIZE } from "../params"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; import { useAppConfigContext } from "../useAppConfig"; -import { useMultipleMetadata } from "../sourcify/useSourcify"; +import { + useDedupedAddresses, + useMultipleMetadata, +} from "../sourcify/useSourcify"; +import { useAddressCodes } from "../useErigonHooks"; type BlockTransactionResultsProps = { blockTag: BlockTag; @@ -44,9 +48,11 @@ const BlockTransactionResults: React.FC = ({ return page.map((t) => t.to).filter((to): to is string => to !== undefined); }, [page]); const { sourcifySource } = useAppConfigContext(); + const deduped = useDedupedAddresses(addresses); + const checked = useAddressCodes(provider, deduped); const metadatas = useMultipleMetadata( undefined, - addresses, + checked, provider?.network.chainId, sourcifySource ); diff --git a/src/sourcify/useSourcify.ts b/src/sourcify/useSourcify.ts index e4d1ab1..6b1e5d6 100644 --- a/src/sourcify/useSourcify.ts +++ b/src/sourcify/useSourcify.ts @@ -131,51 +131,57 @@ export const useSingleMetadata = ( return address !== undefined ? metadatas[address] : undefined; }; +export const useDedupedAddresses = ( + addresses: (ChecksummedAddress | undefined)[] +): ChecksummedAddress[] => { + return useMemo(() => { + const deduped = new Set( + addresses.filter((a): a is ChecksummedAddress => a !== undefined) + ); + return [...deduped]; + }, [addresses]); +}; + export const useMultipleMetadata = ( baseMetadatas: Record | undefined, - addresses: (ChecksummedAddress | undefined)[], + addresses: ChecksummedAddress[] | undefined, chainId: number | undefined, source: SourcifySource ): Record => { const [rawMetadata, setRawMetadata] = useState< Record >({}); - useEffect(() => { - if (!addresses || chainId === undefined) { + if (addresses === undefined || chainId === undefined) { return; } setRawMetadata({}); const abortController = new AbortController(); - const fetchMetadata = async (dedupedAddresses: string[]) => { - const promises: Promise[] = []; - for (const address of dedupedAddresses) { - promises.push( + const fetchMetadata = async (_addresses: string[]) => { + const fetchers: Promise[] = []; + for (const address of _addresses) { + fetchers.push( fetchSourcifyMetadata(address, chainId, source, abortController) ); } - const results = await Promise.all(promises); + const results = await Promise.all(fetchers); if (abortController.signal.aborted) { return; } - const metadatas: Record = baseMetadatas - ? { ...baseMetadatas } - : {}; + let metadatas: Record = {}; + if (baseMetadatas) { + metadatas = { ...baseMetadatas }; + } for (let i = 0; i < results.length; i++) { - metadatas[dedupedAddresses[i]] = results[i]; + metadatas[_addresses[i]] = results[i]; } setRawMetadata(metadatas); }; - const deduped = new Set( - addresses.filter( - (a): a is ChecksummedAddress => - a !== undefined && baseMetadatas?.[a] === undefined - ) - ); - fetchMetadata(Array.from(deduped)); + const filtered = addresses.filter((a) => baseMetadatas?.[a] === undefined); + fetchMetadata(filtered); return () => { abortController.abort(); diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 994ab51..8799987 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -37,7 +37,13 @@ import { use4Bytes, useTransactionDescription, } from "../use4Bytes"; -import { DevDoc, useMultipleMetadata, UserDoc } from "../sourcify/useSourcify"; +import { + DevDoc, + useDedupedAddresses, + useMultipleMetadata, + UserDoc, +} from "../sourcify/useSourcify"; +import { useAddressCodes } from "../useErigonHooks"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; import { useAppConfigContext } from "../useAppConfig"; @@ -96,9 +102,11 @@ const Details: React.FC = ({ return _addresses; }, [txData]); const { sourcifySource } = useAppConfigContext(); + const deduped = useDedupedAddresses(addresses); + const checked = useAddressCodes(provider, deduped); const metadatas = useMultipleMetadata( undefined, - addresses, + checked, provider?.network.chainId, sourcifySource ); diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index 4a9cc93..d907a37 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -4,7 +4,12 @@ import ContentFrame from "../ContentFrame"; import LogEntry from "./LogEntry"; import { TransactionData } from "../types"; import { useAppConfigContext } from "../useAppConfig"; -import { Metadata, useMultipleMetadata } from "../sourcify/useSourcify"; +import { + Metadata, + useDedupedAddresses, + useMultipleMetadata, +} from "../sourcify/useSourcify"; +import { useAddressCodes } from "../useErigonHooks"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; @@ -31,9 +36,11 @@ const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { ); const { provider } = useContext(RuntimeContext); const { sourcifySource } = useAppConfigContext(); + const deduped = useDedupedAddresses(logAddresses); + const checked = useAddressCodes(provider, deduped); const metadatas = useMultipleMetadata( baseMetadatas, - logAddresses, + checked, provider?.network.chainId, sourcifySource ); diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 17d629f..adbfce2 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -14,6 +14,7 @@ import { InternalOperation, ProcessedTransaction, OperationType, + ChecksummedAddress, } from "./types"; import erc20 from "./erc20.json"; @@ -440,3 +441,42 @@ export const useUniqueSignatures = (traces: TraceGroup[] | undefined) => { return uniqueSignatures; }; + +const checkCode = async ( + provider: JsonRpcProvider, + address: ChecksummedAddress +): Promise => { + const code = await provider.getCode(address); + if (code !== "0x") { + console.log(`Has code: ${address}`); + } + return code === "0x"; +}; + +export const useAddressCodes = ( + provider: JsonRpcProvider | undefined, + addresses: ChecksummedAddress[] +): ChecksummedAddress[] | undefined => { + const [hasCode, setCode] = useState(); + + useEffect(() => { + if (provider === undefined) { + setCode(undefined); + return; + } + + const readCodes = async () => { + const checkers: Promise[] = []; + for (const a of addresses) { + checkers.push(checkCode(provider, a)); + } + + const result = await Promise.all(checkers); + const filtered = addresses.filter((_, i) => result[i]); + setCode(filtered); + }; + readCodes(); + }, [provider, addresses]); + + return hasCode; +}; From 2e04c726d736f0fdc4fea7b96ecdc81ebb149b22 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Thu, 2 Dec 2021 15:34:06 -0300 Subject: [PATCH 2/4] Use new custom API to server-side check if address has code/is contract --- src/address/AddressTransactionResults.tsx | 4 ++-- src/block/BlockTransactionResults.tsx | 4 ++-- src/params.ts | 2 +- src/transaction/Details.tsx | 4 ++-- src/transaction/Logs.tsx | 4 ++-- src/useErigonHooks.ts | 21 +++++++++------------ 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index 4c85c6c..e565427 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -12,7 +12,7 @@ import { useDedupedAddresses, useMultipleMetadata, } from "../sourcify/useSourcify"; -import { useAddressCodes } from "../useErigonHooks"; +import { useAddressesWithCode } from "../useErigonHooks"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; import { RuntimeContext } from "../useRuntime"; import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses"; @@ -125,7 +125,7 @@ const AddressTransactionResults: React.FC = ({ }, [address, page]); const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressCodes(provider, deduped); + const checked = useAddressesWithCode(provider, deduped); const metadatas = useMultipleMetadata( undefined, checked, diff --git a/src/block/BlockTransactionResults.tsx b/src/block/BlockTransactionResults.tsx index 891637b..59d1ba6 100644 --- a/src/block/BlockTransactionResults.tsx +++ b/src/block/BlockTransactionResults.tsx @@ -17,7 +17,7 @@ import { useDedupedAddresses, useMultipleMetadata, } from "../sourcify/useSourcify"; -import { useAddressCodes } from "../useErigonHooks"; +import { useAddressesWithCode } from "../useErigonHooks"; type BlockTransactionResultsProps = { blockTag: BlockTag; @@ -49,7 +49,7 @@ const BlockTransactionResults: React.FC = ({ }, [page]); const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressCodes(provider, deduped); + const checked = useAddressesWithCode(provider, deduped); const metadatas = useMultipleMetadata( undefined, checked, diff --git a/src/params.ts b/src/params.ts index 5c95cfa..7ac916a 100644 --- a/src/params.ts +++ b/src/params.ts @@ -1,3 +1,3 @@ -export const MIN_API_LEVEL = 3; +export const MIN_API_LEVEL = 4; export const PAGE_SIZE = 25; diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 8799987..06e70d5 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -43,7 +43,7 @@ import { useMultipleMetadata, UserDoc, } from "../sourcify/useSourcify"; -import { useAddressCodes } from "../useErigonHooks"; +import { useAddressesWithCode } from "../useErigonHooks"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; import { useAppConfigContext } from "../useAppConfig"; @@ -103,7 +103,7 @@ const Details: React.FC = ({ }, [txData]); const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressCodes(provider, deduped); + const checked = useAddressesWithCode(provider, deduped); const metadatas = useMultipleMetadata( undefined, checked, diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index d907a37..acc2baa 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -9,7 +9,7 @@ import { useDedupedAddresses, useMultipleMetadata, } from "../sourcify/useSourcify"; -import { useAddressCodes } from "../useErigonHooks"; +import { useAddressesWithCode } from "../useErigonHooks"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; @@ -37,7 +37,7 @@ const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { const { provider } = useContext(RuntimeContext); const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(logAddresses); - const checked = useAddressCodes(provider, deduped); + const checked = useAddressesWithCode(provider, deduped); const metadatas = useMultipleMetadata( baseMetadatas, checked, diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index adbfce2..f722f03 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -442,41 +442,38 @@ export const useUniqueSignatures = (traces: TraceGroup[] | undefined) => { return uniqueSignatures; }; -const checkCode = async ( +const hasCode = async ( provider: JsonRpcProvider, address: ChecksummedAddress ): Promise => { - const code = await provider.getCode(address); - if (code !== "0x") { - console.log(`Has code: ${address}`); - } - return code === "0x"; + const result = await provider.send("ots_hasCode", [address, "latest"]); + return result as boolean; }; -export const useAddressCodes = ( +export const useAddressesWithCode = ( provider: JsonRpcProvider | undefined, addresses: ChecksummedAddress[] ): ChecksummedAddress[] | undefined => { - const [hasCode, setCode] = useState(); + const [results, setResults] = useState(); useEffect(() => { if (provider === undefined) { - setCode(undefined); + setResults(undefined); return; } const readCodes = async () => { const checkers: Promise[] = []; for (const a of addresses) { - checkers.push(checkCode(provider, a)); + checkers.push(hasCode(provider, a)); } const result = await Promise.all(checkers); const filtered = addresses.filter((_, i) => result[i]); - setCode(filtered); + setResults(filtered); }; readCodes(); }, [provider, addresses]); - return hasCode; + return results; }; From c40e653bef0e164a8177b69a453d8d411003ffcd Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Thu, 2 Dec 2021 15:42:59 -0300 Subject: [PATCH 3/4] Small refactorings --- src/address/AddressTransactionResults.tsx | 6 +++--- src/block/BlockTransactionResults.tsx | 6 +++--- src/sourcify/useSourcify.ts | 6 ++---- src/transaction/Details.tsx | 6 +++--- src/transaction/Logs.tsx | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index e565427..ce7cf45 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -123,12 +123,12 @@ const AddressTransactionResults: React.FC = ({ } return _addresses; }, [address, page]); - const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressesWithCode(provider, deduped); + const contracts = useAddressesWithCode(provider, deduped); + const { sourcifySource } = useAppConfigContext(); const metadatas = useMultipleMetadata( undefined, - checked, + contracts, provider?.network.chainId, sourcifySource ); diff --git a/src/block/BlockTransactionResults.tsx b/src/block/BlockTransactionResults.tsx index 59d1ba6..44caeb1 100644 --- a/src/block/BlockTransactionResults.tsx +++ b/src/block/BlockTransactionResults.tsx @@ -47,12 +47,12 @@ const BlockTransactionResults: React.FC = ({ return page.map((t) => t.to).filter((to): to is string => to !== undefined); }, [page]); - const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressesWithCode(provider, deduped); + const contracts = useAddressesWithCode(provider, deduped); + const { sourcifySource } = useAppConfigContext(); const metadatas = useMultipleMetadata( undefined, - checked, + contracts, provider?.network.chainId, sourcifySource ); diff --git a/src/sourcify/useSourcify.ts b/src/sourcify/useSourcify.ts index 6b1e5d6..85baaaa 100644 --- a/src/sourcify/useSourcify.ts +++ b/src/sourcify/useSourcify.ts @@ -132,12 +132,10 @@ export const useSingleMetadata = ( }; export const useDedupedAddresses = ( - addresses: (ChecksummedAddress | undefined)[] + addresses: ChecksummedAddress[] ): ChecksummedAddress[] => { return useMemo(() => { - const deduped = new Set( - addresses.filter((a): a is ChecksummedAddress => a !== undefined) - ); + const deduped = new Set(addresses); return [...deduped]; }, [addresses]); }; diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 06e70d5..aa7d393 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -101,12 +101,12 @@ const Details: React.FC = ({ } return _addresses; }, [txData]); - const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(addresses); - const checked = useAddressesWithCode(provider, deduped); + const contracts = useAddressesWithCode(provider, deduped); + const { sourcifySource } = useAppConfigContext(); const metadatas = useMultipleMetadata( undefined, - checked, + contracts, provider?.network.chainId, sourcifySource ); diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index acc2baa..dedb178 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -35,12 +35,12 @@ const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { [txData] ); const { provider } = useContext(RuntimeContext); - const { sourcifySource } = useAppConfigContext(); const deduped = useDedupedAddresses(logAddresses); - const checked = useAddressesWithCode(provider, deduped); + const contracts = useAddressesWithCode(provider, deduped); + const { sourcifySource } = useAppConfigContext(); const metadatas = useMultipleMetadata( baseMetadatas, - checked, + contracts, provider?.network.chainId, sourcifySource ); From 751ef0c9af900669c8c762c48f2955fedab5e195 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Thu, 2 Dec 2021 16:19:03 -0300 Subject: [PATCH 4/4] Extract higher level hook --- src/address/AddressTransactionResults.tsx | 17 ++------------ src/block/BlockTransactionResults.tsx | 17 ++------------ src/hooks.ts | 27 +++++++++++++++++++++++ src/transaction/Details.tsx | 20 +++-------------- src/transaction/Logs.tsx | 20 ++++------------- 5 files changed, 38 insertions(+), 63 deletions(-) create mode 100644 src/hooks.ts diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index ce7cf45..07f8e4f 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -8,17 +8,12 @@ import TransactionItem from "../search/TransactionItem"; import UndefinedPageControl from "../search/UndefinedPageControl"; import { useFeeToggler } from "../search/useFeeToggler"; import { SelectionContext, useSelection } from "../useSelection"; -import { - useDedupedAddresses, - useMultipleMetadata, -} from "../sourcify/useSourcify"; -import { useAddressesWithCode } from "../useErigonHooks"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; import { RuntimeContext } from "../useRuntime"; import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses"; -import { useAppConfigContext } from "../useAppConfig"; import { useParams, useSearchParams } from "react-router-dom"; import { ChecksummedAddress } from "../types"; +import { useContractsMetadata } from "../hooks"; type AddressTransactionResultsProps = { address: ChecksummedAddress; @@ -123,15 +118,7 @@ const AddressTransactionResults: React.FC = ({ } return _addresses; }, [address, page]); - const deduped = useDedupedAddresses(addresses); - const contracts = useAddressesWithCode(provider, deduped); - const { sourcifySource } = useAppConfigContext(); - const metadatas = useMultipleMetadata( - undefined, - contracts, - provider?.network.chainId, - sourcifySource - ); + const metadatas = useContractsMetadata(addresses, provider); return ( diff --git a/src/block/BlockTransactionResults.tsx b/src/block/BlockTransactionResults.tsx index 44caeb1..fc5bf9f 100644 --- a/src/block/BlockTransactionResults.tsx +++ b/src/block/BlockTransactionResults.tsx @@ -12,12 +12,7 @@ import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses"; import { ChecksummedAddress, ProcessedTransaction } from "../types"; import { PAGE_SIZE } from "../params"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; -import { useAppConfigContext } from "../useAppConfig"; -import { - useDedupedAddresses, - useMultipleMetadata, -} from "../sourcify/useSourcify"; -import { useAddressesWithCode } from "../useErigonHooks"; +import { useContractsMetadata } from "../hooks"; type BlockTransactionResultsProps = { blockTag: BlockTag; @@ -47,15 +42,7 @@ const BlockTransactionResults: React.FC = ({ return page.map((t) => t.to).filter((to): to is string => to !== undefined); }, [page]); - const deduped = useDedupedAddresses(addresses); - const contracts = useAddressesWithCode(provider, deduped); - const { sourcifySource } = useAppConfigContext(); - const metadatas = useMultipleMetadata( - undefined, - contracts, - provider?.network.chainId, - sourcifySource - ); + const metadatas = useContractsMetadata(addresses, provider); return ( diff --git a/src/hooks.ts b/src/hooks.ts new file mode 100644 index 0000000..a81f10b --- /dev/null +++ b/src/hooks.ts @@ -0,0 +1,27 @@ +import { JsonRpcProvider } from "@ethersproject/providers"; +import { ChecksummedAddress } from "./types"; +import { + Metadata, + useDedupedAddresses, + useMultipleMetadata, +} from "./sourcify/useSourcify"; +import { useAppConfigContext } from "./useAppConfig"; +import { useAddressesWithCode } from "./useErigonHooks"; + +export const useContractsMetadata = ( + addresses: ChecksummedAddress[], + provider: JsonRpcProvider | undefined, + baseMetadatas?: Record +) => { + const deduped = useDedupedAddresses(addresses); + const contracts = useAddressesWithCode(provider, deduped); + const { sourcifySource } = useAppConfigContext(); + const metadatas = useMultipleMetadata( + baseMetadatas, + contracts, + provider?.network.chainId, + sourcifySource + ); + + return metadatas; +}; diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index aa7d393..e4daf2f 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -37,16 +37,10 @@ import { use4Bytes, useTransactionDescription, } from "../use4Bytes"; -import { - DevDoc, - useDedupedAddresses, - useMultipleMetadata, - UserDoc, -} from "../sourcify/useSourcify"; -import { useAddressesWithCode } from "../useErigonHooks"; +import { DevDoc, UserDoc } from "../sourcify/useSourcify"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; -import { useAppConfigContext } from "../useAppConfig"; +import { useContractsMetadata } from "../hooks"; type DetailsProps = { txData: TransactionData; @@ -101,15 +95,7 @@ const Details: React.FC = ({ } return _addresses; }, [txData]); - const deduped = useDedupedAddresses(addresses); - const contracts = useAddressesWithCode(provider, deduped); - const { sourcifySource } = useAppConfigContext(); - const metadatas = useMultipleMetadata( - undefined, - contracts, - provider?.network.chainId, - sourcifySource - ); + const metadatas = useContractsMetadata(addresses, provider); return ( diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index dedb178..eba82e1 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -3,15 +3,10 @@ import { Interface } from "@ethersproject/abi"; import ContentFrame from "../ContentFrame"; import LogEntry from "./LogEntry"; import { TransactionData } from "../types"; -import { useAppConfigContext } from "../useAppConfig"; -import { - Metadata, - useDedupedAddresses, - useMultipleMetadata, -} from "../sourcify/useSourcify"; -import { useAddressesWithCode } from "../useErigonHooks"; +import { Metadata } from "../sourcify/useSourcify"; import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; +import { useContractsMetadata } from "../hooks"; type LogsProps = { txData: TransactionData; @@ -35,15 +30,8 @@ const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { [txData] ); const { provider } = useContext(RuntimeContext); - const deduped = useDedupedAddresses(logAddresses); - const contracts = useAddressesWithCode(provider, deduped); - const { sourcifySource } = useAppConfigContext(); - const metadatas = useMultipleMetadata( - baseMetadatas, - contracts, - provider?.network.chainId, - sourcifySource - ); + const metadatas = useContractsMetadata(logAddresses, provider, baseMetadatas); + const logDescs = useMemo(() => { if (!txData) { return undefined;