2017-11-14 17:04:55 +01:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
2018-03-16 01:29:45 +01:00
|
|
|
const connect = require('./metamask-connect')
|
2017-11-14 17:04:55 +01:00
|
|
|
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')
|
2017-12-22 19:43:02 +01:00
|
|
|
const { setFeatureFlag, setNetworkEndpoints } = require('./actions')
|
|
|
|
const { BETA_UI_NETWORK_TYPE } = require('../../app/scripts/config').enums
|
2017-11-14 17:04:55 +01:00
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
2018-01-15 22:23:44 +01:00
|
|
|
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,
|
|
|
|
}
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 01:19:45 +01:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-12-22 19:43:02 +01:00
|
|
|
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)))
|
|
|
|
},
|
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 () {
|
2018-01-15 22:23:44 +01:00
|
|
|
Component.call(this)
|
2017-12-07 01:19:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectedApp.prototype.componentWillReceiveProps = function (nextProps) {
|
2018-01-15 22:23:44 +01:00
|
|
|
// Code commented out until we begin auto adding users to NewUI
|
|
|
|
const {
|
|
|
|
// isUnlocked,
|
|
|
|
// setFeatureFlagWithModal,
|
|
|
|
setFeatureFlagWithoutModal,
|
|
|
|
isMascara,
|
|
|
|
// firstTime,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
// if (isMascara || firstTime) {
|
|
|
|
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 () {
|
2018-01-15 22:23:44 +01:00
|
|
|
// Code commented out until we begin auto adding users to NewUI
|
|
|
|
// const { betaUI, isMascara, firstTime } = this.props
|
|
|
|
// const Selected = betaUI || isMascara || firstTime ? App : OldApp
|
|
|
|
|
|
|
|
const { betaUI, isMascara } = this.props
|
|
|
|
const Selected = betaUI || isMascara ? App : OldApp
|
2017-12-22 04:03:01 +01:00
|
|
|
|
2017-11-14 17:04:55 +01:00
|
|
|
return h(Selected)
|
|
|
|
}
|