diff --git a/components/01-atoms/ConnectWallet.tsx b/components/01-atoms/ConnectWallet.tsx index 77944f21..c58ee6b3 100644 --- a/components/01-atoms/ConnectWallet.tsx +++ b/components/01-atoms/ConnectWallet.tsx @@ -1,4 +1,4 @@ -import { WalletIcon } from "@/components/01-atoms"; +import { LoadingIndicator, WalletIcon } from "@/components/01-atoms"; import { ConnectButton } from "@rainbow-me/rainbowkit"; import { useRouter } from "next/router"; diff --git a/components/01-atoms/ENSAvatar.tsx b/components/01-atoms/ENSAvatar.tsx index bc54eeac..55370cb1 100644 --- a/components/01-atoms/ENSAvatar.tsx +++ b/components/01-atoms/ENSAvatar.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { LoadingIndicator } from "@/components/01-atoms"; import { ENSAvatarQueryStatus, @@ -6,6 +7,7 @@ import { import { EthereumAddress } from "@/lib/shared/types"; import BoringAvatar from "boring-avatars"; import cc from "classcat"; +import { useEffect, useState } from "react"; export enum ENSAvatarSize { SMALL = "small", @@ -26,10 +28,36 @@ export const ENSAvatar = ({ avatarENSAddress, size = ENSAvatarSize.MEDIUM, }: ENSAvatarProps) => { - const { avatarQueryStatus, avatarSrc } = useEnsData({ + const { avatarQueryStatus, avatarSrc, primaryName } = useEnsData({ ensAddress: avatarENSAddress, }); + const [imageSrc, setImageSrc] = useState(null); + const [failedLoadingImage, setFailedLoadingImage] = useState(false); + useEffect(() => { + if (avatarQueryStatus === ENSAvatarQueryStatus.SUCCESS) { + if (avatarSrc) { + fetch(avatarSrc) + .then((response) => { + if (response.ok) { + setImageSrc(avatarSrc); + setFailedLoadingImage(false); + } else { + setImageSrc(null); + setFailedLoadingImage(true); + } + }) + .catch(() => { + setImageSrc(null); + setFailedLoadingImage(true); + }); + } else { + setImageSrc(null); + setFailedLoadingImage(true); + } + } + }, [avatarQueryStatus]); + return (
{avatarQueryStatus === ENSAvatarQueryStatus.LOADING ? ( @@ -41,12 +69,13 @@ export const ENSAvatar = ({ >
- ) : avatarQueryStatus === ENSAvatarQueryStatus.ERROR ? ( + ) : avatarQueryStatus === ENSAvatarQueryStatus.ERROR || + failedLoadingImage ? (
- ) : /* - Below condition will always be true since we only have 3 possible values - for avatarQueryStatus, being the third one ENSAvatarQueryStatus.SUCCESS: - - When the query is successful, avatarSrc will be defined - */ - avatarSrc ? ( + ) : imageSrc ? ( {`ENS