2017-11-14 17:04:55 +01:00
|
|
|
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')
|
2017-12-07 01:19:45 +01:00
|
|
|
const { autoAddToBetaUI } = require('./selectors')
|
|
|
|
const { setFeatureFlag } = require('./actions')
|
2017-11-14 17:04:55 +01:00
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
2017-12-07 01:19:45 +01:00
|
|
|
return {
|
|
|
|
betaUI: state.metamask.featureFlags.betaUI,
|
|
|
|
autoAdd: autoAddToBetaUI(state),
|
|
|
|
isUnlocked: state.metamask.isUnlocked,
|
|
|
|
}
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 01:19:45 +01:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
setFeatureFlagToBeta: () => dispatch(setFeatureFlag('betaUI', true)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(SelectedApp)
|
2017-11-14 17:04:55 +01:00
|
|
|
|
|
|
|
inherits(SelectedApp, Component)
|
2017-12-07 01:19:45 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
2017-11-14 17:04:55 +01:00
|
|
|
|
|
|
|
SelectedApp.prototype.render = function () {
|
|
|
|
const { betaUI } = this.props
|
|
|
|
const Selected = betaUI ? App : OldApp
|
|
|
|
return h(Selected)
|
|
|
|
}
|