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-12-20 19:22:50 +01:00
|
|
|
isMascara: state.metamask.isMascara,
|
2017-12-07 01:19:45 +01:00
|
|
|
}
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 01:19:45 +01:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-12-20 19:22:50 +01:00
|
|
|
setFeatureFlagWithModal: () => dispatch(setFeatureFlag('betaUI', true, 'BETA_UI_NOTIFICATION_MODAL')),
|
|
|
|
setFeatureFlagWithoutModal: () => dispatch(setFeatureFlag('betaUI', true)),
|
2017-12-07 01:19:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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 () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectedApp.prototype.componentWillReceiveProps = function (nextProps) {
|
2017-12-20 19:22:50 +01:00
|
|
|
const {
|
|
|
|
isUnlocked,
|
|
|
|
setFeatureFlagWithModal,
|
|
|
|
setFeatureFlagWithoutModal,
|
|
|
|
isMascara,
|
|
|
|
} = this.props
|
2017-12-07 01:19:45 +01:00
|
|
|
|
2017-12-20 19:22:50 +01:00
|
|
|
if (isMascara) {
|
|
|
|
setFeatureFlagWithoutModal()
|
|
|
|
} else if (!isUnlocked && nextProps.isUnlocked && (nextProps.autoAdd)) {
|
|
|
|
setFeatureFlagWithModal()
|
2017-12-07 01:19:45 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-14 17:04:55 +01:00
|
|
|
|
|
|
|
SelectedApp.prototype.render = function () {
|
2017-12-20 19:22:50 +01:00
|
|
|
const { betaUI, isMascara } = this.props
|
|
|
|
const Selected = betaUI || isMascara ? App : OldApp
|
2017-11-14 17:04:55 +01:00
|
|
|
return h(Selected)
|
|
|
|
}
|