Skip to content

Commit

Permalink
exclude namewrapper nfts from nft avatar selection
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 22, 2024
1 parent d4a8abf commit b666bd2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/components/@molecules/ProfileEditor/Avatar/AvatarNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import MagnifyingGlassSVG from '@app/assets/MagnifyingGlass.svg'
import { InnerDialog } from '@app/components/@atoms/InnerDialog'
import { ScrollBoxWithSpinner, SpinnerRow } from '@app/components/@molecules/ScrollBoxWithSpinner'
import { useChainName } from '@app/hooks/chain/useChainName'
import { usePublicClient } from '@app/hooks/usePublicClient'
import { getSupportedChainContractAddress } from '@app/utils/getSupportedChainContractAddress'

type OwnedNFT = {
contract: {
Expand Down Expand Up @@ -168,6 +170,8 @@ export const AvatarNFT = ({
const { address: _address } = useAccount()
const address = _address!

const publicClient = usePublicClient()

const {
data: NFTPages,
fetchNextPage,
Expand All @@ -191,7 +195,16 @@ export const AvatarNFT = ({
ownedNfts: response.ownedNfts.filter(
(nft) =>
(nft.media[0].thumbnail || nft.media[0].gateway) &&
nft.contract.address !== '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85',
nft.contract.address !==
getSupportedChainContractAddress({
client: publicClient,
contract: 'ensBaseRegistrarImplementation',
}) &&
nft.contract.address !==
getSupportedChainContractAddress({
client: publicClient,
contract: 'ensNameWrapper',
}),
),
} as NFTResponse
},
Expand Down
2 changes: 2 additions & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ export const localhostWithEns = {
export const mainnetWithEns = addEnsContracts(mainnet)
export const goerliWithEns = addEnsContracts(goerli)
export const sepoliaWithEns = addEnsContracts(sepolia)

export type SupportedChain = typeof mainnetWithEns | typeof goerliWithEns | typeof sepoliaWithEns
4 changes: 3 additions & 1 deletion src/hooks/usePublicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { usePublicClient as usePublicClient_ } from 'wagmi'

import { PublicClientWithChain } from '@app/types'

export const usePublicClient = usePublicClient_ as <TPublicClient extends PublicClientWithChain>(
export const usePublicClient = usePublicClient_ as <
TPublicClient extends PublicClientWithChain = PublicClientWithChain,
>(
args?: Partial<GetPublicClientArgs>,
) => TPublicClient
4 changes: 3 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
} from '@ensdomains/ensjs/utils'
import { Helper, Space } from '@ensdomains/thorin'

import { SupportedChain } from '@app/constants/chains'

export type Profile = Partial<
GetRecordsReturnType &
Pick<NonNullable<GetSubgraphRecordsReturnType>, 'isMigrated' | 'createdAt'> & {
Expand Down Expand Up @@ -161,7 +163,7 @@ export type Prettify<T> = {
[K in keyof T]: T[K]
} & {}

export type PublicClientWithChain = PublicClient<Transport, ChainWithEns>
export type PublicClientWithChain = PublicClient<Transport, SupportedChain>
export type WalletClientWithAccount = WalletClient<Transport, ChainWithEns, Account>

export type QueryConfig<TData, TError, TSelectData = TData> = Pick<
Expand Down
18 changes: 18 additions & 0 deletions src/utils/getSupportedChainContractAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Client, getChainContractAddress, Transport } from 'viem'

import { SupportedChain } from '@app/constants/chains'

export const getSupportedChainContractAddress = <
const TClient extends Client<Transport, SupportedChain>,
TContract extends Extract<keyof TClient['chain']['contracts'], string>,
>({
client,
contract,
}: {
client: TClient
contract: TContract
}) =>
getChainContractAddress({
chain: client.chain,
contract,
})

0 comments on commit b666bd2

Please sign in to comment.