diff --git a/src/components/forms/AddressInput/index.tsx b/src/components/forms/AddressInput/index.tsx index cc54b754..9ffcc47a 100644 --- a/src/components/forms/AddressInput/index.tsx +++ b/src/components/forms/AddressInput/index.tsx @@ -5,8 +5,7 @@ import { OnChange } from 'react-final-form-listeners' import TextField from 'src/components/forms/TextField' import { composeValidators, mustBeEthereumAddress, required } from 'src/components/forms/validator' import { getAddressFromENS } from 'src/logic/wallets/getWeb3' - -const isValidEnsName = (name) => /^([\w-]+\.)+(eth|test|xyz|luxe)$/.test(name) +import { isValidEnsName } from 'src/logic/wallets/ethAddresses' // an idea for second field was taken from here // https://github.com/final-form/react-final-form-listeners/blob/master/src/OnBlur.js diff --git a/src/logic/wallets/ethAddresses.ts b/src/logic/wallets/ethAddresses.ts index e0b0a3cb..b6ad3a75 100644 --- a/src/logic/wallets/ethAddresses.ts +++ b/src/logic/wallets/ethAddresses.ts @@ -43,3 +43,5 @@ export const isUserOwner = (safe, userAccount) => { } export const isUserOwnerOnAnySafe = (safes, userAccount) => safes.some((safe) => isUserOwner(safe, userAccount)) + +export const isValidEnsName = (name) => /^([\w-]+\.)+(eth|test|xyz|luxe)$/.test(name) diff --git a/src/routes/safe/components/Balances/SendModal/screens/AddressBookInput/index.tsx b/src/routes/safe/components/Balances/SendModal/screens/AddressBookInput/index.tsx index 89fcc25e..e3a50f57 100644 --- a/src/routes/safe/components/Balances/SendModal/screens/AddressBookInput/index.tsx +++ b/src/routes/safe/components/Balances/SendModal/screens/AddressBookInput/index.tsx @@ -12,6 +12,7 @@ import Identicon from 'src/components/Identicon' import { mustBeEthereumAddress, mustBeEthereumContractAddress } from 'src/components/forms/validator' import { getAddressBookListSelector } from 'src/logic/addressBook/store/selectors' import { getAddressFromENS } from 'src/logic/wallets/getWeb3' +import { isValidEnsName } from 'src/logic/wallets/ethAddresses' const textFieldLabelStyle = makeStyles(() => ({ root: { @@ -38,8 +39,6 @@ const filterAddressBookWithContractAddresses = async (addressBook) => { return addressBook.filter((adbkEntry, index) => abFlags[index]) } -const isValidEnsName = (name) => /^([\w-]+\.)+(eth|test|xyz|luxe)$/.test(name) - const AddressBookInput = ({ classes, fieldMutator, diff --git a/src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/index.tsx b/src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/index.tsx index eeb1f39b..1d200145 100644 --- a/src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/index.tsx +++ b/src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/index.tsx @@ -18,7 +18,7 @@ import Header from './Header' import MethodsDropdown from './MethodsDropdown' import RenderInputParams from './RenderInputParams' import RenderOutputParams from './RenderOutputParams' -import { abiExtractor, createTxObject, formMutators, handleSubmitError, isReadMethod } from './utils' +import { abiExtractor, createTxObject, formMutators, handleSubmitError, isReadMethod, ensResolver } from './utils' const useStyles = makeStyles(styles) @@ -73,7 +73,7 @@ const ContractInteraction = ({ contractAddress, initialValues, onClose, onNext }
{ + try { + const resolvedAddress = isValidEnsName(contractAddress) && (await getAddressFromENS(contractAddress)) + + if (resolvedAddress) { + return resolvedAddress + } + } catch (e) { + console.error(e.message) + return contractAddress + } + + return contractAddress + }, + }, +}) + export const formMutators = { setMax: (args, state, utils) => { utils.changeValue(state, 'value', () => args[0])