1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

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

* fix up ens/hex address validation error handling

* fix lint/tests
This commit is contained in:
Alex Donesky 2021-07-09 09:17:02 -05:00 committed by Dan Miller
parent 54a6588628
commit bff17c6873
7 changed files with 29 additions and 25 deletions

View File

@ -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;

View File

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

View File

@ -1456,7 +1456,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',
);

View File

@ -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 (
} else {
resetEnsResolution();
if (
onValidAddressTyped &&
!isBurnAddress(input) &&
isValidHexAddress(input, { mixedCaseUseChecksum: true })
) {
onValidAddressTyped(input);
} else {
resetEnsResolution();
}
}
return null;
};

View File

@ -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),
};
}

View File

@ -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}

View File

@ -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()),
};
};