11import { ChainId } from '@aave/contract-helpers' ;
22import { normalizeBN } from '@aave/math-utils' ;
33import { useInfiniteQuery , useQuery } from '@tanstack/react-query' ;
4- import { constants , Contract } from 'ethers' ;
4+ import { constants } from 'ethers' ;
55import { gql } from 'graphql-request' ;
66import {
77 adaptCacheProposalToDetail ,
@@ -26,7 +26,7 @@ import {
2626import { useRootStore } from 'src/store/root' ;
2727import { governanceV3Config } from 'src/ui-config/governanceConfig' ;
2828import { useSharedDependencies } from 'src/ui-config/SharedDependenciesProvider' ;
29- import { getProvider } from 'src/utils/marketsAndNetworksConfig ' ;
29+ import { getEnsProfilesMap } from 'src/utils/ens ' ;
3030import { subgraphRequest } from 'src/utils/subgraphRequest' ;
3131
3232import { getProposal } from './useProposal' ;
@@ -42,7 +42,6 @@ const USE_GOVERNANCE_CACHE = process.env.NEXT_PUBLIC_USE_GOVERNANCE_CACHE === 't
4242const PAGE_SIZE = 10 ;
4343const VOTES_PAGE_SIZE = 50 ;
4444const SEARCH_RESULTS_LIMIT = 10 ;
45- export const ENS_REVERSE_REGISTRAR = '0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C' ;
4645
4746// ============================================
4847// Subgraph search query
@@ -78,16 +77,6 @@ const getProposalVotesQuery = gql`
7877 }
7978` ;
8079
81- const ensAbi = [
82- {
83- inputs : [ { internalType : 'address[]' , name : 'addresses' , type : 'address[]' } ] ,
84- name : 'getNames' ,
85- outputs : [ { internalType : 'string[]' , name : 'r' , type : 'string[]' } ] ,
86- stateMutability : 'view' ,
87- type : 'function' ,
88- } ,
89- ] ;
90-
9180type SubgraphVote = {
9281 proposalId : string ;
9382 support : boolean ;
@@ -334,18 +323,13 @@ export const useGovernanceVotersSplit = (
334323 const { data : graphVotes , isFetching : graphFetching } = useQuery ( {
335324 queryFn : async ( ) => {
336325 const votes = await fetchSubgraphVotes ( proposalId , votingChainId as ChainId ) ;
337- try {
338- const provider = getProvider ( governanceV3Config . coreChainId ) ;
339- const contract = new Contract ( ENS_REVERSE_REGISTRAR , ensAbi ) ;
340- const connectedContract = contract . connect ( provider ) ;
341- const ensNames : string [ ] = await connectedContract . getNames ( votes . map ( ( v ) => v . voter ) ) ;
342- return votes . map ( ( vote , i ) => ( {
343- ...vote ,
344- ensName : ensNames [ i ] || undefined ,
345- } ) ) ;
346- } catch {
347- return votes ;
348- }
326+ const ensProfiles = await getEnsProfilesMap ( votes . map ( ( vote ) => vote . voter ) ) ;
327+
328+ return votes . map ( ( vote ) => ( {
329+ ...vote ,
330+ ensName : ensProfiles [ vote . voter . toLowerCase ( ) ] ?. name ,
331+ ensAvatar : ensProfiles [ vote . voter . toLowerCase ( ) ] ?. avatar ,
332+ } ) ) ;
349333 } ,
350334 queryKey : [ 'governance-voters-graph' , proposalId ] ,
351335 enabled : ! USE_GOVERNANCE_CACHE && votingChainId !== undefined && ! isNaN ( proposalId ) ,
@@ -362,18 +346,8 @@ export const useGovernanceVotersSplit = (
362346 ]
363347 : [ ] ;
364348
365- const { data : cacheEnsNames } = useQuery ( {
366- queryFn : async ( ) => {
367- const provider = getProvider ( governanceV3Config . coreChainId ) ;
368- const contract = new Contract ( ENS_REVERSE_REGISTRAR , ensAbi ) ;
369- const connectedContract = contract . connect ( provider ) ;
370- const names : string [ ] = await connectedContract . getNames ( cacheVoterAddresses ) ;
371- const map : Record < string , string > = { } ;
372- cacheVoterAddresses . forEach ( ( addr , i ) => {
373- if ( names [ i ] ) map [ addr . toLowerCase ( ) ] = names [ i ] ;
374- } ) ;
375- return map ;
376- } ,
349+ const { data : cacheEnsProfiles } = useQuery ( {
350+ queryFn : ( ) => getEnsProfilesMap ( cacheVoterAddresses ) ,
377351 queryKey : [ 'governance-voters-ens' , proposalId , cacheVoterAddresses ] ,
378352 enabled : USE_GOVERNANCE_CACHE && cacheVoterAddresses . length > 0 ,
379353 refetchOnMount : false ,
@@ -384,7 +358,8 @@ export const useGovernanceVotersSplit = (
384358 if ( USE_GOVERNANCE_CACHE ) {
385359 const withEns = ( vote : VoteDisplay ) : VoteDisplay => ( {
386360 ...vote ,
387- ensName : cacheEnsNames ?. [ vote . voter . toLowerCase ( ) ] ,
361+ ensName : cacheEnsProfiles ?. [ vote . voter . toLowerCase ( ) ] ?. name ,
362+ ensAvatar : cacheEnsProfiles ?. [ vote . voter . toLowerCase ( ) ] ?. avatar ,
388363 } ) ;
389364 const yaeVotes = ( cacheForData ?. pages . flatMap ( ( p ) => p . votes . map ( adaptCacheVote ) ) || [ ] ) . map (
390365 withEns
@@ -411,11 +386,13 @@ export const useGovernanceVotersSplit = (
411386 support : boolean ;
412387 votingPower : string ;
413388 ensName ?: string ;
389+ ensAvatar ?: string ;
414390 } ) : VoteDisplay => ( {
415391 voter : v . voter ,
416392 support : v . support ,
417393 votingPower : v . votingPower ,
418394 ensName : v . ensName ,
395+ ensAvatar : v . ensAvatar ,
419396 } ) ;
420397
421398 const yaeVotes =
0 commit comments