Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all users to the new UI #6082

Merged
merged 5 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@
"typePassword": {
"message": "Type your MetaMask password"
},
"uiMigrationAnnouncement": {
"message": "Welcome to the new MetaMask UI. If you have feedback about the UI or feature requests, please reach out to our support team or on GitHub."
},
"uiWelcome": {
"message": "Welcome to the New UI (Beta)"
},
Expand Down
14 changes: 10 additions & 4 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class PreferencesController {
tokens: [],
suggestedTokens: {},
useBlockie: false,
featureFlags: {
betaUI: true,
skipAnnounceBetaUI: true,
},
featureFlags: {},
knownMethodData: {},
currentLocale: opts.initLangCode,
identities: {},
Expand All @@ -47,6 +44,7 @@ class PreferencesController {
useNativeCurrencyAsPrimaryCurrency: true,
},
completedOnboarding: false,
completedUiMigration: true,
}, opts.initState)

this.diagnostics = opts.diagnostics
Expand Down Expand Up @@ -552,6 +550,14 @@ class PreferencesController {
return Promise.resolve(true)
}

/**
* Sets the {@code completedUiMigration} state to {@code true}, indicating that the user has completed the UI switch.
*/
completeUiMigration () {
this.store.updateState({ completedUiMigration: true })
return Promise.resolve(true)
}

//
// PRIVATE METHODS
//
Expand Down
1 change: 1 addition & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ module.exports = class MetamaskController extends EventEmitter {
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
setPreference: nodeify(preferencesController.setPreference, preferencesController),
completeUiMigration: nodeify(preferencesController.completeUiMigration, preferencesController),
completeOnboarding: nodeify(preferencesController.completeOnboarding, preferencesController),
addKnownMethodData: nodeify(preferencesController.addKnownMethodData, preferencesController),

Expand Down
29 changes: 29 additions & 0 deletions app/scripts/migrations/032.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const version = 32
const clone = require('clone')

/**
* The purpose of this migration is to set the {@code completedUiMigration} flag based on the user's UI preferences
*/
module.exports = {
version,
migrate: async function (originalVersionedData) {
const versionedData = clone(originalVersionedData)
versionedData.meta.version = version
const state = versionedData.data
versionedData.data = transformState(state)
return versionedData
},
}

function transformState (state) {
const { PreferencesController } = state

if (PreferencesController) {
const { betaUI } = PreferencesController.featureFlags || {}
// Users who have been using the "beta" UI are considered to have completed the migration
// as they'll see no difference in this version
PreferencesController.completedUiMigration = betaUI
}

return state
}
22 changes: 2 additions & 20 deletions app/scripts/ui.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const injectCss = require('inject-css')
const OldMetaMaskUiCss = require('../../old-ui/css')
const NewMetaMaskUiCss = require('../../ui/css')
const {getShouldUseNewUi} = require('../../ui/app/selectors')
const startPopup = require('./popup-core')
const PortStream = require('extension-port-stream')
const { getEnvironmentType } = require('./lib/util')
Expand Down Expand Up @@ -49,30 +47,14 @@ async function start () {
if (err) return displayCriticalError(err)

const state = store.getState()
const { metamask: { completedOnboarding, featureFlags } = {} } = state
const { metamask: { completedOnboarding } = {} } = state

if (!completedOnboarding && windowType !== ENVIRONMENT_TYPE_FULLSCREEN) {
global.platform.openExtensionInBrowser()
return
}

let betaUIState = Boolean(featureFlags && featureFlags.betaUI)
const useBetaCss = getShouldUseNewUi(state)

let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss()
let deleteInjectedCss = injectCss(css)
let newBetaUIState

store.subscribe(() => {
const state = store.getState()
newBetaUIState = state.metamask.featureFlags.betaUI
if (newBetaUIState !== betaUIState) {
deleteInjectedCss()
betaUIState = newBetaUIState
css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss()
deleteInjectedCss = injectCss(css)
}
})
injectCss(NewMetaMaskUiCss())
})


Expand Down
8 changes: 3 additions & 5 deletions test/unit/ui/app/reducers/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,15 @@ describe('MetaMask Reducers', () => {
assert.equal(state.useBlockie, true)
})

it('updates feature flag', () => {
it('updates an arbitrary feature flag', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_FEATURE_FLAGS,
value: {
betaUI: true,
skipAnnounceBetaUI: true,
foo: true,
},
})

assert.equal(state.featureFlags.betaUI, true)
assert.equal(state.featureFlags.skipAnnounceBetaUI, true)
assert.equal(state.featureFlags.foo, true)
})

it('updates network endpoint type', () => {
Expand Down
30 changes: 30 additions & 0 deletions ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ var actions = {
UPDATE_PREFERENCES: 'UPDATE_PREFERENCES',
setUseNativeCurrencyAsPrimaryCurrencyPreference,

// Migration of users to new UI
setCompletedUiMigration,
completeUiMigration,
COMPLETE_UI_MIGRATION: 'COMPLETE_UI_MIGRATION',

// Onboarding
setCompletedOnboarding,
completeOnboarding,
Expand Down Expand Up @@ -2474,6 +2479,31 @@ function completeOnboarding () {
}
}

function setCompletedUiMigration () {
return dispatch => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.completeUiMigration(err => {
dispatch(actions.hideLoadingIndication())

if (err) {
dispatch(actions.displayWarning(err.message))
return reject(err)
}

dispatch(actions.completeUiMigration())
resolve()
})
})
}
}

function completeUiMigration () {
return {
type: actions.COMPLETE_UI_MIGRATION,
}
}

function setNetworkNonce (networkNonce) {
return {
type: actions.SET_NETWORK_NONCE,
Expand Down
4 changes: 2 additions & 2 deletions ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Settings from './components/pages/settings'
import Authenticated from './higher-order-components/authenticated'
import Initialized from './higher-order-components/initialized'
import Lock from './components/pages/lock'
import UiMigrationAnnouncement from './components/ui-migration-annoucement'
const RestoreVaultPage = require('./components/pages/keychains/restore-vault').default
const RevealSeedConfirmation = require('./components/pages/keychains/reveal-seed')
const AddTokenPage = require('./components/pages/add-token')
Expand Down Expand Up @@ -173,6 +174,7 @@ class App extends Component {
}
}}
>
<UiMigrationAnnouncement />
<Modal />
<Alert
visible={this.props.alertOpen}
Expand Down Expand Up @@ -303,7 +305,6 @@ App.propTypes = {
unapprovedTypedMessagesCount: PropTypes.number,
welcomeScreenSeen: PropTypes.bool,
isPopup: PropTypes.bool,
betaUI: PropTypes.bool,
isMouseUser: PropTypes.bool,
setMouseUserState: PropTypes.func,
t: PropTypes.func,
Expand Down Expand Up @@ -375,7 +376,6 @@ function mapStateToProps (state) {
frequentRpcListDetail: state.metamask.frequentRpcListDetail || [],
currentCurrency: state.metamask.currentCurrency,
isMouseUser: state.appState.isMouseUser,
betaUI: state.metamask.featureFlags.betaUI,
isRevealingSeedWords: state.metamask.isRevealingSeedWords,
Qr: state.appState.Qr,
welcomeScreenSeen: state.metamask.welcomeScreenSeen,
Expand Down
2 changes: 2 additions & 0 deletions ui/app/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@
@import './gas-customization/index';

@import './gas-customization/gas-price-button-group/index';

@import './ui-migration-annoucement/index';
14 changes: 0 additions & 14 deletions ui/app/components/modals/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import ConfirmRemoveAccount from './confirm-remove-account'
import ConfirmResetAccount from './confirm-reset-account'
import TransactionConfirmed from './transaction-confirmed'
import CancelTransaction from './cancel-transaction'
import WelcomeBeta from './welcome-beta'
import RejectTransactions from './reject-transactions'
import ClearApprovedOrigins from './clear-approved-origins'
import ConfirmCustomizeGasModal from '../gas-customization/gas-modal-page-container'
Expand Down Expand Up @@ -201,19 +200,6 @@ const MODALS = {
},
},

BETA_UI_NOTIFICATION_MODAL: {
contents: h(WelcomeBeta),
mobileModalStyle: {
...modalContainerMobileStyle,
},
laptopModalStyle: {
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},

CLEAR_APPROVED_ORIGINS: {
contents: h(ClearApprovedOrigins),
mobileModalStyle: {
Expand Down
1 change: 0 additions & 1 deletion ui/app/components/modals/welcome-beta/index.js

This file was deleted.

30 changes: 0 additions & 30 deletions ui/app/components/modals/welcome-beta/welcome-beta.component.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ export default class SettingsTab extends PureComponent {
delRpcTarget: PropTypes.func,
displayWarning: PropTypes.func,
revealSeedConfirmation: PropTypes.func,
setFeatureFlagToBeta: PropTypes.func,
showClearApprovalModal: PropTypes.func,
showResetAccountConfirmationModal: PropTypes.func,
warning: PropTypes.string,
history: PropTypes.object,
isMascara: PropTypes.bool,
updateCurrentLocale: PropTypes.func,
currentLocale: PropTypes.string,
useBlockie: PropTypes.bool,
Expand Down Expand Up @@ -338,34 +336,6 @@ export default class SettingsTab extends PureComponent {
)
}

renderOldUI () {
const { t } = this.context
const { setFeatureFlagToBeta } = this.props

return (
<div className="settings-page__content-row">
<div className="settings-page__content-item">
<span>{ t('useOldUI') }</span>
</div>
<div className="settings-page__content-item">
<div className="settings-page__content-item-col">
<Button
type="secondary"
large
className="settings-tab__button--orange"
onClick={event => {
event.preventDefault()
setFeatureFlagToBeta()
}}
>
{ t('useOldUI') }
</Button>
</div>
</div>
</div>
)
}

renderResetAccount () {
const { t } = this.context
const { showResetAccountConfirmationModal } = this.props
Expand Down Expand Up @@ -523,7 +493,7 @@ export default class SettingsTab extends PureComponent {
}

render () {
const { warning, isMascara } = this.props
const { warning } = this.props

return (
<div className="settings-page__content">
Expand All @@ -534,7 +504,6 @@ export default class SettingsTab extends PureComponent {
{ this.renderNewRpcUrl() }
{ this.renderStateLogs() }
{ this.renderSeedWords() }
{ !isMascara && this.renderOldUI() }
{ this.renderResetAccount() }
{ this.renderClearApproval() }
{ this.renderPrivacyOptIn() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ const mapStateToProps = state => {
privacyMode,
} = {},
provider = {},
isMascara,
currentLocale,
} = metamask
const { useNativeCurrencyAsPrimaryCurrency } = preferencesSelector(state)

return {
warning,
isMascara,
currentLocale,
currentCurrency,
conversionDate,
Expand All @@ -55,9 +53,6 @@ const mapDispatchToProps = dispatch => {
revealSeedConfirmation: () => dispatch(revealSeedConfirmation()),
setUseBlockie: value => dispatch(setUseBlockie(value)),
updateCurrentLocale: key => dispatch(updateCurrentLocale(key)),
setFeatureFlagToBeta: () => {
return dispatch(setFeatureFlag('betaUI', false, 'OLD_UI_NOTIFICATION_MODAL'))
},
setHexDataFeatureFlag: shouldShow => dispatch(setFeatureFlag('sendHexData', shouldShow)),
setPrivacyMode: enabled => dispatch(setFeatureFlag('privacyMode', enabled)),
showResetAccountConfirmationModal: () => dispatch(showModal({ name: 'CONFIRM_RESET_ACCOUNT' })),
Expand Down
Loading