diff --git a/src/Address.tsx b/src/Address.tsx index eb0213d..950b04e 100644 --- a/src/Address.tsx +++ b/src/Address.tsx @@ -20,7 +20,7 @@ import AddressTransactionResults from "./address/AddressTransactionResults"; import Contracts from "./address/Contracts"; import { RuntimeContext } from "./useRuntime"; import { useAppConfigContext } from "./useAppConfig"; -import { useAddressOrENSFromURL } from "./useResolvedAddresses"; +import { useAddressOrENS } from "./useResolvedAddresses"; import { useMultipleMetadata } from "./sourcify/useSourcify"; import { ChecksummedAddress } from "./types"; import { useAddressesWithCode } from "./useErigonHooks"; @@ -45,7 +45,7 @@ const Address: React.FC = () => { }, [navigate, direction, searchParams] ); - const [checksummedAddress, isENS, error] = useAddressOrENSFromURL( + const [checksummedAddress, isENS, error] = useAddressOrENS( addressOrName, urlFixer ); diff --git a/src/AddressTransaction.tsx b/src/AddressTransaction.tsx index a6b1a52..84d5394 100644 --- a/src/AddressTransaction.tsx +++ b/src/AddressTransaction.tsx @@ -1,8 +1,10 @@ -import React, { useContext } from "react"; +import React, { useCallback, useContext } from "react"; import { useNavigate, useParams, useSearchParams } from "react-router-dom"; import StandardFrame from "./StandardFrame"; +import { ChecksummedAddress } from "./types"; import { transactionURL } from "./url"; import { useTransactionBySenderAndNonce } from "./useErigonHooks"; +import { useAddressOrENS } from "./useResolvedAddresses"; import { RuntimeContext } from "./useRuntime"; const AddressTransaction: React.FC = () => { @@ -14,6 +16,19 @@ const AddressTransaction: React.FC = () => { } const [searchParams] = useSearchParams(); + const urlFixer = useCallback( + (address: ChecksummedAddress) => { + navigate(`/address/${address}/tx?${searchParams.toString()}`, { + replace: true, + }); + }, + [navigate, searchParams] + ); + const [checksummedAddress, isENS, error] = useAddressOrENS( + addressOrName, + urlFixer + ); + const rawNonce = searchParams.get("nonce"); if (rawNonce === null) { throw new Error("rawNonce couldn't be undefined here"); @@ -25,7 +40,19 @@ const AddressTransaction: React.FC = () => { // ignore } - const txHash = useTransactionBySenderAndNonce(provider, addressOrName, nonce); + const txHash = useTransactionBySenderAndNonce( + provider, + checksummedAddress, + nonce + ); + + if (error) { + return ( + + "{addressOrName}" is not an ETH address or ENS name. + + ); + } if (txHash) { navigate(transactionURL(txHash)); } diff --git a/src/useResolvedAddresses.ts b/src/useResolvedAddresses.ts index adc3819..056fa98 100644 --- a/src/useResolvedAddresses.ts +++ b/src/useResolvedAddresses.ts @@ -7,7 +7,7 @@ import { SelectedResolvedName } from "./api/address-resolver/CompositeAddressRes import { RuntimeContext } from "./useRuntime"; import { ChecksummedAddress } from "./types"; -export const useAddressOrENSFromURL = ( +export const useAddressOrENS = ( addressOrName: string, urlFixer: (address: ChecksummedAddress) => void ): [