1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/select-app.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

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')
const { autoAddToBetaUI } = require('./selectors')
const { setFeatureFlag } = require('./actions')
2017-11-14 17:04:55 +01:00
function mapStateToProps (state) {
return {
betaUI: state.metamask.featureFlags.betaUI,
autoAdd: autoAddToBetaUI(state),
isUnlocked: state.metamask.isUnlocked,
isMascara: state.metamask.isMascara,
}
2017-11-14 17:04:55 +01:00
}
function mapDispatchToProps (dispatch) {
return {
setFeatureFlagWithModal: () => dispatch(setFeatureFlag('betaUI', true, 'BETA_UI_NOTIFICATION_MODAL')),
setFeatureFlagWithoutModal: () => dispatch(setFeatureFlag('betaUI', true)),
}
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(SelectedApp)
2017-11-14 17:04:55 +01:00
inherits(SelectedApp, Component)
function SelectedApp () {
Component.call(this)
}
SelectedApp.prototype.componentWillReceiveProps = function (nextProps) {
const {
isUnlocked,
setFeatureFlagWithModal,
setFeatureFlagWithoutModal,
isMascara,
} = this.props
if (isMascara) {
setFeatureFlagWithoutModal()
} else if (!isUnlocked && nextProps.isUnlocked && (nextProps.autoAdd)) {
setFeatureFlagWithModal()
}
}
2017-11-14 17:04:55 +01:00
SelectedApp.prototype.render = function () {
const { betaUI, isMascara } = this.props
const Selected = betaUI || isMascara ? App : OldApp
2017-11-14 17:04:55 +01:00
return h(Selected)
}