2019-01-23 16:25:34 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Redirect } from 'react-router-dom'
|
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
LOCK_ROUTE,
|
|
|
|
INITIALIZE_WELCOME_ROUTE,
|
|
|
|
INITIALIZE_UNLOCK_ROUTE,
|
2019-03-05 16:45:01 +01:00
|
|
|
INITIALIZE_METAMETRICS_OPT_IN_ROUTE,
|
2019-03-22 00:03:30 +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,
|
|
|
|
isUnlocked: PropTypes.bool,
|
2019-03-05 16:45:01 +01:00
|
|
|
optInMetaMetrics: PropTypes.bool,
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
completedOnboarding,
|
|
|
|
isInitialized,
|
|
|
|
isUnlocked,
|
2019-03-05 16:45:01 +01:00
|
|
|
optInMetaMetrics,
|
2019-01-23 16:25:34 +01:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (completedOnboarding) {
|
|
|
|
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:59:40 +02:00
|
|
|
if (isUnlocked) {
|
2019-01-23 16:25:34 +01:00
|
|
|
return <Redirect to={{ pathname: LOCK_ROUTE }} />
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isInitialized) {
|
|
|
|
return <Redirect to={{ pathname: INITIALIZE_WELCOME_ROUTE }} />
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isUnlocked) {
|
|
|
|
return <Redirect to={{ pathname: INITIALIZE_UNLOCK_ROUTE }} />
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:01 +01:00
|
|
|
if (optInMetaMetrics === null) {
|
|
|
|
return <Redirect to={{ pathname: INITIALIZE_WELCOME_ROUTE }} />
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Redirect to={{ pathname: INITIALIZE_METAMETRICS_OPT_IN_ROUTE }} />
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|