Skip to content

Commit

Permalink
Refactor: remove custom ENS resolver for Sepolia (#3204)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Feb 7, 2024
1 parent 7a0e42f commit 074146d
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/components/common/AddressInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const AddressInput = ({
className={inputCss.input}
autoComplete="off"
autoFocus={props.focused}
label={<>{error?.message || props.label}</>}
label={<>{error?.message || props.label || `Recipient address${isDomainLookupEnabled ? ' or ENS' : ''}`}</>}
error={!!error}
fullWidth
spellCheck={false}
Expand Down
2 changes: 1 addition & 1 deletion src/components/tx-flow/flows/NftTransfer/SendNftBatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const SendNftBatch = ({ params, onSubmit }: SendNftBatchProps) => {
<FormProvider {...formMethods}>
<form onSubmit={handleSubmit(onFormSubmit)}>
<FormControl fullWidth sx={{ mb: 3, mt: 1 }}>
<AddressBookInput name={Field.recipient} label="Recipient address or ENS" canAdd={isAddressValid} />
<AddressBookInput name={Field.recipient} canAdd={isAddressValid} />
</FormControl>

<Typography data-testid="selected-nfts" variant="body2" color="text.secondary" mb={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ export const CreateTokenTransfer = ({
<FormProvider {...formMethods}>
<form onSubmit={handleSubmit(onSubmit)} className={commonCss.form}>
<FormControl fullWidth sx={{ mt: 1 }}>
<AddressBookInput
name={TokenTransferFields.recipient}
label="Recipient address or ENS"
canAdd={isAddressValid}
/>
<AddressBookInput name={TokenTransferFields.recipient} canAdd={isAddressValid} />
</FormControl>

<TokenAmountInput balances={balancesItems} selectedToken={selectedToken} maxAmount={maxAmount} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('CreateTokenTransfer', () => {
<CreateTokenTransfer params={mockParams} onSubmit={jest.fn()} isSafeTokenPaused={true} />,
)

expect(getAllByText('Recipient address or ENS')[0]).toBeInTheDocument()
expect(getAllByText('Recipient address')[0]).toBeInTheDocument()
})

it('should disable the submit button and display a warning if $SAFE token is selected and not transferable', () => {
Expand Down
6 changes: 0 additions & 6 deletions src/services/ens/config.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/services/ens/custom.ts

This file was deleted.

17 changes: 2 additions & 15 deletions src/services/ens/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logError } from '../exceptions'

// mock rpcProvider
const rpcProvider = {
resolveName: jest.fn(() => Promise.resolve('0x0000000000000000000000000000000000000000')),
resolveName: jest.fn(() => Promise.resolve('0x0000000000000000000000000000000000000001')),
lookupAddress: jest.fn(() => Promise.resolve('safe.eth')),
getNetwork: jest.fn(() => Promise.resolve({ chainId: 1 })),
} as unknown as JsonRpcProvider
Expand All @@ -20,10 +20,6 @@ jest.mock('../exceptions', () => ({
logError: jest.fn(),
}))

jest.mock('./custom', () => ({
customResolveName: jest.fn(() => Promise.resolve('0x0000001111111111111111111111111111111111')),
}))

describe('domains', () => {
describe('isDomain', () => {
it('should check the domain format', async () => {
Expand All @@ -37,23 +33,14 @@ describe('domains', () => {

describe('resolveName', () => {
it('should resolve names', async () => {
expect(await resolveName(rpcProvider, 'test.eth')).toBe('0x0000000000000000000000000000000000000000')
expect(await resolveName(rpcProvider, 'test.eth')).toBe('0x0000000000000000000000000000000000000001')
})

it('should return undefined and log on error', async () => {
const address = await resolveName(badRpcProvider, 'safe.eth')
expect(address).toBe(undefined)
expect(logError).toHaveBeenCalledWith('101: Failed to resolve the address', 'bad resolveName')
})

it('should look up names on Sepolia', async () => {
// mock rpcProvider
const rpcProvider = {
getNetwork: jest.fn(() => Promise.resolve({ chainId: 11155111 })),
} as unknown as JsonRpcProvider

expect(await resolveName(rpcProvider, 'sepolia.eth')).toBe('0x0000001111111111111111111111111111111111')
})
})

describe('lookupAddress', () => {
Expand Down
8 changes: 0 additions & 8 deletions src/services/ens/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { type Provider } from 'ethers'
import { logError } from '../exceptions'
import ErrorCodes from '../exceptions/ErrorCodes'
import { CUSTOM_REGISTRIES } from './config'
import { customResolveName } from './custom'

type EthersError = Error & {
reason?: string
Expand All @@ -22,12 +20,6 @@ export const resolveName = async (rpcProvider: Provider, name: string): Promise<
} catch {}

try {
// Try custom resolvers first
if (chainId && CUSTOM_REGISTRIES[chainId]) {
return await customResolveName(CUSTOM_REGISTRIES[chainId], rpcProvider, name)
}

// The default ENS resolver
return (await rpcProvider.resolveName(name)) || undefined
} catch (e) {
const err = e as EthersError
Expand Down

0 comments on commit 074146d

Please sign in to comment.