From ff0fd63ab9633bbffbea4980ffe013a86f7895f1 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Thu, 16 Dec 2021 23:17:13 -0300 Subject: [PATCH] Replace batch calls of address resolution caches and deep props down with in-place useSWR calls --- src/TokenTransferItem.tsx | 11 +------ src/Transaction.tsx | 25 ++-------------- src/address/AddressTransactionResults.tsx | 2 -- src/block/BlockTransactionResults.tsx | 4 +-- src/components/AddressOrENSName.tsx | 14 ++++----- src/components/DecoratedAddressLink.tsx | 4 --- src/components/InternalCreate.tsx | 20 ++----------- src/components/InternalSelfDestruct.tsx | 22 ++------------ .../InternalTransactionOperation.tsx | 21 +++---------- src/components/InternalTransfer.tsx | 5 ---- src/components/TransactionAddress.tsx | 4 --- src/search/TransactionItem.tsx | 6 ---- src/transaction/Details.tsx | 14 +-------- src/transaction/LogEntry.tsx | 11 +------ src/transaction/Logs.tsx | 5 +--- src/transaction/Trace.tsx | 23 ++------------ src/transaction/TraceInput.tsx | 14 ++------- src/transaction/TraceItem.tsx | 25 +++------------- src/transaction/decoder/AddressDecoder.tsx | 9 ++---- src/transaction/decoder/DecodedParamRow.tsx | 10 +------ .../decoder/DecodedParamsTable.tsx | 4 --- src/transaction/decoder/InputDecoder.tsx | 4 --- src/useResolvedAddresses.ts | 30 +++++++++++++++++-- 23 files changed, 64 insertions(+), 223 deletions(-) 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..62a23d6 100644 --- a/src/Transaction.tsx +++ b/src/Transaction.tsx @@ -11,10 +11,7 @@ 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 { transactionDataCollector } from "./useResolvedAddresses"; import { SelectedTransactionContext } from "./useSelectedTransaction"; const Details = React.lazy( @@ -49,7 +46,6 @@ const Transaction: React.FC = () => { () => transactionDataCollector(txData), [txData] ); - const resolvedAddresses = useResolvedAddresses(provider, addrCollector); const internalOps = useInternalOperations(provider, txData); const sendsEthToMiner = useMemo(() => { @@ -119,29 +115,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..0b62115 100644 --- a/src/address/AddressTransactionResults.tsx +++ b/src/address/AddressTransactionResults.tsx @@ -104,7 +104,6 @@ const AddressTransactionResults: React.FC = ({ // 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(() => { @@ -152,7 +151,6 @@ const AddressTransactionResults: React.FC = ({ = ({ 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 +78,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..dcdab74 100644 --- a/src/transaction/Trace.tsx +++ b/src/transaction/Trace.tsx @@ -6,32 +6,19 @@ import { TransactionData } from "../types"; import { useBatch4Bytes } from "../use4Bytes"; import { useTraceTransaction, useUniqueSignatures } from "../useErigonHooks"; import { RuntimeContext } from "../useRuntime"; -import { ResolvedAddresses } from "../api/address-resolver"; -import { tracesCollector, useResolvedAddresses } from "../useResolvedAddresses"; +import { tracesCollector } 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,10 +26,7 @@ const Trace: React.FC = ({ txData, resolvedAddresses }) => { {traces ? ( <>
- +
{traces.map((t, i, a) => ( @@ -51,7 +35,6 @@ const Trace: React.FC = ({ txData, resolvedAddresses }) => { t={t} last={i === a.length - 1} fourBytesMap={sigMap} - resolvedAddresses={mergedResolvedAddresses} /> ))}
diff --git a/src/transaction/TraceInput.tsx b/src/transaction/TraceInput.tsx index f7e4713..a13234d 100644 --- a/src/transaction/TraceInput.tsx +++ b/src/transaction/TraceInput.tsx @@ -7,7 +7,6 @@ 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, @@ -17,14 +16,9 @@ import { type TraceInputProps = { t: TraceEntry; fourBytesMap: Record; - resolvedAddresses: ResolvedAddresses | undefined; }; -const TraceInput: React.FC = ({ - t, - fourBytesMap, - resolvedAddresses, -}) => { +const TraceInput: React.FC = ({ t, fourBytesMap }) => { const raw4Bytes = extract4Bytes(t.input); const fourBytes = raw4Bytes !== null ? fourBytesMap[raw4Bytes] : null; const sigText = @@ -54,10 +48,7 @@ const TraceInput: React.FC = ({ ) : ( <> - + {t.type !== "CREATE" && t.type !== "CREATE2" && ( <> @@ -93,7 +84,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..9b91d0e 100644 --- a/src/transaction/TraceItem.tsx +++ b/src/transaction/TraceItem.tsx @@ -5,22 +5,15 @@ 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, fourBytesMap }) => { const [expanded, setExpanded] = useState(true); return ( @@ -42,11 +35,7 @@ const TraceItem: React.FC = ({ /> )} - +
{t.children && (
= ({ expanded ? "" : "hidden" }`} > - +
)} @@ -68,11 +53,10 @@ const TraceItem: React.FC = ({ type TraceChildrenProps = { c: TraceGroup[]; fourBytesMap: Record; - resolvedAddresses: ResolvedAddresses | undefined; }; const TraceChildren: React.FC = React.memo( - ({ c, fourBytesMap, resolvedAddresses }) => { + ({ c, fourBytesMap }) => { return ( <> {c.map((tc, i, a) => ( @@ -81,7 +65,6 @@ const TraceChildren: React.FC = React.memo( t={tc} last={i === a.length - 1} fourBytesMap={fourBytesMap} - resolvedAddresses={resolvedAddresses} /> ))} 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/useResolvedAddresses.ts b/src/useResolvedAddresses.ts index 9250232..d7c3cb9 100644 --- a/src/useResolvedAddresses.ts +++ b/src/useResolvedAddresses.ts @@ -1,7 +1,13 @@ import { useState, useEffect, useRef, useContext } from "react"; -import { JsonRpcProvider } from "@ethersproject/providers"; +import { BaseProvider, JsonRpcProvider } from "@ethersproject/providers"; import { getAddress, isAddress } from "@ethersproject/address"; -import { batchPopulate, ResolvedAddresses } from "./api/address-resolver"; +import useSWR from "swr"; +import { + batchPopulate, + mainResolver, + ResolvedAddresses, +} from "./api/address-resolver"; +import { SelectedResolvedName } from "./api/address-resolver/CompositeAddressResolver"; import { TraceGroup } from "./useErigonHooks"; import { RuntimeContext } from "./useRuntime"; import { @@ -184,3 +190,23 @@ export const useResolvedAddresses = ( return names; }; + +export const useResolvedAddress = ( + provider: BaseProvider | undefined, + address: ChecksummedAddress +): SelectedResolvedName | undefined => { + const fetcher = async ( + key: string + ): Promise | undefined> => { + if (!provider) { + return undefined; + } + return mainResolver.resolveAddress(provider, address); + }; + + const { data, error } = useSWR(address, fetcher); + if (error) { + return undefined; + } + return data; +};