-
Notifications
You must be signed in to change notification settings - Fork 477
Revert "fix: ens resolve" #2894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,15 +15,13 @@ import { ModalType, useModalContext } from 'src/hooks/useModal'; | |||||||||||||||||||||||||||
| import { useWeb3Context } from 'src/libs/hooks/useWeb3Context'; | ||||||||||||||||||||||||||||
| import { useRootStore } from 'src/store/root'; | ||||||||||||||||||||||||||||
| import { AUTH } from 'src/utils/events'; | ||||||||||||||||||||||||||||
| import { getENSClient } from 'src/utils/marketsAndNetworksConfig'; | ||||||||||||||||||||||||||||
| import { getENSProvider } from 'src/utils/marketsAndNetworksConfig'; | ||||||||||||||||||||||||||||
| import { normalize } from 'viem/ens'; | ||||||||||||||||||||||||||||
| import { useAccount, useDisconnect } from 'wagmi'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { BasicModal } from '../primitives/BasicModal'; | ||||||||||||||||||||||||||||
| import { TxModalTitle } from '../transactions/FlowCommons/TxModalTitle'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const viemClient = getENSClient(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export const ReadOnlyModal = () => { | ||||||||||||||||||||||||||||
| const { disconnectAsync } = useDisconnect(); | ||||||||||||||||||||||||||||
| const { isConnected } = useAccount(); | ||||||||||||||||||||||||||||
|
|
@@ -33,6 +31,7 @@ export const ReadOnlyModal = () => { | |||||||||||||||||||||||||||
| const { type, close } = useModalContext(); | ||||||||||||||||||||||||||||
| const { breakpoints } = useTheme(); | ||||||||||||||||||||||||||||
| const sm = useMediaQuery(breakpoints.down('sm')); | ||||||||||||||||||||||||||||
| const mainnetProvider = getENSProvider(); | ||||||||||||||||||||||||||||
| const trackEvent = useRootStore((store) => store.trackEvent); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const handleReadAddress = async (inputMockWalletAddress: string): Promise<void> => { | ||||||||||||||||||||||||||||
|
|
@@ -44,7 +43,7 @@ export const ReadOnlyModal = () => { | |||||||||||||||||||||||||||
| if (inputMockWalletAddress.slice(-4) === '.eth') { | ||||||||||||||||||||||||||||
| const normalizedENS = normalize(inputMockWalletAddress); | ||||||||||||||||||||||||||||
| // Attempt to resolve ENS name and use resolved address if valid | ||||||||||||||||||||||||||||
| const resolvedAddress = await viemClient.getEnsAddress({ name: normalizedENS }); | ||||||||||||||||||||||||||||
| const resolvedAddress = await mainnetProvider.resolveName(normalizedENS); | ||||||||||||||||||||||||||||
| if (resolvedAddress && utils.isAddress(resolvedAddress)) { | ||||||||||||||||||||||||||||
| saveAndClose(resolvedAddress); | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
|
Comment on lines
+46
to
49
|
||||||||||||||||||||||||||||
| const resolvedAddress = await mainnetProvider.resolveName(normalizedENS); | |
| if (resolvedAddress && utils.isAddress(resolvedAddress)) { | |
| saveAndClose(resolvedAddress); | |
| } else { | |
| try { | |
| const resolvedAddress = await mainnetProvider.resolveName(normalizedENS); | |
| if (resolvedAddress && utils.isAddress(resolvedAddress)) { | |
| saveAndClose(resolvedAddress); | |
| } else { | |
| setValidAddressError(true); | |
| } | |
| } catch { | |
| // Treat resolution errors as invalid ENS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| import { ChainId } from '@aave/contract-helpers'; | ||
| import { normalizeBN } from '@aave/math-utils'; | ||
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
| import { Contract } from 'ethers'; | ||
| import { gql } from 'graphql-request'; | ||
| import { governanceV3Config } from 'src/ui-config/governanceConfig'; | ||
| import { getENSClient } from 'src/utils/marketsAndNetworksConfig'; | ||
| import { getProvider } from 'src/utils/marketsAndNetworksConfig'; | ||
| import { subgraphRequest } from 'src/utils/subgraphRequest'; | ||
|
|
||
| import { ENS_REVERSE_REGISTRAR } from './useGovernanceProposals'; | ||
|
|
||
| export type ProposalVote = { | ||
| proposalId: string; | ||
| support: boolean; | ||
|
|
@@ -24,7 +27,20 @@ export interface ProposalVotes { | |
| isFetching: boolean; | ||
| } | ||
|
|
||
| const viemClient = getENSClient(); | ||
| const abi = [ | ||
| { | ||
| inputs: [{ internalType: 'contract ENS', name: '_ens', type: 'address' }], | ||
| stateMutability: 'nonpayable', | ||
| type: 'constructor', | ||
| }, | ||
| { | ||
| inputs: [{ internalType: 'address[]', name: 'addresses', type: 'address[]' }], | ||
| name: 'getNames', | ||
| outputs: [{ internalType: 'string[]', name: 'r', type: 'string[]' }], | ||
| stateMutability: 'view', | ||
| type: 'function', | ||
| }, | ||
| ]; | ||
|
|
||
| const getProposalVotes = gql` | ||
| query getProposalVotes($proposalId: Int!) { | ||
|
|
@@ -55,13 +71,11 @@ const fetchProposalVotes = async ( | |
| })); | ||
| }; | ||
|
|
||
| const fetchProposalVotesEnsNames = async (addresses: string[]): Promise<string[]> => { | ||
| const names = await Promise.all( | ||
| addresses.map((addr) => | ||
| viemClient.getEnsName({ address: addr as `0x${string}` }).catch(() => null) | ||
| ) | ||
| ); | ||
| return names.map((name) => name ?? ''); | ||
| const fetchProposalVotesEnsNames = async (addresses: string[]) => { | ||
| const provider = getProvider(governanceV3Config.coreChainId); | ||
| const contract = new Contract(ENS_REVERSE_REGISTRAR, abi); | ||
| const connectedContract = contract.connect(provider); | ||
| return connectedContract.getNames(addresses) as Promise<string[]>; | ||
|
Comment on lines
+74
to
+78
|
||
| }; | ||
|
|
||
| export const useProposalVotesQuery = ({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { blo } from 'blo'; | ||
| import { utils } from 'ethers'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { getENSClient } from 'src/utils/marketsAndNetworksConfig'; | ||
| import { getENSProvider } from 'src/utils/marketsAndNetworksConfig'; | ||
|
|
||
| const viemClient = getENSClient(); | ||
| const mainnetProvider = getENSProvider(); | ||
|
|
||
| interface EnsResponse { | ||
| name?: string; | ||
|
|
@@ -12,20 +13,26 @@ interface EnsResponse { | |
| const useGetEns = (address: string): EnsResponse => { | ||
| const [ensName, setEnsName] = useState<string | undefined>(undefined); | ||
| const [ensAvatar, setEnsAvatar] = useState<string | undefined>(undefined); | ||
|
|
||
| const getName = async (address: string) => { | ||
| try { | ||
| const name = await viemClient.getEnsName({ address: address as `0x${string}` }); | ||
| setEnsName(name ?? undefined); | ||
| const name = await mainnetProvider.lookupAddress(address); | ||
| setEnsName(name ? name : undefined); | ||
| } catch (error) { | ||
| console.error('ENS name lookup error', error); | ||
| } | ||
| }; | ||
|
|
||
| const getAvatar = async (name: string) => { | ||
| try { | ||
| const avatar = await viemClient.getEnsAvatar({ name }); | ||
| setEnsAvatar(avatar ?? blo(address as `0x${string}`)); | ||
| const labelHash = utils.keccak256(utils.toUtf8Bytes(name?.replace('.eth', ''))); | ||
| const result: { background_image: string } = await ( | ||
| await fetch( | ||
| `https://metadata.ens.domains/mainnet/0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85/${labelHash}/` | ||
| ) | ||
| ).json(); | ||
| setEnsAvatar( | ||
| result && result.background_image ? result.background_image : blo(address as `0x${string}`) | ||
| ); | ||
|
Comment on lines
25
to
+35
|
||
| } catch (error) { | ||
| console.error('ENS avatar lookup error', error); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| import { ChainId, ChainIdToNetwork } from '@aave/contract-helpers'; | ||
| import { StaticJsonRpcProvider } from '@ethersproject/providers'; | ||
| import { ProviderWithSend } from 'src/components/transactions/GovVote/temporary/VotingMachineService'; | ||
| import { createPublicClient, http, PublicClient } from 'viem'; | ||
| import { mainnet } from 'viem/chains'; | ||
|
|
||
| import { | ||
| CustomMarket, | ||
|
|
@@ -190,13 +188,10 @@ export const getProvider = (chainId: ChainId): ProviderWithSend => { | |
| return providers[chainId]; | ||
| }; | ||
|
|
||
| export const getENSClient = (): PublicClient => { | ||
| const config = getNetworkConfig(ChainId.mainnet); | ||
| return createPublicClient({ | ||
| chain: mainnet, | ||
| transport: http(config.publicJsonRPCUrl[0]), | ||
| batch: { multicall: true }, | ||
| }); | ||
| export const getENSProvider = () => { | ||
| const chainId = 1; | ||
| const config = getNetworkConfig(chainId); | ||
| return new StaticJsonRpcProvider(config.publicJsonRPCUrl[0], chainId); | ||
| }; | ||
|
Comment on lines
+191
to
195
|
||
|
|
||
| const ammDisableProposal = 'https://governance-v2.aave.com/governance/proposal/44'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainnetProvideris created inside the component body, so a newStaticJsonRpcProviderinstance is constructed on every render. This can create unnecessary connections and makes caching harder. Prefer a module-level singleton (like other ENS helpers) oruseMemoto construct it once.