diff --git a/src/Transaction.tsx b/src/Transaction.tsx index 62a23d6..22873d0 100644 --- a/src/Transaction.tsx +++ b/src/Transaction.tsx @@ -11,7 +11,6 @@ import { useInternalOperations, useTxData } from "./useErigonHooks"; import { useETHUSDOracle } from "./usePriceOracle"; import { useAppConfigContext } from "./useAppConfig"; import { useSourcify, useTransactionDescription } from "./sourcify/useSourcify"; -import { transactionDataCollector } from "./useResolvedAddresses"; import { SelectedTransactionContext } from "./useSelectedTransaction"; const Details = React.lazy( @@ -42,11 +41,6 @@ const Transaction: React.FC = () => { } const txData = useTxData(provider, txhash); - const addrCollector = useMemo( - () => transactionDataCollector(txData), - [txData] - ); - const internalOps = useInternalOperations(provider, txData); const sendsEthToMiner = useMemo(() => { if (!txData || !internalOps) { diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index 0b62115..8ca2118 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -10,7 +10,6 @@ import { useFeeToggler } from "../search/useFeeToggler"; import { SelectionContext, useSelection } from "../useSelection"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; import { RuntimeContext } from "../useRuntime"; -import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses"; import { useParams, useSearchParams } from "react-router-dom"; import { ChecksummedAddress } from "../types"; import { useContractsMetadata } from "../hooks"; @@ -102,9 +101,6 @@ const AddressTransactionResults: React.FC = ({ }, [page]); const priceMap = useMultipleETHUSDOracle(provider, blockTags); - // Resolve all addresses that appear on this page results - const addrCollector = useMemo(() => pageCollector(page), [page]); - // Calculate Sourcify metadata for all addresses that appear on this page results const addresses = useMemo(() => { const _addresses = [address]; diff --git a/src/api/address-resolver/index.ts b/src/api/address-resolver/index.ts index c6a1687..57f1b37 100644 --- a/src/api/address-resolver/index.ts +++ b/src/api/address-resolver/index.ts @@ -1,4 +1,3 @@ -import { BaseProvider } from "@ethersproject/providers"; import { ensRenderer } from "../../components/ENSName"; import { plainStringRenderer } from "../../components/PlainString"; import { tokenRenderer } from "../../components/TokenName"; @@ -48,30 +47,3 @@ resolverRendererRegistry.set(uniswapV2Resolver, uniswapV2PairRenderer); resolverRendererRegistry.set(uniswapV3Resolver, uniswapV3PairRenderer); resolverRendererRegistry.set(ercTokenResolver, tokenRenderer); resolverRendererRegistry.set(hardcodedResolver, plainStringRenderer); - -// TODO: implement progressive resolving -export const batchPopulate = async ( - provider: BaseProvider, - addresses: string[], - currentMap: ResolvedAddresses | undefined -): Promise => { - const solvers: Promise | undefined>[] = []; - const unresolvedAddresses = addresses.filter( - (a) => currentMap?.[a] === undefined - ); - for (const a of unresolvedAddresses) { - solvers.push(mainResolver.resolveAddress(provider, a)); - } - - const resultMap: ResolvedAddresses = currentMap ? { ...currentMap } : {}; - const results = await Promise.all(solvers); - for (let i = 0; i < results.length; i++) { - const r = results[i]; - if (r === undefined) { - continue; - } - resultMap[unresolvedAddresses[i]] = r; - } - - return resultMap; -}; diff --git a/src/block/BlockTransactionResults.tsx b/src/block/BlockTransactionResults.tsx index f41a6f4..2d768cc 100644 --- a/src/block/BlockTransactionResults.tsx +++ b/src/block/BlockTransactionResults.tsx @@ -8,7 +8,6 @@ import TransactionItem from "../search/TransactionItem"; import { useFeeToggler } from "../search/useFeeToggler"; import { RuntimeContext } from "../useRuntime"; import { SelectionContext, useSelection } from "../useSelection"; -import { pageCollector } from "../useResolvedAddresses"; import { ChecksummedAddress, ProcessedTransaction } from "../types"; import { PAGE_SIZE } from "../params"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; @@ -30,7 +29,6 @@ const BlockTransactionResults: React.FC = ({ const { provider } = useContext(RuntimeContext); const selectionCtx = useSelection(); const [feeDisplay, feeDisplayToggler] = useFeeToggler(); - const addrCollector = useMemo(() => pageCollector(page), [page]); const blockTags = useMemo(() => [blockTag], [blockTag]); const priceMap = useMultipleETHUSDOracle(provider, blockTags); diff --git a/src/transaction/Trace.tsx b/src/transaction/Trace.tsx index dcdab74..565192e 100644 --- a/src/transaction/Trace.tsx +++ b/src/transaction/Trace.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useMemo } from "react"; +import React, { useContext } from "react"; import ContentFrame from "../ContentFrame"; import TransactionAddress from "../components/TransactionAddress"; import TraceItem from "./TraceItem"; @@ -6,7 +6,6 @@ import { TransactionData } from "../types"; import { useBatch4Bytes } from "../use4Bytes"; import { useTraceTransaction, useUniqueSignatures } from "../useErigonHooks"; import { RuntimeContext } from "../useRuntime"; -import { tracesCollector } from "../useResolvedAddresses"; type TraceProps = { txData: TransactionData; @@ -18,8 +17,6 @@ const Trace: React.FC = ({ txData }) => { const uniqueSignatures = useUniqueSignatures(traces); const sigMap = useBatch4Bytes(uniqueSignatures); - const addrCollector = useMemo(() => tracesCollector(traces), [traces]); - return (
diff --git a/src/useResolvedAddresses.ts b/src/useResolvedAddresses.ts index d7c3cb9..266a377 100644 --- a/src/useResolvedAddresses.ts +++ b/src/useResolvedAddresses.ts @@ -1,20 +1,11 @@ -import { useState, useEffect, useRef, useContext } from "react"; -import { BaseProvider, JsonRpcProvider } from "@ethersproject/providers"; +import { useState, useEffect, useContext } from "react"; +import { BaseProvider } from "@ethersproject/providers"; import { getAddress, isAddress } from "@ethersproject/address"; import useSWR from "swr"; -import { - batchPopulate, - mainResolver, - ResolvedAddresses, -} from "./api/address-resolver"; +import { mainResolver } from "./api/address-resolver"; import { SelectedResolvedName } from "./api/address-resolver/CompositeAddressResolver"; -import { TraceGroup } from "./useErigonHooks"; import { RuntimeContext } from "./useRuntime"; -import { - ChecksummedAddress, - ProcessedTransaction, - TransactionData, -} from "./types"; +import { ChecksummedAddress } from "./types"; export const useAddressOrENSFromURL = ( addressOrName: string, @@ -75,122 +66,6 @@ export const useAddressOrENSFromURL = ( return [checksummedAddress, isENS, error]; }; -export type AddressCollector = () => string[]; - -export const pageCollector = - (page: ProcessedTransaction[] | undefined): AddressCollector => - () => { - if (!page) { - return []; - } - - const uniqueAddresses = new Set(); - for (const tx of page) { - if (tx.from) { - uniqueAddresses.add(tx.from); - } - if (tx.to) { - uniqueAddresses.add(tx.to); - } - if (tx.createdContractAddress) { - uniqueAddresses.add(tx.createdContractAddress); - } - } - - return Array.from(uniqueAddresses); - }; - -export const transactionDataCollector = - (txData: TransactionData | null | undefined): AddressCollector => - () => { - if (!txData) { - return []; - } - - const uniqueAddresses = new Set(); - - // Standard fields - uniqueAddresses.add(txData.from); - if (txData.to) { - uniqueAddresses.add(txData.to); - } - if (txData.confirmedData?.createdContractAddress) { - uniqueAddresses.add(txData.confirmedData?.createdContractAddress); - } - - // Dig token transfers - for (const t of txData.tokenTransfers) { - uniqueAddresses.add(t.from); - uniqueAddresses.add(t.to); - uniqueAddresses.add(t.token); - } - - // Dig log addresses - if (txData.confirmedData) { - for (const l of txData.confirmedData.logs) { - uniqueAddresses.add(l.address); - // TODO: find a way to dig over decoded address log attributes - } - } - - return Array.from(uniqueAddresses); - }; - -export const tracesCollector = - (traces: TraceGroup[] | undefined): AddressCollector => - () => { - if (traces === undefined) { - return []; - } - - const uniqueAddresses = new Set(); - let searchTraces = [...traces]; - while (searchTraces.length > 0) { - const nextSearch: TraceGroup[] = []; - - for (const g of searchTraces) { - uniqueAddresses.add(g.from); - uniqueAddresses.add(g.to); - if (g.children) { - nextSearch.push(...g.children); - } - } - - searchTraces = nextSearch; - } - return Array.from(uniqueAddresses); - }; - -export const useResolvedAddresses = ( - provider: JsonRpcProvider | undefined, - addrCollector: AddressCollector -) => { - const [names, setNames] = useState(); - const ref = useRef(); - useEffect(() => { - ref.current = names; - }); - - useEffect( - () => { - if (!provider) { - return; - } - - const populate = async () => { - const _addresses = addrCollector(); - const _names = await batchPopulate(provider, _addresses, ref.current); - setNames(_names); - }; - populate(); - }, - // DON'T put names variables in dependency array; this is intentional; useRef - [provider, addrCollector] - ); - - return names; -}; - export const useResolvedAddress = ( provider: BaseProvider | undefined, address: ChecksummedAddress