1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/select-app.js
Alexander Tseung a218008adf
Track usage of old and new UI (#2794)
[NewUI] Track usage of old and new UI
2017-12-22 10:43:02 -08:00

62 lines
1.8 KiB
JavaScript

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, setNetworkEndpoints } = require('./actions')
const { BETA_UI_NETWORK_TYPE } = require('../../app/scripts/config').enums
function mapStateToProps (state) {
return {
betaUI: state.metamask.featureFlags.betaUI,
autoAdd: autoAddToBetaUI(state),
isUnlocked: state.metamask.isUnlocked,
isMascara: state.metamask.isMascara,
firstTime: Object.keys(state.metamask.identities).length === 0,
}
}
function mapDispatchToProps (dispatch) {
return {
setFeatureFlagWithModal: () => {
return dispatch(setFeatureFlag('betaUI', true, 'BETA_UI_NOTIFICATION_MODAL'))
.then(() => dispatch(setNetworkEndpoints(BETA_UI_NETWORK_TYPE)))
},
setFeatureFlagWithoutModal: () => {
return dispatch(setFeatureFlag('betaUI', true))
.then(() => dispatch(setNetworkEndpoints(BETA_UI_NETWORK_TYPE)))
},
}
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(SelectedApp)
inherits(SelectedApp, Component)
function SelectedApp () {
Component.call(this)
}
SelectedApp.prototype.componentWillReceiveProps = function (nextProps) {
const {
isUnlocked,
setFeatureFlagWithModal,
setFeatureFlagWithoutModal,
isMascara,
firstTime,
} = this.props
if (isMascara || firstTime) {
setFeatureFlagWithoutModal()
} else if (!isUnlocked && nextProps.isUnlocked && (nextProps.autoAdd)) {
setFeatureFlagWithModal()
}
}
SelectedApp.prototype.render = function () {
const { betaUI, isMascara, firstTime } = this.props
const Selected = betaUI || isMascara || firstTime ? App : OldApp
return h(Selected)
}