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

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

@ -1457,7 +1457,7 @@ describe('Send Slice', () => {
);
expect(actionResult[0].payload).toStrictEqual('');
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(
'send/validateRecipientUserInput',
);

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

@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import {
lookupEnsName,
initializeEnsSlice,
resetResolution,
resetEnsResolution,
} from '../../../../ducks/ens';
import EnsInput from './ens-input.component';
@ -11,7 +11,7 @@ function mapDispatchToProps(dispatch) {
return {
lookupEnsName: debounce((ensName) => dispatch(lookupEnsName(ensName)), 150),
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,
ensResolution: PropTypes.string,
ensError: PropTypes.string,
resetResolution: PropTypes.func,
resetEnsResolution: PropTypes.func,
};
state = {
@ -88,7 +88,7 @@ export default class AddContact extends PureComponent {
this.validate(text);
}}
onReset={() => {
this.props.resetResolution();
this.props.resetEnsResolution();
this.setState({ ethAddress: '', input: '' });
}}
userInput={this.state.input}

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

Loading…
Cancel
Save