2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Redirect } from 'react-router-dom';
|
2019-01-23 16:25:34 +01:00
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
2020-11-09 14:50:24 +01:00
|
|
|
LOCK_ROUTE,
|
2020-11-10 22:27:08 +01:00
|
|
|
INITIALIZE_END_OF_FLOW_ROUTE,
|
2019-01-23 16:25:34 +01:00
|
|
|
INITIALIZE_WELCOME_ROUTE,
|
|
|
|
INITIALIZE_UNLOCK_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../helpers/constants/routes';
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
export default class FirstTimeFlowSwitch extends PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
completedOnboarding: PropTypes.bool,
|
|
|
|
isInitialized: PropTypes.bool,
|
2020-11-09 14:50:24 +01:00
|
|
|
isUnlocked: PropTypes.bool,
|
2020-11-10 22:27:08 +01:00
|
|
|
seedPhraseBackedUp: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2020-11-10 22:27:08 +01:00
|
|
|
const {
|
|
|
|
completedOnboarding,
|
|
|
|
isInitialized,
|
|
|
|
isUnlocked,
|
|
|
|
seedPhraseBackedUp,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
if (completedOnboarding) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-10 22:27:08 +01:00
|
|
|
if (seedPhraseBackedUp !== null) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: INITIALIZE_END_OF_FLOW_ROUTE }} />;
|
2020-11-10 22:27:08 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 14:50:24 +01:00
|
|
|
if (isUnlocked) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: LOCK_ROUTE }} />;
|
2020-11-09 14:50:24 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
if (!isInitialized) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: INITIALIZE_WELCOME_ROUTE }} />;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname: INITIALIZE_UNLOCK_ROUTE }} />;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|