ENS names not working properly (#1372)
* Fix ENS names * Fix types * Add typo to AddressBookInput component * Remove ensToAddress field * Fix error message variable name Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
parent
dc632be4e2
commit
46c59460cd
|
@ -1,5 +1,4 @@
|
||||||
import MuiTextField from '@material-ui/core/TextField'
|
import MuiTextField from '@material-ui/core/TextField'
|
||||||
import { withStyles } from '@material-ui/core/styles'
|
|
||||||
import makeStyles from '@material-ui/core/styles/makeStyles'
|
import makeStyles from '@material-ui/core/styles/makeStyles'
|
||||||
import Autocomplete from '@material-ui/lab/Autocomplete'
|
import Autocomplete from '@material-ui/lab/Autocomplete'
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
|
@ -22,7 +21,7 @@ export interface AddressBookProps {
|
||||||
pristine: boolean
|
pristine: boolean
|
||||||
recipientAddress?: string
|
recipientAddress?: string
|
||||||
setSelectedEntry: (
|
setSelectedEntry: (
|
||||||
entry: { address?: string; name?: string } | React.SetStateAction<{ address?: string; name?: string }> | null,
|
entry: { address?: string; name?: string } | React.SetStateAction<{ address?: string; name? }> | null,
|
||||||
) => void
|
) => void
|
||||||
setIsValidAddress: (valid: boolean) => void
|
setIsValidAddress: (valid: boolean) => void
|
||||||
}
|
}
|
||||||
|
@ -71,7 +70,7 @@ const AddressBookInput = ({
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
setIsValidAddress,
|
setIsValidAddress,
|
||||||
setSelectedEntry,
|
setSelectedEntry,
|
||||||
}: AddressBookProps) => {
|
}: AddressBookProps): React.ReactElement => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const addressBook = useSelector(getAddressBook)
|
const addressBook = useSelector(getAddressBook)
|
||||||
const [isValidForm, setIsValidForm] = useState(true)
|
const [isValidForm, setIsValidForm] = useState(true)
|
||||||
|
@ -84,9 +83,10 @@ const AddressBookInput = ({
|
||||||
|
|
||||||
const onAddressInputChanged = async (value: string): Promise<void> => {
|
const onAddressInputChanged = async (value: string): Promise<void> => {
|
||||||
const normalizedAddress = trimSpaces(value)
|
const normalizedAddress = trimSpaces(value)
|
||||||
|
const isENSDomain = isValidEnsName(normalizedAddress)
|
||||||
setInputAddValue(normalizedAddress)
|
setInputAddValue(normalizedAddress)
|
||||||
let resolvedAddress = normalizedAddress
|
let resolvedAddress = normalizedAddress
|
||||||
let isValidText
|
let addressErrorMessage
|
||||||
if (inputTouched && !normalizedAddress) {
|
if (inputTouched && !normalizedAddress) {
|
||||||
setIsValidForm(false)
|
setIsValidForm(false)
|
||||||
setValidationText('Required')
|
setValidationText('Required')
|
||||||
|
@ -94,13 +94,14 @@ const AddressBookInput = ({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (normalizedAddress) {
|
if (normalizedAddress) {
|
||||||
if (isValidEnsName(normalizedAddress)) {
|
if (isENSDomain) {
|
||||||
resolvedAddress = await getAddressFromENS(normalizedAddress)
|
resolvedAddress = await getAddressFromENS(normalizedAddress)
|
||||||
setInputAddValue(resolvedAddress)
|
setInputAddValue(resolvedAddress)
|
||||||
}
|
}
|
||||||
isValidText = mustBeEthereumAddress(resolvedAddress)
|
|
||||||
if (isCustomTx && isValidText === undefined) {
|
addressErrorMessage = mustBeEthereumAddress(resolvedAddress)
|
||||||
isValidText = await mustBeEthereumContractAddress(resolvedAddress)
|
if (isCustomTx && addressErrorMessage === undefined) {
|
||||||
|
addressErrorMessage = await mustBeEthereumContractAddress(resolvedAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// First removes the entries that are not contracts if the operation is custom tx
|
// First removes the entries that are not contracts if the operation is custom tx
|
||||||
|
@ -114,14 +115,17 @@ const AddressBookInput = ({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
setADBKList(filteredADBK)
|
setADBKList(filteredADBK)
|
||||||
if (!isValidText) {
|
if (!addressErrorMessage) {
|
||||||
setSelectedEntry({ address: normalizedAddress })
|
setSelectedEntry({
|
||||||
|
name: normalizedAddress,
|
||||||
|
address: resolvedAddress,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setIsValidForm(isValidText === undefined)
|
setIsValidForm(addressErrorMessage === undefined)
|
||||||
setValidationText(isValidText)
|
setValidationText(addressErrorMessage)
|
||||||
fieldMutator(resolvedAddress)
|
fieldMutator(resolvedAddress)
|
||||||
setIsValidAddress(isValidText === undefined)
|
setIsValidAddress(addressErrorMessage === undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -237,4 +241,4 @@ const AddressBookInput = ({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withStyles(styles as any)(AddressBookInput)
|
export default AddressBookInput
|
||||||
|
|
Loading…
Reference in New Issue