aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/select-app.js
blob: ffa31b767564d6d8e4a6891d63fafd87f8cdc458 (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
const inherits = require('util').inherits
const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const App = require('./app')
const OldApp = require('../../old-ui/app/app')
const { autoAddToBetaUI } = require('./selectors')
const { setFeatureFlag } = require('./actions')

function mapStateToProps (state) {
    return {
        betaUI: state.metamask.featureFlags.betaUI,
        autoAdd: autoAddToBetaUI(state),
        isUnlocked: state.metamask.isUnlocked,
    }
}

function mapDispatchToProps (dispatch) {
  return {
    setFeatureFlagToBeta: () => dispatch(setFeatureFlag('betaUI', true)),
  }
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(SelectedApp)

inherits(SelectedApp, Component)
function SelectedApp () {
    this.state = {
        autoAdd: false,
    }
    Component.call(this)
}

SelectedApp.prototype.componentWillReceiveProps = function (nextProps) {
    const { isUnlocked, setFeatureFlagToBeta } = this.props

    if (!isUnlocked && nextProps.isUnlocked && nextProps.autoAdd) {
        this.setState({ autoAdd: nextProps.autoAdd })
        setFeatureFlagToBeta()
    }
}

SelectedApp.prototype.render = function () {
  const { betaUI } = this.props
  const { autoAdd } = this.state 
  const Selected = betaUI ? App : OldApp
  return h(Selected)
}