Remove AddressCollectors and batchResolver
This commit is contained in:
parent
ff0fd63ab9
commit
7df1babd27
|
@ -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) {
|
||||
|
|
|
@ -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<AddressTransactionResultsProps> = ({
|
|||
}, [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];
|
||||
|
|
|
@ -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<ResolvedAddresses> => {
|
||||
const solvers: Promise<SelectedResolvedName<any> | 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;
|
||||
};
|
||||
|
|
|
@ -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<BlockTransactionResultsProps> = ({
|
|||
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);
|
||||
|
||||
|
|
|
@ -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<TraceProps> = ({ txData }) => {
|
|||
const uniqueSignatures = useUniqueSignatures(traces);
|
||||
const sigMap = useBatch4Bytes(uniqueSignatures);
|
||||
|
||||
const addrCollector = useMemo(() => tracesCollector(traces), [traces]);
|
||||
|
||||
return (
|
||||
<ContentFrame tabs>
|
||||
<div className="mt-4 mb-5 space-y-3 font-code text-sm flex flex-col items-start overflow-x-auto">
|
||||
|
|
|
@ -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<string>();
|
||||
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<string>();
|
||||
|
||||
// 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<string>();
|
||||
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<ResolvedAddresses>();
|
||||
const ref = useRef<ResolvedAddresses | undefined>();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue