mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
User is automatically added to new UI if they meet conditions at time of login.
This commit is contained in:
parent
9db00fa507
commit
bd5ce9461e
@ -4,18 +4,44 @@ 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')
|
||||
|
||||
function mapStateToProps (state) {
|
||||
return { betaUI: state.metamask.featureFlags.betaUI }
|
||||
return {
|
||||
betaUI: state.metamask.featureFlags.betaUI,
|
||||
autoAdd: autoAddToBetaUI(state),
|
||||
isUnlocked: state.metamask.isUnlocked,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect(mapStateToProps)(SelectedApp)
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return {
|
||||
setFeatureFlagToBeta: () => dispatch(setFeatureFlag('betaUI', true)),
|
||||
}
|
||||
}
|
||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(SelectedApp)
|
||||
|
||||
inherits(SelectedApp, Component)
|
||||
function SelectedApp () { Component.call(this) }
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
SelectedApp.prototype.render = function () {
|
||||
const { betaUI } = this.props
|
||||
const { autoAdd } = this.state
|
||||
const Selected = betaUI ? App : OldApp
|
||||
return h(Selected)
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ const selectors = {
|
||||
getSendAmount,
|
||||
getSelectedTokenToFiatRate,
|
||||
getSelectedTokenContract,
|
||||
autoAddToBetaUI,
|
||||
}
|
||||
|
||||
module.exports = selectors
|
||||
@ -158,3 +159,20 @@ function getSelectedTokenContract (state) {
|
||||
? global.eth.contract(abi).at(selectedToken.address)
|
||||
: null
|
||||
}
|
||||
|
||||
function autoAddToBetaUI (state) {
|
||||
const autoAddTransactionThreshold = 12
|
||||
const autoAddAccountsThreshold = 2
|
||||
const autoAddTokensThreshold = 1
|
||||
|
||||
const numberOfTransactions = state.metamask.selectedAddressTxList.length
|
||||
const numberOfAccounts = Object.keys(state.metamask.accounts).length
|
||||
const numberOfTokensAdded = state.metamask.tokens.length
|
||||
|
||||
const userPassesThreshold = (numberOfTransactions > autoAddTransactionThreshold) &&
|
||||
(numberOfAccounts > autoAddAccountsThreshold) &&
|
||||
(numberOfTokensAdded > autoAddTokensThreshold)
|
||||
const userIsNotInBeta = !state.metamask.featureFlags.betaUI
|
||||
|
||||
return userIsNotInBeta && userPassesThreshold
|
||||
}
|
Loading…
Reference in New Issue
Block a user