aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/first-time-flow/first-time-flow-switch/first-time-flow-switch.component.js
blob: 5c229439306141819d2d91d16fed2c3fcbe0d7d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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,
  INITIALIZE_SEED_PHRASE_ROUTE,
  INITIALIZE_METAMETRICS_OPT_IN_ROUTE,
} from '../../../../routes'

export default class FirstTimeFlowSwitch extends PureComponent {
  static propTypes = {
    completedOnboarding: PropTypes.bool,
    isInitialized: PropTypes.bool,
    isUnlocked: PropTypes.bool,
    seedPhrase: PropTypes.string,
    optInMetaMetrics: PropTypes.bool,
  }

  render () {
    const {
      completedOnboarding,
      isInitialized,
      isUnlocked,
      seedPhrase,
      optInMetaMetrics,
    } = this.props

    if (completedOnboarding) {
      return <Redirect to={{ pathname: DEFAULT_ROUTE }} />
    }

    if (isUnlocked && !seedPhrase) {
      return <Redirect to={{ pathname: LOCK_ROUTE }} />
    }

    if (!isInitialized) {
      return <Redirect to={{ pathname: INITIALIZE_WELCOME_ROUTE }} />
    }

    if (!isUnlocked) {
      return <Redirect to={{ pathname: INITIALIZE_UNLOCK_ROUTE }} />
    }

    if (seedPhrase) {
      return <Redirect to={{ pathname: INITIALIZE_SEED_PHRASE_ROUTE }} />
    }

    if (optInMetaMetrics === null) {
      return <Redirect to={{ pathname: INITIALIZE_WELCOME_ROUTE }} />
    }

    return <Redirect to={{ pathname: INITIALIZE_METAMETRICS_OPT_IN_ROUTE }} />
  }
}