fix up ens/hex address validation error handling (#11477)

* fix up ens/hex address validation error handling

* fix lint/tests
feature/default_network_editable
Alex Donesky 3 years ago committed by GitHub
parent 68dfc98f40
commit 2cb807dc20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      ui/ducks/ens.js
  2. 4
      ui/ducks/send/send.js
  3. 2
      ui/ducks/send/send.test.js
  4. 15
      ui/pages/send/send-content/add-recipient/ens-input.component.js
  5. 4
      ui/pages/send/send-content/add-recipient/ens-input.container.js
  6. 4
      ui/pages/settings/contact-list-tab/add-contact/add-contact.component.js
  7. 4
      ui/pages/settings/contact-list-tab/add-contact/add-contact.container.js

@ -92,18 +92,20 @@ const slice = createSlice({
}, },
disableEnsLookup: (state) => { disableEnsLookup: (state) => {
state.stage = 'NO_NETWORK_SUPPORT'; state.stage = 'NO_NETWORK_SUPPORT';
state.error = ENS_NOT_SUPPORTED_ON_NETWORK; state.error = null;
state.warning = null; state.warning = null;
state.resolution = null; state.resolution = null;
state.network = null; state.network = null;
}, },
resetResolution: (state) => { ensNotSupported: (state) => {
state.resolution = null; state.resolution = null;
state.warning = null; state.warning = null;
state.error = state.error = ENS_NOT_SUPPORTED_ON_NETWORK;
state.stage === 'NO_NETWORK_SUPPORT' },
? ENS_NOT_SUPPORTED_ON_NETWORK resetEnsResolution: (state) => {
: null; state.resolution = null;
state.warning = null;
state.error = null;
}, },
}, },
extraReducers: (builder) => { extraReducers: (builder) => {
@ -123,9 +125,10 @@ const {
disableEnsLookup, disableEnsLookup,
ensLookup, ensLookup,
enableEnsLookup, enableEnsLookup,
resetResolution, ensNotSupported,
resetEnsResolution,
} = actions; } = actions;
export { resetResolution }; export { resetEnsResolution };
export function initializeEnsSlice() { export function initializeEnsSlice() {
return (dispatch, getState) => { return (dispatch, getState) => {
@ -159,7 +162,7 @@ export function lookupEnsName(ensName) {
) && ) &&
!isHexString(trimmedEnsName) !isHexString(trimmedEnsName)
) { ) {
await dispatch(resetResolution()); await dispatch(ensNotSupported());
} else { } else {
log.info(`ENS attempting to resolve name: ${trimmedEnsName}`); log.info(`ENS attempting to resolve name: ${trimmedEnsName}`);
let address; let address;

@ -78,7 +78,7 @@ import {
isValidDomainName, isValidDomainName,
} from '../../helpers/utils/util'; } from '../../helpers/utils/util';
import { getTokens, getUnapprovedTxs } from '../metamask/metamask'; import { getTokens, getUnapprovedTxs } from '../metamask/metamask';
import { resetResolution } from '../ens'; import { resetEnsResolution } from '../ens';
import { import {
isBurnAddress, isBurnAddress,
isValidHexAddress, isValidHexAddress,
@ -1284,7 +1284,7 @@ export function resetRecipientInput() {
return async (dispatch) => { return async (dispatch) => {
await dispatch(updateRecipientUserInput('')); await dispatch(updateRecipientUserInput(''));
await dispatch(updateRecipient({ address: '', nickname: '' })); await dispatch(updateRecipient({ address: '', nickname: '' }));
await dispatch(resetResolution()); await dispatch(resetEnsResolution());
await dispatch(validateRecipientUserInput()); await dispatch(validateRecipientUserInput());
}; };
} }

@ -1457,7 +1457,7 @@ describe('Send Slice', () => {
); );
expect(actionResult[0].payload).toStrictEqual(''); expect(actionResult[0].payload).toStrictEqual('');
expect(actionResult[1].type).toStrictEqual('send/updateRecipient'); expect(actionResult[1].type).toStrictEqual('send/updateRecipient');
expect(actionResult[2].type).toStrictEqual('ENS/resetResolution'); expect(actionResult[2].type).toStrictEqual('ENS/resetEnsResolution');
expect(actionResult[3].type).toStrictEqual( expect(actionResult[3].type).toStrictEqual(
'send/validateRecipientUserInput', 'send/validateRecipientUserInput',
); );

@ -62,18 +62,19 @@ export default class EnsInput extends Component {
} }
// Empty ENS state if input is empty // Empty ENS state if input is empty
// maybe scan ENS // maybe scan ENS
if (isValidDomainName(input)) { if (isValidDomainName(input)) {
lookupEnsName(input); lookupEnsName(input);
} else if (
onValidAddressTyped &&
!isBurnAddress(input) &&
isValidHexAddress(input, { mixedCaseUseChecksum: true })
) {
onValidAddressTyped(input);
} else { } else {
resetEnsResolution(); resetEnsResolution();
if (
onValidAddressTyped &&
!isBurnAddress(input) &&
isValidHexAddress(input, { mixedCaseUseChecksum: true })
) {
onValidAddressTyped(input);
}
} }
return null; return null;
}; };

@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { import {
lookupEnsName, lookupEnsName,
initializeEnsSlice, initializeEnsSlice,
resetResolution, resetEnsResolution,
} from '../../../../ducks/ens'; } from '../../../../ducks/ens';
import EnsInput from './ens-input.component'; import EnsInput from './ens-input.component';
@ -11,7 +11,7 @@ function mapDispatchToProps(dispatch) {
return { return {
lookupEnsName: debounce((ensName) => dispatch(lookupEnsName(ensName)), 150), lookupEnsName: debounce((ensName) => dispatch(lookupEnsName(ensName)), 150),
initializeEnsSlice: () => dispatch(initializeEnsSlice()), initializeEnsSlice: () => dispatch(initializeEnsSlice()),
resetEnsResolution: debounce(() => dispatch(resetResolution()), 300), resetEnsResolution: debounce(() => dispatch(resetEnsResolution()), 300),
}; };
} }

