mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix #16959 - Don't allow user to see welcome or password creation screen after a keyring has been created (#17024)
This commit is contained in:
parent
64eae7d3f0
commit
7cd2b28cd5
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useMemo, useContext } from 'react';
|
import React, { useState, useMemo, useContext, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import zxcvbn from 'zxcvbn';
|
import zxcvbn from 'zxcvbn';
|
||||||
@ -28,7 +28,7 @@ import {
|
|||||||
} from '../../../components/app/step-progress-bar';
|
} from '../../../components/app/step-progress-bar';
|
||||||
import { PASSWORD_MIN_LENGTH } from '../../../helpers/constants/common';
|
import { PASSWORD_MIN_LENGTH } from '../../../helpers/constants/common';
|
||||||
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
||||||
import { getFirstTimeFlowType } from '../../../selectors';
|
import { getFirstTimeFlowType, getCurrentKeyring } from '../../../selectors';
|
||||||
import { FIRST_TIME_FLOW_TYPES } from '../../../helpers/constants/onboarding';
|
import { FIRST_TIME_FLOW_TYPES } from '../../../helpers/constants/onboarding';
|
||||||
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
||||||
import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics';
|
import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics';
|
||||||
@ -50,6 +50,17 @@ export default function CreatePassword({
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
|
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
|
||||||
const trackEvent = useContext(MetaMetricsContext);
|
const trackEvent = useContext(MetaMetricsContext);
|
||||||
|
const currentKeyring = useSelector(getCurrentKeyring);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentKeyring) {
|
||||||
|
if (firstTimeFlowType === FIRST_TIME_FLOW_TYPES.IMPORT) {
|
||||||
|
history.replace(ONBOARDING_COMPLETION_ROUTE);
|
||||||
|
} else {
|
||||||
|
history.replace(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [currentKeyring, history, firstTimeFlowType]);
|
||||||
|
|
||||||
const isValid = useMemo(() => {
|
const isValid = useMemo(() => {
|
||||||
if (!password || !confirmPassword || password !== confirmPassword) {
|
if (!password || !confirmPassword || password !== confirmPassword) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {
|
import {
|
||||||
TwoStepProgressBar,
|
TwoStepProgressBar,
|
||||||
@ -17,11 +18,19 @@ import { ONBOARDING_CREATE_PASSWORD_ROUTE } from '../../../helpers/constants/rou
|
|||||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||||
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
||||||
import SrpInput from '../../../components/app/srp-input';
|
import SrpInput from '../../../components/app/srp-input';
|
||||||
|
import { getCurrentKeyring } from '../../../selectors';
|
||||||
|
|
||||||
export default function ImportSRP({ submitSecretRecoveryPhrase }) {
|
export default function ImportSRP({ submitSecretRecoveryPhrase }) {
|
||||||
const [secretRecoveryPhrase, setSecretRecoveryPhrase] = useState('');
|
const [secretRecoveryPhrase, setSecretRecoveryPhrase] = useState('');
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
|
const currentKeyring = useSelector(getCurrentKeyring);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentKeyring) {
|
||||||
|
history.replace(ONBOARDING_CREATE_PASSWORD_ROUTE);
|
||||||
|
}
|
||||||
|
}, [currentKeyring, history]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="import-srp" data-testid="import-srp">
|
<div className="import-srp" data-testid="import-srp">
|
||||||
|
@ -34,7 +34,9 @@ jest.mock('../../store/actions', () => ({
|
|||||||
|
|
||||||
describe('Onboarding Flow', () => {
|
describe('Onboarding Flow', () => {
|
||||||
const mockState = {
|
const mockState = {
|
||||||
metamask: {},
|
metamask: {
|
||||||
|
identities: {},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const store = configureMockStore()(mockState);
|
const store = configureMockStore()(mockState);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { Carousel } from 'react-responsive-carousel';
|
import { Carousel } from 'react-responsive-carousel';
|
||||||
import Mascot from '../../../components/ui/mascot';
|
import Mascot from '../../../components/ui/mascot';
|
||||||
@ -13,13 +13,33 @@ import {
|
|||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||||
import { setFirstTimeFlowType } from '../../../store/actions';
|
import { setFirstTimeFlowType } from '../../../store/actions';
|
||||||
import { ONBOARDING_METAMETRICS } from '../../../helpers/constants/routes';
|
import {
|
||||||
|
ONBOARDING_METAMETRICS,
|
||||||
|
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
|
||||||
|
ONBOARDING_COMPLETION_ROUTE,
|
||||||
|
} from '../../../helpers/constants/routes';
|
||||||
|
import { FIRST_TIME_FLOW_TYPES } from '../../../helpers/constants/onboarding';
|
||||||
|
import { getFirstTimeFlowType, getCurrentKeyring } from '../../../selectors';
|
||||||
|
|
||||||
export default function OnboardingWelcome() {
|
export default function OnboardingWelcome() {
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [eventEmitter] = useState(new EventEmitter());
|
const [eventEmitter] = useState(new EventEmitter());
|
||||||
|
const currentKeyring = useSelector(getCurrentKeyring);
|
||||||
|
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
|
||||||
|
|
||||||
|
// Don't allow users to come back to this screen after they
|
||||||
|
// have already imported or created a wallet
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentKeyring) {
|
||||||
|
if (firstTimeFlowType === FIRST_TIME_FLOW_TYPES.IMPORT) {
|
||||||
|
history.replace(ONBOARDING_COMPLETION_ROUTE);
|
||||||
|
} else {
|
||||||
|
history.replace(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [currentKeyring, history, firstTimeFlowType]);
|
||||||
|
|
||||||
const onCreateClick = () => {
|
const onCreateClick = () => {
|
||||||
dispatch(setFirstTimeFlowType('create'));
|
dispatch(setFirstTimeFlowType('create'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user