From dc587fd8d9eec1053943a5cf9967ee8f7bdccd67 Mon Sep 17 00:00:00 2001 From: Vitor Marthendal Nunes Date: Mon, 15 Apr 2024 14:32:35 -0300 Subject: [PATCH] fix: filter expired ens names (#15) --- apps/website/lib/hooks/web3/use-nfts-for-owner.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/website/lib/hooks/web3/use-nfts-for-owner.ts b/apps/website/lib/hooks/web3/use-nfts-for-owner.ts index 83e1153..4cd5f5e 100644 --- a/apps/website/lib/hooks/web3/use-nfts-for-owner.ts +++ b/apps/website/lib/hooks/web3/use-nfts-for-owner.ts @@ -1,3 +1,4 @@ +import { ENS_CONTRACT_ADDRESS } from "@/data/constants" import { env } from "@/env.mjs" import { useQuery } from "@tanstack/react-query" import { type Address } from "viem" @@ -9,7 +10,7 @@ export interface Nft { imageUrl?: string | null contract: { address: Address - name: string + name: string | null symbol: string totalSupply: number | null tokenType: "ERC721" | "ERC1155" | "UNKNOWN" @@ -116,6 +117,13 @@ export function useNftsForOwner({ owner, contractAddresses, chainId }: Params) { ) const allNfts = responses .flatMap((response) => response) + // Filters out ENS names that doesn't have a `name` property, + // Meaning they have expired + .filter( + ({ name, contract }) => + contract?.address !== ENS_CONTRACT_ADDRESS || + (contract?.address === ENS_CONTRACT_ADDRESS && name !== null) + ) .map((nft) => ({ ...nft, // Adds a convenience property that gets fallback image from the NFT metadata