@ -27,7 +27,7 @@ export default class AddContact extends PureComponent {
qrCodeDetected: PropTypes.func, qrCodeDetected: PropTypes.func,
ensResolution: PropTypes.string, ensResolution: PropTypes.string,
ensError: PropTypes.string, ensError: PropTypes.string,
resetResolution: PropTypes.func, resetEnsResolution: PropTypes.func,
}; };
state = { state = {
@ -88,7 +88,7 @@ export default class AddContact extends PureComponent {
this.validate(text); this.validate(text);
}} }}
onReset={() => { onReset={() => {
this.props.resetResolution(); this.props.resetEnsResolution();
this.setState({ ethAddress: '', input: '' }); this.setState({ ethAddress: '', input: '' });
}} }}
userInput={this.state.input} userInput={this.state.input}

@ -10,7 +10,7 @@ import { getQrCodeData } from '../../../../ducks/app/app';
import { import {
getEnsError, getEnsError,
getEnsResolution, getEnsResolution,
resetResolution, resetEnsResolution,
} from '../../../../ducks/ens'; } from '../../../../ducks/ens';
import AddContact from './add-contact.component'; import AddContact from './add-contact.component';
@ -28,7 +28,7 @@ const mapDispatchToProps = (dispatch) => {
dispatch(addToAddressBook(recipient, nickname)), dispatch(addToAddressBook(recipient, nickname)),
scanQrCode: () => dispatch(showQrScanner()), scanQrCode: () => dispatch(showQrScanner()),
qrCodeDetected: (data) => dispatch(qrCodeDetected(data)), qrCodeDetected: (data) => dispatch(qrCodeDetected(data)),
resetResolution: () => dispatch(resetResolution()), resetEnsResolution: () => dispatch(resetEnsResolution()),
}; };
}; };

Loading…
Cancel
Save