diff --git a/src/TokenTransferItem.tsx b/src/TokenTransferItem.tsx index 9e49ee4..2cf91a0 100644 --- a/src/TokenTransferItem.tsx +++ b/src/TokenTransferItem.tsx @@ -10,13 +10,11 @@ import { TokenMeta, TokenTransfer, } from "./types"; -import { ResolvedAddresses } from "./api/address-resolver"; import { Metadata } from "./sourcify/useSourcify"; type TokenTransferItemProps = { t: TokenTransfer; tokenMeta?: TokenMeta | null | undefined; - resolvedAddresses: ResolvedAddresses | undefined; metadatas: Record; }; @@ -24,7 +22,6 @@ type TokenTransferItemProps = { const TokenTransferItem: React.FC = ({ t, tokenMeta, - resolvedAddresses, metadatas, }) => (
@@ -37,7 +34,6 @@ const TokenTransferItem: React.FC = ({
@@ -46,7 +42,6 @@ const TokenTransferItem: React.FC = ({ @@ -60,11 +55,7 @@ const TokenTransferItem: React.FC = ({ /> - + diff --git a/src/Transaction.tsx b/src/Transaction.tsx index 5101193..22873d0 100644 --- a/src/Transaction.tsx +++ b/src/Transaction.tsx @@ -11,10 +11,6 @@ import { useInternalOperations, useTxData } from "./useErigonHooks"; import { useETHUSDOracle } from "./usePriceOracle"; import { useAppConfigContext } from "./useAppConfig"; import { useSourcify, useTransactionDescription } from "./sourcify/useSourcify"; -import { - transactionDataCollector, - useResolvedAddresses, -} from "./useResolvedAddresses"; import { SelectedTransactionContext } from "./useSelectedTransaction"; const Details = React.lazy( @@ -45,12 +41,6 @@ const Transaction: React.FC = () => { } const txData = useTxData(provider, txhash); - const addrCollector = useMemo( - () => transactionDataCollector(txData), - [txData] - ); - const resolvedAddresses = useResolvedAddresses(provider, addrCollector); - const internalOps = useInternalOperations(provider, txData); const sendsEthToMiner = useMemo(() => { if (!txData || !internalOps) { @@ -119,29 +109,14 @@ const Transaction: React.FC = () => { internalOps={internalOps} sendsEthToMiner={sendsEthToMiner} ethUSDPrice={blockETHUSDPrice} - resolvedAddresses={resolvedAddresses} /> } /> - } - /> - - } + element={} /> + } /> diff --git a/src/address/AddressTransactionResults.tsx b/src/address/AddressTransactionResults.tsx index f1a373e..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,10 +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]); - const resolvedAddresses = useResolvedAddresses(provider, addrCollector); - // Calculate Sourcify metadata for all addresses that appear on this page results const addresses = useMemo(() => { const _addresses = [address]; @@ -152,7 +147,6 @@ const AddressTransactionResults: React.FC = ({ => { - 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 01d867c..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, useResolvedAddresses } from "../useResolvedAddresses"; import { ChecksummedAddress, ProcessedTransaction } from "../types"; import { PAGE_SIZE } from "../params"; import { useMultipleETHUSDOracle } from "../usePriceOracle"; @@ -30,8 +29,6 @@ const BlockTransactionResults: React.FC = ({ const { provider } = useContext(RuntimeContext); const selectionCtx = useSelection(); const [feeDisplay, feeDisplayToggler] = useFeeToggler(); - const addrCollector = useMemo(() => pageCollector(page), [page]); - const resolvedAddresses = useResolvedAddresses(provider, addrCollector); const blockTags = useMemo(() => [blockTag], [blockTag]); const priceMap = useMultipleETHUSDOracle(provider, blockTags); @@ -79,7 +76,6 @@ const BlockTransactionResults: React.FC = ({ = ({ address, selectedAddress, dontOverrideColors, - resolvedAddresses, }) => { - const resolvedAddress = resolvedAddresses?.[address]; + const { provider } = useContext(RuntimeContext); + const resolvedAddress = useResolvedAddress(provider, address); const linkable = address !== selectedAddress; if (!resolvedAddress) { diff --git a/src/components/DecoratedAddressLink.tsx b/src/components/DecoratedAddressLink.tsx index 0f13f2c..1b3870a 100644 --- a/src/components/DecoratedAddressLink.tsx +++ b/src/components/DecoratedAddressLink.tsx @@ -9,7 +9,6 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins"; import AddressOrENSName from "./AddressOrENSName"; import SourcifyLogo from "../sourcify/SourcifyLogo"; import { AddressContext, ZERO_ADDRESS } from "../types"; -import { ResolvedAddresses } from "../api/address-resolver"; import { Metadata } from "../sourcify/useSourcify"; type DecoratedAddressLinkProps = { @@ -21,7 +20,6 @@ type DecoratedAddressLinkProps = { selfDestruct?: boolean; txFrom?: boolean; txTo?: boolean; - resolvedAddresses?: ResolvedAddresses | undefined; metadata?: Metadata | null | undefined; }; @@ -34,7 +32,6 @@ const DecoratedAddressLink: React.FC = ({ selfDestruct, txFrom, txTo, - resolvedAddresses, metadata, }) => { const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS; @@ -87,7 +84,6 @@ const DecoratedAddressLink: React.FC = ({ address={address} selectedAddress={selectedAddress} dontOverrideColors={mint || burn} - resolvedAddresses={resolvedAddresses} /> ); diff --git a/src/components/InternalCreate.tsx b/src/components/InternalCreate.tsx index e086e9d..cc13650 100644 --- a/src/components/InternalCreate.tsx +++ b/src/components/InternalCreate.tsx @@ -5,17 +5,12 @@ import TransactionAddress from "./TransactionAddress"; import AddressHighlighter from "./AddressHighlighter"; import DecoratedAddressLink from "./DecoratedAddressLink"; import { InternalOperation } from "../types"; -import { ResolvedAddresses } from "../api/address-resolver"; type InternalCreateProps = { internalOp: InternalOperation; - resolvedAddresses: ResolvedAddresses | undefined; }; -const InternalCreate: React.FC = ({ - internalOp, - resolvedAddresses, -}) => ( +const InternalCreate: React.FC = ({ internalOp }) => (
CREATE @@ -23,20 +18,11 @@ const InternalCreate: React.FC = ({ Contract
- +
- (Creator:{" "} - - ) + (Creator: )
); diff --git a/src/components/InternalSelfDestruct.tsx b/src/components/InternalSelfDestruct.tsx index 794b987..4df2119 100644 --- a/src/components/InternalSelfDestruct.tsx +++ b/src/components/InternalSelfDestruct.tsx @@ -5,19 +5,16 @@ import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight"; import AddressHighlighter from "./AddressHighlighter"; import DecoratedAddressLink from "./DecoratedAddressLink"; import { TransactionData, InternalOperation } from "../types"; -import { ResolvedAddresses } from "../api/address-resolver"; import TransactionAddress from "./TransactionAddress"; type InternalSelfDestructProps = { txData: TransactionData; internalOp: InternalOperation; - resolvedAddresses: ResolvedAddresses | undefined; }; const InternalSelfDestruct: React.FC = ({ txData, internalOp, - resolvedAddresses, }) => { const toMiner = txData.confirmedData?.miner !== undefined && @@ -32,21 +29,12 @@ const InternalSelfDestruct: React.FC = ({ Contract
- +
{internalOp.value.isZero() && (
- (To:{" "} - - ) + (To: )
)} @@ -64,11 +52,7 @@ const InternalSelfDestruct: React.FC = ({ toMiner ? "rounded px-2 py-1 bg-yellow-100" : "" }`} > - + diff --git a/src/components/InternalTransactionOperation.tsx b/src/components/InternalTransactionOperation.tsx index f167eb5..5870336 100644 --- a/src/components/InternalTransactionOperation.tsx +++ b/src/components/InternalTransactionOperation.tsx @@ -3,37 +3,24 @@ import InternalTransfer from "./InternalTransfer"; import InternalSelfDestruct from "./InternalSelfDestruct"; import InternalCreate from "./InternalCreate"; import { TransactionData, InternalOperation, OperationType } from "../types"; -import { ResolvedAddresses } from "../api/address-resolver"; type InternalTransactionOperationProps = { txData: TransactionData; internalOp: InternalOperation; - resolvedAddresses: ResolvedAddresses | undefined; }; const InternalTransactionOperation: React.FC = - ({ txData, internalOp, resolvedAddresses }) => ( + ({ txData, internalOp }) => ( <> {internalOp.type === OperationType.TRANSFER && ( - + )} {internalOp.type === OperationType.SELF_DESTRUCT && ( - + )} {(internalOp.type === OperationType.CREATE || internalOp.type === OperationType.CREATE2) && ( - + )} ); diff --git a/src/components/InternalTransfer.tsx b/src/components/InternalTransfer.tsx index bf46778..0600e95 100644 --- a/src/components/InternalTransfer.tsx +++ b/src/components/InternalTransfer.tsx @@ -5,18 +5,15 @@ import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight"; import AddressHighlighter from "./AddressHighlighter"; import DecoratedAddressLink from "./DecoratedAddressLink"; import { TransactionData, InternalOperation } from "../types"; -import { ResolvedAddresses } from "../api/address-resolver"; type InternalTransferProps = { txData: TransactionData; internalOp: InternalOperation; - resolvedAddresses: ResolvedAddresses | undefined; }; const InternalTransfer: React.FC = ({ txData, internalOp, - resolvedAddresses, }) => { const fromMiner = txData.confirmedData?.miner !== undefined && @@ -44,7 +41,6 @@ const InternalTransfer: React.FC = ({ miner={fromMiner} txFrom={internalOp.from === txData.from} txTo={internalOp.from === txData.to} - resolvedAddresses={resolvedAddresses} /> @@ -62,7 +58,6 @@ const InternalTransfer: React.FC = ({ miner={toMiner} txFrom={internalOp.to === txData.from} txTo={internalOp.to === txData.to} - resolvedAddresses={resolvedAddresses} /> diff --git a/src/components/TransactionAddress.tsx b/src/components/TransactionAddress.tsx index cb1edc9..a313b24 100644 --- a/src/components/TransactionAddress.tsx +++ b/src/components/TransactionAddress.tsx @@ -1,7 +1,6 @@ import React from "react"; import AddressHighlighter from "./AddressHighlighter"; import DecoratedAddressLink from "./DecoratedAddressLink"; -import { ResolvedAddresses } from "../api/address-resolver"; import { useSelectedTransaction } from "../useSelectedTransaction"; import { AddressContext } from "../types"; import { Metadata } from "../sourcify/useSourcify"; @@ -9,14 +8,12 @@ import { Metadata } from "../sourcify/useSourcify"; type TransactionAddressProps = { address: string; addressCtx?: AddressContext | undefined; - resolvedAddresses: ResolvedAddresses | undefined; metadata?: Metadata | null | undefined; }; const TransactionAddress: React.FC = ({ address, addressCtx, - resolvedAddresses, metadata, }) => { const txData = useSelectedTransaction(); @@ -32,7 +29,6 @@ const TransactionAddress: React.FC = ({ txFrom={address === txData?.from} txTo={address === txData?.to || creation} creation={creation} - resolvedAddresses={resolvedAddresses} metadata={metadata} /> diff --git a/src/search/TransactionItem.tsx b/src/search/TransactionItem.tsx index b6cfe1e..daa0088 100644 --- a/src/search/TransactionItem.tsx +++ b/src/search/TransactionItem.tsx @@ -18,12 +18,10 @@ import { ChecksummedAddress, ProcessedTransaction } from "../types"; import { FeeDisplay } from "./useFeeToggler"; import { formatValue } from "../components/formatter"; import ETH2USDValue from "../components/ETH2USDValue"; -import { ResolvedAddresses } from "../api/address-resolver"; import { Metadata } from "../sourcify/useSourcify"; type TransactionItemProps = { tx: ProcessedTransaction; - resolvedAddresses?: ResolvedAddresses; selectedAddress?: string; feeDisplay: FeeDisplay; priceMap: Record; @@ -32,7 +30,6 @@ type TransactionItemProps = { const TransactionItem: React.FC = ({ tx, - resolvedAddresses, selectedAddress, feeDisplay, priceMap, @@ -87,7 +84,6 @@ const TransactionItem: React.FC = ({ address={tx.from} selectedAddress={selectedAddress} miner={tx.miner === tx.from} - resolvedAddresses={resolvedAddresses} /> )} @@ -110,7 +106,6 @@ const TransactionItem: React.FC = ({ address={tx.to} selectedAddress={selectedAddress} miner={tx.miner === tx.to} - resolvedAddresses={resolvedAddresses} metadata={metadatas[tx.to]} /> @@ -120,7 +115,6 @@ const TransactionItem: React.FC = ({ address={tx.createdContractAddress!} selectedAddress={selectedAddress} creation - resolvedAddresses={resolvedAddresses} metadata={metadatas[tx.createdContractAddress!]} /> diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index d414d1e..695a686 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -42,7 +42,6 @@ import { useTransactionDescription, } from "../use4Bytes"; import { DevDoc, Metadata, useError, UserDoc } from "../sourcify/useSourcify"; -import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; import { useContractsMetadata } from "../hooks"; import { useTransactionError } from "../useErigonHooks"; @@ -56,7 +55,6 @@ type DetailsProps = { internalOps?: InternalOperation[]; sendsEthToMiner: boolean; ethUSDPrice: BigNumber | undefined; - resolvedAddresses: ResolvedAddresses | undefined; }; const Details: React.FC = ({ @@ -68,7 +66,6 @@ const Details: React.FC = ({ internalOps, sendsEthToMiner, ethUSDPrice, - resolvedAddresses, }) => { const hasEIP1559 = txData.confirmedData?.blockBaseFeePerGas !== undefined && @@ -200,7 +197,6 @@ const Details: React.FC = ({ hasParamNames userMethod={userError} devMethod={devError} - resolvedAddresses={resolvedAddresses} /> )} @@ -252,10 +248,7 @@ const Details: React.FC = ({
- +
@@ -268,7 +261,6 @@ const Details: React.FC = ({
@@ -281,7 +273,6 @@ const Details: React.FC = ({
= ({ key={i} txData={txData} internalOp={op} - resolvedAddresses={resolvedAddresses} /> ))}
@@ -314,7 +304,6 @@ const Details: React.FC = ({ key={i} t={t} tokenMeta={txData.tokenMetas[t.token]} - resolvedAddresses={resolvedAddresses} metadatas={metadatas} /> ))} @@ -438,7 +427,6 @@ const Details: React.FC = ({ data={txData.data} userMethod={userMethod} devMethod={devMethod} - resolvedAddresses={resolvedAddresses} /> diff --git a/src/transaction/LogEntry.tsx b/src/transaction/LogEntry.tsx index 07be33f..90f9bee 100644 --- a/src/transaction/LogEntry.tsx +++ b/src/transaction/LogEntry.tsx @@ -8,23 +8,16 @@ import ModeTab from "../components/ModeTab"; import DecodedParamsTable from "./decoder/DecodedParamsTable"; import DecodedLogSignature from "./decoder/DecodedLogSignature"; import { useTopic0 } from "../useTopic0"; -import { ResolvedAddresses } from "../api/address-resolver"; import { ChecksummedAddress } from "../types"; import { Metadata } from "../sourcify/useSourcify"; type LogEntryProps = { log: Log; logDesc: LogDescription | null | undefined; - resolvedAddresses: ResolvedAddresses | undefined; metadatas: Record; }; -const LogEntry: React.FC = ({ - log, - logDesc, - resolvedAddresses, - metadatas, -}) => { +const LogEntry: React.FC = ({ log, logDesc, metadatas }) => { const rawTopic0 = log.topics[0]; const topic0 = useTopic0(rawTopic0); @@ -65,7 +58,6 @@ const LogEntry: React.FC = ({
@@ -109,7 +101,6 @@ const LogEntry: React.FC = ({ args={resolvedLogDesc.args} paramTypes={resolvedLogDesc.eventFragment.inputs} hasParamNames={resolvedLogDesc === logDesc} - resolvedAddresses={resolvedAddresses} />
diff --git a/src/transaction/Logs.tsx b/src/transaction/Logs.tsx index eba82e1..9b903b7 100644 --- a/src/transaction/Logs.tsx +++ b/src/transaction/Logs.tsx @@ -4,17 +4,15 @@ import ContentFrame from "../ContentFrame"; import LogEntry from "./LogEntry"; import { TransactionData } from "../types"; import { Metadata } from "../sourcify/useSourcify"; -import { ResolvedAddresses } from "../api/address-resolver"; import { RuntimeContext } from "../useRuntime"; import { useContractsMetadata } from "../hooks"; type LogsProps = { txData: TransactionData; metadata: Metadata | null | undefined; - resolvedAddresses: ResolvedAddresses | undefined; }; -const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { +const Logs: React.FC = ({ txData, metadata }) => { const baseMetadatas = useMemo((): Record => { if (!txData.to || metadata === undefined) { return {}; @@ -68,7 +66,6 @@ const Logs: React.FC = ({ txData, metadata, resolvedAddresses }) => { key={i} log={l} logDesc={logDescs?.[i]} - resolvedAddresses={resolvedAddresses} metadatas={metadatas} /> ))} diff --git a/src/transaction/Trace.tsx b/src/transaction/Trace.tsx index 5002391..a04bcdb 100644 --- a/src/transaction/Trace.tsx +++ b/src/transaction/Trace.tsx @@ -1,37 +1,18 @@ -import React, { useContext, useMemo } from "react"; +import React, { useContext } from "react"; import ContentFrame from "../ContentFrame"; import TransactionAddress from "../components/TransactionAddress"; import TraceItem from "./TraceItem"; import { TransactionData } from "../types"; -import { useBatch4Bytes } from "../use4Bytes"; -import { useTraceTransaction, useUniqueSignatures } from "../useErigonHooks"; +import { useTraceTransaction } from "../useErigonHooks"; import { RuntimeContext } from "../useRuntime"; -import { ResolvedAddresses } from "../api/address-resolver"; -import { tracesCollector, useResolvedAddresses } from "../useResolvedAddresses"; type TraceProps = { txData: TransactionData; - resolvedAddresses: ResolvedAddresses | undefined; }; -const Trace: React.FC = ({ txData, resolvedAddresses }) => { +const Trace: React.FC = ({ txData }) => { const { provider } = useContext(RuntimeContext); const traces = useTraceTransaction(provider, txData.transactionHash); - const uniqueSignatures = useUniqueSignatures(traces); - const sigMap = useBatch4Bytes(uniqueSignatures); - - const addrCollector = useMemo(() => tracesCollector(traces), [traces]); - const traceResolvedAddresses = useResolvedAddresses(provider, addrCollector); - const mergedResolvedAddresses = useMemo(() => { - const merge = {}; - if (resolvedAddresses) { - Object.assign(merge, resolvedAddresses); - } - if (traceResolvedAddresses) { - Object.assign(merge, traceResolvedAddresses); - } - return merge; - }, [resolvedAddresses, traceResolvedAddresses]); return ( @@ -39,20 +20,11 @@ const Trace: React.FC = ({ txData, resolvedAddresses }) => { {traces ? ( <>
- +
{traces.map((t, i, a) => ( - + ))}
diff --git a/src/transaction/TraceInput.tsx b/src/transaction/TraceInput.tsx index f7e4713..0524501 100644 --- a/src/transaction/TraceInput.tsx +++ b/src/transaction/TraceInput.tsx @@ -7,26 +7,19 @@ import FunctionSignature from "./FunctionSignature"; import InputDecoder from "./decoder/InputDecoder"; import ExpanderSwitch from "../components/ExpanderSwitch"; import { TraceEntry } from "../useErigonHooks"; -import { ResolvedAddresses } from "../api/address-resolver"; import { extract4Bytes, - FourBytesEntry, + use4Bytes, useTransactionDescription, } from "../use4Bytes"; type TraceInputProps = { t: TraceEntry; - fourBytesMap: Record; - resolvedAddresses: ResolvedAddresses | undefined; }; -const TraceInput: React.FC = ({ - t, - fourBytesMap, - resolvedAddresses, -}) => { +const TraceInput: React.FC = ({ t }) => { const raw4Bytes = extract4Bytes(t.input); - const fourBytes = raw4Bytes !== null ? fourBytesMap[raw4Bytes] : null; + const fourBytes = use4Bytes(raw4Bytes); const sigText = raw4Bytes === null ? "" : fourBytes?.name ?? raw4Bytes; const hasParams = t.input.length > 10; @@ -54,10 +47,7 @@ const TraceInput: React.FC = ({ ) : ( <> - + {t.type !== "CREATE" && t.type !== "CREATE2" && ( <> @@ -93,7 +83,6 @@ const TraceInput: React.FC = ({ data={t.input} userMethod={undefined} devMethod={undefined} - resolvedAddresses={resolvedAddresses} />
)
diff --git a/src/transaction/TraceItem.tsx b/src/transaction/TraceItem.tsx index 60e4d85..d6a4d7d 100644 --- a/src/transaction/TraceItem.tsx +++ b/src/transaction/TraceItem.tsx @@ -3,24 +3,15 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPlusSquare } from "@fortawesome/free-regular-svg-icons/faPlusSquare"; import { faMinusSquare } from "@fortawesome/free-regular-svg-icons/faMinusSquare"; import { Switch } from "@headlessui/react"; -import { FourBytesEntry } from "../use4Bytes"; import { TraceGroup } from "../useErigonHooks"; -import { ResolvedAddresses } from "../api/address-resolver"; import TraceInput from "./TraceInput"; type TraceItemProps = { t: TraceGroup; last: boolean; - fourBytesMap: Record; - resolvedAddresses: ResolvedAddresses | undefined; }; -const TraceItem: React.FC = ({ - t, - last, - fourBytesMap, - resolvedAddresses, -}) => { +const TraceItem: React.FC = ({ t, last }) => { const [expanded, setExpanded] = useState(true); return ( @@ -42,11 +33,7 @@ const TraceItem: React.FC = ({ /> )} - +
{t.children && (
= ({ expanded ? "" : "hidden" }`} > - +
)} @@ -67,26 +50,16 @@ const TraceItem: React.FC = ({ type TraceChildrenProps = { c: TraceGroup[]; - fourBytesMap: Record; - resolvedAddresses: ResolvedAddresses | undefined; }; -const TraceChildren: React.FC = React.memo( - ({ c, fourBytesMap, resolvedAddresses }) => { - return ( - <> - {c.map((tc, i, a) => ( - - ))} - - ); - } -); +const TraceChildren: React.FC = React.memo(({ c }) => { + return ( + <> + {c.map((tc, i, a) => ( + + ))} + + ); +}); export default TraceItem; diff --git a/src/transaction/decoder/AddressDecoder.tsx b/src/transaction/decoder/AddressDecoder.tsx index 49726e6..7c5c3ce 100644 --- a/src/transaction/decoder/AddressDecoder.tsx +++ b/src/transaction/decoder/AddressDecoder.tsx @@ -1,19 +1,14 @@ import React from "react"; import TransactionAddress from "../../components/TransactionAddress"; import Copy from "../../components/Copy"; -import { ResolvedAddresses } from "../../api/address-resolver"; type AddressDecoderProps = { r: string; - resolvedAddresses?: ResolvedAddresses | undefined; }; -const AddressDecoder: React.FC = ({ - r, - resolvedAddresses, -}) => ( +const AddressDecoder: React.FC = ({ r }) => (
- +
); diff --git a/src/transaction/decoder/DecodedParamRow.tsx b/src/transaction/decoder/DecodedParamRow.tsx index 3ad47cc..f30381d 100644 --- a/src/transaction/decoder/DecodedParamRow.tsx +++ b/src/transaction/decoder/DecodedParamRow.tsx @@ -8,7 +8,6 @@ import Uint256Decoder from "./Uint256Decoder"; import AddressDecoder from "./AddressDecoder"; import BooleanDecoder from "./BooleanDecoder"; import BytesDecoder from "./BytesDecoder"; -import { ResolvedAddresses } from "../../api/address-resolver"; import SelectionHighlighter, { valueSelector, } from "../../components/SelectionHighlighter"; @@ -20,7 +19,6 @@ type DecodedParamRowProps = { paramType: ParamType; arrayElem?: number | undefined; help?: string | undefined; - resolvedAddresses: ResolvedAddresses | undefined; }; const DecodedParamRow: React.FC = ({ @@ -30,7 +28,6 @@ const DecodedParamRow: React.FC = ({ paramType, arrayElem, help, - resolvedAddresses, }) => { const [showHelp, setShowHelp] = useState(false); @@ -80,10 +77,7 @@ const DecodedParamRow: React.FC = ({ {paramType.baseType === "uint256" ? ( ) : paramType.baseType === "address" ? ( - + ) : paramType.baseType === "bool" ? ( ) : paramType.baseType === "bytes" ? ( @@ -111,7 +105,6 @@ const DecodedParamRow: React.FC = ({ i={idx} r={e} paramType={paramType.components[idx]} - resolvedAddresses={resolvedAddresses} /> ))} {paramType.baseType === "array" && @@ -122,7 +115,6 @@ const DecodedParamRow: React.FC = ({ r={e} paramType={paramType.arrayChildren} arrayElem={idx} - resolvedAddresses={resolvedAddresses} /> ))} diff --git a/src/transaction/decoder/DecodedParamsTable.tsx b/src/transaction/decoder/DecodedParamsTable.tsx index 78d94e6..40dd473 100644 --- a/src/transaction/decoder/DecodedParamsTable.tsx +++ b/src/transaction/decoder/DecodedParamsTable.tsx @@ -2,7 +2,6 @@ import React from "react"; import { ParamType, Result } from "@ethersproject/abi"; import DecodedParamRow from "./DecodedParamRow"; import { DevMethod, UserMethod } from "../../sourcify/useSourcify"; -import { ResolvedAddresses } from "../../api/address-resolver"; type DecodedParamsTableProps = { args: Result; @@ -10,7 +9,6 @@ type DecodedParamsTableProps = { hasParamNames?: boolean; userMethod?: UserMethod | undefined; devMethod?: DevMethod | undefined; - resolvedAddresses?: ResolvedAddresses | undefined; }; const DecodedParamsTable: React.FC = ({ @@ -18,7 +16,6 @@ const DecodedParamsTable: React.FC = ({ paramTypes, hasParamNames = true, devMethod, - resolvedAddresses, }) => ( @@ -47,7 +44,6 @@ const DecodedParamsTable: React.FC = ({ r={r} paramType={paramTypes[i]} help={devMethod?.params?.[paramTypes[i].name]} - resolvedAddresses={resolvedAddresses} /> ))} diff --git a/src/transaction/decoder/InputDecoder.tsx b/src/transaction/decoder/InputDecoder.tsx index 0bd9835..07d6f80 100644 --- a/src/transaction/decoder/InputDecoder.tsx +++ b/src/transaction/decoder/InputDecoder.tsx @@ -5,7 +5,6 @@ import { Tab } from "@headlessui/react"; import ModeTab from "../../components/ModeTab"; import DecodedParamsTable from "./DecodedParamsTable"; import { DevMethod, UserMethod } from "../../sourcify/useSourcify"; -import { ResolvedAddresses } from "../../api/address-resolver"; type InputDecoderProps = { fourBytes: string; @@ -14,7 +13,6 @@ type InputDecoderProps = { data: string; userMethod: UserMethod | undefined; devMethod: DevMethod | undefined; - resolvedAddresses: ResolvedAddresses | undefined; }; const InputDecoder: React.FC = ({ @@ -24,7 +22,6 @@ const InputDecoder: React.FC = ({ data, userMethod, devMethod, - resolvedAddresses, }) => { const utfInput = useMemo(() => { try { @@ -57,7 +54,6 @@ const InputDecoder: React.FC = ({ hasParamNames={hasParamNames} userMethod={userMethod} devMethod={devMethod} - resolvedAddresses={resolvedAddresses} /> )} diff --git a/src/use4Bytes.ts b/src/use4Bytes.ts index ea4f28c..85f4e98 100644 --- a/src/use4Bytes.ts +++ b/src/use4Bytes.ts @@ -1,11 +1,11 @@ -import { useState, useEffect, useContext, useMemo } from "react"; +import { useContext, useMemo } from "react"; import { Fragment, Interface, TransactionDescription, } from "@ethersproject/abi"; import { BigNumberish } from "@ethersproject/bignumber"; -import useSWR from "swr"; +import useSWRImmutable from "swr/immutable"; import { RuntimeContext } from "./useRuntime"; import { fourBytesURL } from "./url"; @@ -14,8 +14,6 @@ export type FourBytesEntry = { signature: string | undefined; }; -export type FourBytesMap = Record; - /** * Given a hex input data; extract the method selector * @@ -61,38 +59,6 @@ const fetch4Bytes = async ( } }; -// TODO: migrate to swr and merge with use4Bytes -export const useBatch4Bytes = ( - rawFourByteSigs: string[] | undefined -): FourBytesMap => { - const runtime = useContext(RuntimeContext); - const assetsURLPrefix = runtime.config?.assetsURLPrefix; - - const [fourBytesMap, setFourBytesMap] = useState({}); - useEffect(() => { - if (!rawFourByteSigs || assetsURLPrefix === undefined) { - setFourBytesMap({}); - return; - } - - const loadSigs = async () => { - const promises = rawFourByteSigs.map((s) => - fetch4Bytes(assetsURLPrefix, s.slice(2)) - ); - const results = await Promise.all(promises); - - const _fourBytesMap: Record = {}; - for (let i = 0; i < rawFourByteSigs.length; i++) { - _fourBytesMap[rawFourByteSigs[i]] = results[i]; - } - setFourBytesMap(_fourBytesMap); - }; - loadSigs(); - }, [assetsURLPrefix, rawFourByteSigs]); - - return fourBytesMap; -}; - /** * Extract 4bytes DB info * @@ -111,10 +77,6 @@ export const use4Bytes = ( const assetsURLPrefix = config?.assetsURLPrefix; const fourBytesFetcher = (key: string | null) => { - // TODO: throw error? - if (assetsURLPrefix === undefined) { - return undefined; - } if (key === null || key === "0x") { return undefined; } @@ -126,17 +88,14 @@ export const use4Bytes = ( return undefined; } - return fetch4Bytes(assetsURLPrefix, key.slice(2)); + return fetch4Bytes(assetsURLPrefix!, key.slice(2)); }; - const { data, error } = useSWR( - rawFourBytes, + const { data, error } = useSWRImmutable( + assetsURLPrefix !== undefined ? rawFourBytes : null, fourBytesFetcher ); - if (error) { - return undefined; - } - return data; + return error ? undefined : data; }; export const useMethodSelector = (data: string): [boolean, string, string] => { diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 66fe480..e63a718 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -1,4 +1,4 @@ -import { useState, useEffect, useMemo } from "react"; +import { useState, useEffect } from "react"; import { Block, BlockWithTransactions } from "@ethersproject/abstract-provider"; import { JsonRpcProvider } from "@ethersproject/providers"; import { getAddress } from "@ethersproject/address"; @@ -6,7 +6,6 @@ import { Contract } from "@ethersproject/contracts"; import { defaultAbiCoder } from "@ethersproject/abi"; import { BigNumber } from "@ethersproject/bignumber"; import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes"; -import { extract4Bytes } from "./use4Bytes"; import { getInternalOperations } from "./nodeFunctions"; import { TokenMetas, @@ -408,46 +407,6 @@ export const useTraceTransaction = ( return traceGroups; }; -/** - * Flatten a trace tree and extract and dedup 4byte function signatures - */ -export const useUniqueSignatures = (traces: TraceGroup[] | undefined) => { - const uniqueSignatures = useMemo(() => { - if (!traces) { - return undefined; - } - - const sigs = new Set(); - let nextTraces: TraceGroup[] = [...traces]; - while (nextTraces.length > 0) { - const traces = nextTraces; - nextTraces = []; - - for (const t of traces) { - if ( - t.type === "CALL" || - t.type === "DELEGATECALL" || - t.type === "STATICCALL" || - t.type === "CALLCODE" - ) { - const fourBytes = extract4Bytes(t.input); - if (fourBytes) { - sigs.add(fourBytes); - } - } - - if (t.children) { - nextTraces.push(...t.children); - } - } - } - - return [...sigs]; - }, [traces]); - - return uniqueSignatures; -}; - const hasCode = async ( provider: JsonRpcProvider, address: ChecksummedAddress diff --git a/src/useResolvedAddresses.ts b/src/useResolvedAddresses.ts index 9250232..adc3819 100644 --- a/src/useResolvedAddresses.ts +++ b/src/useResolvedAddresses.ts @@ -1,14 +1,11 @@ -import { useState, useEffect, useRef, useContext } from "react"; -import { JsonRpcProvider } from "@ethersproject/providers"; +import { useState, useEffect, useContext } from "react"; +import { BaseProvider } from "@ethersproject/providers"; import { getAddress, isAddress } from "@ethersproject/address"; -import { batchPopulate, ResolvedAddresses } from "./api/address-resolver"; -import { TraceGroup } from "./useErigonHooks"; +import useSWRImmutable from "swr/immutable"; +import { mainResolver } from "./api/address-resolver"; +import { SelectedResolvedName } from "./api/address-resolver/CompositeAddressResolver"; import { RuntimeContext } from "./useRuntime"; -import { - ChecksummedAddress, - ProcessedTransaction, - TransactionData, -} from "./types"; +import { ChecksummedAddress } from "./types"; export const useAddressOrENSFromURL = ( addressOrName: string, @@ -69,118 +66,22 @@ export const useAddressOrENSFromURL = ( return [checksummedAddress, isENS, error]; }; -export type AddressCollector = () => string[]; - -export const pageCollector = - (page: ProcessedTransaction[] | undefined): AddressCollector => - () => { - if (!page) { - return []; +export const useResolvedAddress = ( + provider: BaseProvider | undefined, + address: ChecksummedAddress +): SelectedResolvedName | undefined => { + const fetcher = async ( + key: string + ): Promise | undefined> => { + if (!provider) { + return undefined; } - - 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); + return mainResolver.resolveAddress(provider, address); }; -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; + const { data, error } = useSWRImmutable(address, fetcher); + if (error) { + return undefined; + } + return data; };