Disable search by ENS name if network does not support it

This commit is contained in:
Willian Mitsuda 2022-02-18 03:46:37 -03:00
parent 33839eb5ef
commit 488f267d48
3 changed files with 27 additions and 15 deletions

View File

@ -100,7 +100,10 @@ const Address: React.FC = () => {
return (
<StandardFrame>
{error ? (
<AddressOrENSNameNotFound addressOrENSName={addressOrName} />
<AddressOrENSNameNotFound
addressOrENSName={addressOrName}
supportsENS={provider?.network.ensAddress !== undefined}
/>
) : (
checksummedAddress && (
<>

View File

@ -4,16 +4,19 @@ import ContentFrame from "../ContentFrame";
type AddressOrENSNameNotFoundProps = {
addressOrENSName: string;
supportsENS: boolean;
};
const AddressOrENSNameNotFound: React.FC<AddressOrENSNameNotFoundProps> = ({
addressOrENSName,
supportsENS,
}) => (
<>
<StandardSubtitle>Transaction Details</StandardSubtitle>
<ContentFrame>
<div className="py-4 text-sm">
"{addressOrENSName}" is not an ETH address or ENS name.
"{addressOrENSName}" is not an ETH address
{supportsENS && " or ENS name"}.
</div>
</ContentFrame>
</>

View File

@ -48,6 +48,7 @@ export const useAddressOrENS = (
if (!provider) {
return;
}
if (provider.network.ensAddress) {
const resolveName = async () => {
const resolvedAddress = await provider.resolveName(addressOrName);
if (resolvedAddress !== null) {
@ -61,6 +62,11 @@ export const useAddressOrENS = (
}
};
resolveName();
} else {
setENS(false);
setError(true);
setChecksummedAddress(undefined);
}
}, [provider, addressOrName, urlFixer]);
return [checksummedAddress, isENS, error];