Add ENS support to search by nonce url
This commit is contained in:
parent
17b6c03a33
commit
aeda92e41c
|
@ -20,7 +20,7 @@ import AddressTransactionResults from "./address/AddressTransactionResults";
|
||||||
import Contracts from "./address/Contracts";
|
import Contracts from "./address/Contracts";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { useAppConfigContext } from "./useAppConfig";
|
import { useAppConfigContext } from "./useAppConfig";
|
||||||
import { useAddressOrENSFromURL } from "./useResolvedAddresses";
|
import { useAddressOrENS } from "./useResolvedAddresses";
|
||||||
import { useMultipleMetadata } from "./sourcify/useSourcify";
|
import { useMultipleMetadata } from "./sourcify/useSourcify";
|
||||||
import { ChecksummedAddress } from "./types";
|
import { ChecksummedAddress } from "./types";
|
||||||
import { useAddressesWithCode } from "./useErigonHooks";
|
import { useAddressesWithCode } from "./useErigonHooks";
|
||||||
|
@ -45,7 +45,7 @@ const Address: React.FC = () => {
|
||||||
},
|
},
|
||||||
[navigate, direction, searchParams]
|
[navigate, direction, searchParams]
|
||||||
);
|
);
|
||||||
const [checksummedAddress, isENS, error] = useAddressOrENSFromURL(
|
const [checksummedAddress, isENS, error] = useAddressOrENS(
|
||||||
addressOrName,
|
addressOrName,
|
||||||
urlFixer
|
urlFixer
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useCallback, useContext } from "react";
|
||||||
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
|
import { ChecksummedAddress } from "./types";
|
||||||
import { transactionURL } from "./url";
|
import { transactionURL } from "./url";
|
||||||
import { useTransactionBySenderAndNonce } from "./useErigonHooks";
|
import { useTransactionBySenderAndNonce } from "./useErigonHooks";
|
||||||
|
import { useAddressOrENS } from "./useResolvedAddresses";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
|
|
||||||
const AddressTransaction: React.FC = () => {
|
const AddressTransaction: React.FC = () => {
|
||||||
|
@ -14,6 +16,19 @@ const AddressTransaction: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [searchParams] = useSearchParams();
|
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");
|
const rawNonce = searchParams.get("nonce");
|
||||||
if (rawNonce === null) {
|
if (rawNonce === null) {
|
||||||
throw new Error("rawNonce couldn't be undefined here");
|
throw new Error("rawNonce couldn't be undefined here");
|
||||||
|
@ -25,7 +40,19 @@ const AddressTransaction: React.FC = () => {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
const txHash = useTransactionBySenderAndNonce(provider, addressOrName, nonce);
|
const txHash = useTransactionBySenderAndNonce(
|
||||||
|
provider,
|
||||||
|
checksummedAddress,
|
||||||
|
nonce
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<span className="text-base">
|
||||||
|
"{addressOrName}" is not an ETH address or ENS name.
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
if (txHash) {
|
if (txHash) {
|
||||||
navigate(transactionURL(txHash));
|
navigate(transactionURL(txHash));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { SelectedResolvedName } from "./api/address-resolver/CompositeAddressRes
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { ChecksummedAddress } from "./types";
|
import { ChecksummedAddress } from "./types";
|
||||||
|
|
||||||
export const useAddressOrENSFromURL = (
|
export const useAddressOrENS = (
|
||||||
addressOrName: string,
|
addressOrName: string,
|
||||||
urlFixer: (address: ChecksummedAddress) => void
|
urlFixer: (address: ChecksummedAddress) => void
|
||||||
): [
|
): [
|
||||||
|
|
Loading…
Reference in New Issue