mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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:
parent
54a6588628
commit
bff17c6873
@ -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;
|
||||||
|
@ -75,7 +75,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,
|
||||||
@ -1218,7 +1218,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());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1456,7 +1456,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…
x
Reference in New Issue
Block a user