diff --git a/src/components/ui/page/Global/index.tsx b/src/components/ui/page/Global/index.tsx index 21e1be827..ae4fef745 100644 --- a/src/components/ui/page/Global/index.tsx +++ b/src/components/ui/page/Global/index.tsx @@ -1,7 +1,6 @@ import * as amplitude from '@amplitude/analytics-browser'; import * as Sentry from '@sentry/react'; import { useEffect, useState } from 'react'; -import { createPublicClient, http, PublicClient } from 'viem'; import { useAccount } from 'wagmi'; import { useAccountFavorites } from '../../../../hooks/DAO/loaders/useFavorites'; import { @@ -36,8 +35,6 @@ const useUpdateFavoritesCache = (onFavoritesUpdated: () => void) => { useEffect(() => { (async () => { - const publicClientsByChain = new Map(); - const favoriteNames = await Promise.all( favoritesList.map(async favorite => { const favoriteChain = wagmiConfig.chains.find( @@ -54,22 +51,9 @@ const useUpdateFavoritesCache = (onFavoritesUpdated: () => void) => { return; } - let favoritePublicClient = publicClientsByChain.get(favoriteChain.id); - - if (!favoritePublicClient) { - favoritePublicClient = createPublicClient({ - chain: favoriteChain, - transport: http(favoriteNetwork.rpcEndpoint), - }); - publicClientsByChain.set(favoriteChain.id, favoritePublicClient); - } - const networkConfig = getNetworkConfig(favoriteChain.id); - return Promise.all([ - favorite, - getSafeName(favoritePublicClient, networkConfig.subgraph, favorite.address), - ]); + return Promise.all([favorite, getSafeName(networkConfig.subgraph, favorite.address)]); }), ); diff --git a/src/hooks/utils/useGetSafeName.ts b/src/hooks/utils/useGetSafeName.ts index 89652c3df..356c0e720 100644 --- a/src/hooks/utils/useGetSafeName.ts +++ b/src/hooks/utils/useGetSafeName.ts @@ -1,25 +1,27 @@ import { useCallback } from 'react'; -import { Address, ChainDoesNotSupportContract, PublicClient } from 'viem'; -import { usePublicClient } from 'wagmi'; +import { Address, http, createPublicClient } from 'viem'; import { DAOQueryDocument } from '../../../.graphclient'; import graphQLClient from '../../graphql'; -import { useNetworkConfigStore } from '../../providers/NetworkConfig/useNetworkConfigStore'; +import { + supportedNetworks, + useNetworkConfigStore, +} from '../../providers/NetworkConfig/useNetworkConfigStore'; import { createAccountSubstring } from './useGetAccountName'; export const getSafeName = async ( - publicClient: PublicClient, subgraph: { space: number; slug: string; version: string }, address: Address, ) => { - const ensName = await publicClient.getEnsName({ address }).catch((error: Error) => { - if (error.name === ChainDoesNotSupportContract.name) { - // Sliently fail, this is fine. - // https://github.com/wevm/viem/discussions/781 - } else { - throw error; - } - }); + const mainnet = supportedNetworks.find(network => network.chain.id === 1); + if (!mainnet) { + throw new Error('Mainnet not found'); + } + const mainnetPublicClient = createPublicClient({ + chain: mainnet.chain, + transport: http(mainnet.rpcEndpoint), + }); + const ensName = await mainnetPublicClient.getEnsName({ address }); if (ensName) { return ensName; } @@ -45,17 +47,13 @@ export const getSafeName = async ( export const useGetSafeName = (chainId?: number) => { const { getConfigByChainId } = useNetworkConfigStore(); - const publicClient = usePublicClient({ chainId }); return { getSafeName: useCallback( (address: Address) => { - if (!publicClient) { - throw new Error('Public client not available'); - } - return getSafeName(publicClient, getConfigByChainId(chainId).subgraph, address); + return getSafeName(getConfigByChainId(chainId).subgraph, address); }, - [publicClient, getConfigByChainId, chainId], + [chainId, getConfigByChainId], ), }; };