Remove unused `currentAccountTab` state (#8404)

This state has been removed from the background. It was used for the
old UI, and has been unused for some time. A migration has been added
to delete this state as well.

The action creator responsible for updating this state has been removed
from the UI as well, along with the `callBackgroundThenUpdateNoSpinner`
convenience function, which was only used for this action.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent 26dcb3af9b
commit a36e6d414b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/background.js
  2. 16
      app/scripts/controllers/preferences.js
  3. 1
      app/scripts/metamask-controller.js
  4. 23
      app/scripts/migrations/043.js
  5. 1
      app/scripts/migrations/index.js
  6. 1
      test/data/2-state.json
  7. 1
      test/data/v17-long-history.json
  8. 1
      test/e2e/fixtures/imported-account/state.json
  9. 1
      test/unit/migrations/035-test.js
  10. 55
      test/unit/migrations/043-test.js
  11. 26
      ui/app/store/actions.js

@ -134,7 +134,6 @@ initialize().catch(log.error)
* @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs. * @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs.
* @property {string[]} keyringTypes - An array of unique keyring identifying strings, representing available strategies for creating accounts. * @property {string[]} keyringTypes - An array of unique keyring identifying strings, representing available strategies for creating accounts.
* @property {Keyring[]} keyrings - An array of keyring descriptions, summarizing the accounts that are available for use, and what keyrings they belong to. * @property {Keyring[]} keyrings - An array of keyring descriptions, summarizing the accounts that are available for use, and what keyrings they belong to.
* @property {string} currentAccountTab - A view identifying string for displaying the current displayed view, allows user to have a preferred tab in the old UI (between tokens and history).
* @property {string} selectedAddress - A lower case hex string of the currently selected address. * @property {string} selectedAddress - A lower case hex string of the currently selected address.
* @property {string} currentCurrency - A string identifying the user's preferred display currency, for use in showing conversion rates. * @property {string} currentCurrency - A string identifying the user's preferred display currency, for use in showing conversion rates.
* @property {number} conversionRate - A number representing the current exchange rate from the user's preferred currency to Ether. * @property {number} conversionRate - A number representing the current exchange rate from the user's preferred currency to Ether.

@ -11,7 +11,6 @@ class PreferencesController {
* @param {Object} opts - Overrides the defaults for the initial state of this.store * @param {Object} opts - Overrides the defaults for the initial state of this.store
* @property {object} store The stored object containing a users preferences, stored in local storage * @property {object} store The stored object containing a users preferences, stored in local storage
* @property {array} store.frequentRpcList A list of custom rpcs to provide the user * @property {array} store.frequentRpcList A list of custom rpcs to provide the user
* @property {string} store.currentAccountTab Indicates the selected tab in the ui
* @property {array} store.tokens The tokens the user wants display in their token lists * @property {array} store.tokens The tokens the user wants display in their token lists
* @property {object} store.accountTokens The tokens stored per account and then per network type * @property {object} store.accountTokens The tokens stored per account and then per network type
* @property {object} store.assetImages Contains assets objects related to assets added * @property {object} store.assetImages Contains assets objects related to assets added
@ -29,7 +28,6 @@ class PreferencesController {
constructor (opts = {}) { constructor (opts = {}) {
const initState = Object.assign({ const initState = Object.assign({
frequentRpcListDetail: [], frequentRpcListDetail: [],
currentAccountTab: 'history',
accountTokens: {}, accountTokens: {},
assetImages: {}, assetImages: {},
tokens: [], tokens: [],
@ -477,20 +475,6 @@ class PreferencesController {
return Promise.resolve(label) return Promise.resolve(label)
} }
/**
* Setter for the `currentAccountTab` property
*
* @param {string} currentAccountTab - Specifies the new tab to be marked as current
* @returns {Promise<void>} - Promise resolves with undefined
*
*/
setCurrentAccountTab (currentAccountTab) {
return new Promise((resolve) => {
this.store.updateState({ currentAccountTab })
resolve()
})
}
/** /**
* updates custom RPC details * updates custom RPC details
* *

@ -492,7 +492,6 @@ export default class MetamaskController extends EventEmitter {
addToken: nodeify(preferencesController.addToken, preferencesController), addToken: nodeify(preferencesController.addToken, preferencesController),
removeToken: nodeify(preferencesController.removeToken, preferencesController), removeToken: nodeify(preferencesController.removeToken, preferencesController),
removeSuggestedTokens: nodeify(preferencesController.removeSuggestedTokens, preferencesController), removeSuggestedTokens: nodeify(preferencesController.removeSuggestedTokens, preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController),
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController), setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController), setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
setPreference: nodeify(preferencesController.setPreference, preferencesController), setPreference: nodeify(preferencesController.setPreference, preferencesController),

@ -0,0 +1,23 @@
const version = 43
import { cloneDeep } from 'lodash'
/**
* Remove unused 'currentAccountTab' state
*/
export default {
version,
migrate: async function (originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData)
versionedData.meta.version = version
const state = versionedData.data
versionedData.data = transformState(state)
return versionedData
},
}
function transformState (state) {
if (state?.PreferencesController?.currentAccountTab) {
delete state.PreferencesController.currentAccountTab
}
return state
}

@ -53,6 +53,7 @@ const migrations = [
require('./040').default, require('./040').default,
require('./041').default, require('./041').default,
require('./042').default, require('./042').default,
require('./043').default,
] ]
export default migrations export default migrations

@ -38,7 +38,6 @@
} }
], ],
"frequentRpcList": [], "frequentRpcList": [],
"currentAccountTab": "history",
"tokens": [], "tokens": [],
"useBlockie": false, "useBlockie": false,
"featureFlags": {}, "featureFlags": {},

@ -44,7 +44,6 @@
}, },
"PreferencesController": { "PreferencesController": {
"frequentRpcList": [], "frequentRpcList": [],
"currentAccountTab": "history",
"tokens": [], "tokens": [],
"selectedAddress": "0x3ae39e89dc7e736cce53091057a45bf44b1a566c" "selectedAddress": "0x3ae39e89dc7e736cce53091057a45bf44b1a566c"
}, },

@ -83,7 +83,6 @@
}, },
"assetImages": {}, "assetImages": {},
"completedOnboarding": true, "completedOnboarding": true,
"currentAccountTab": "history",
"currentLocale": "en", "currentLocale": "en",
"featureFlags": { "featureFlags": {
"showIncomingTransactions": true, "showIncomingTransactions": true,

@ -62,7 +62,6 @@ describe('migration #35', function () {
data: { data: {
PreferencesController: { PreferencesController: {
frequentRpcListDetail: [], frequentRpcListDetail: [],
currentAccountTab: 'history',
accountTokens: {}, accountTokens: {},
assetImages: {}, assetImages: {},
tokens: [], tokens: [],

@ -0,0 +1,55 @@
import { strict as assert } from 'assert'
import migration43 from '../../../app/scripts/migrations/043'
describe('migration #43', function () {
it('should update the version metadata', async function () {
const oldStorage = {
'meta': {
'version': 42,
},
'data': {},
}
const newStorage = await migration43.migrate(oldStorage)
assert.deepEqual(newStorage.meta, {
'version': 43,
})
})
it('should delete currentAccountTab state', async function () {
const oldStorage = {
meta: {},
data: {
PreferencesController: {
currentAccountTab: 'history',
bar: 'baz',
},
foo: 'bar',
},
}
const newStorage = await migration43.migrate(oldStorage)
assert.deepEqual(newStorage.data, {
PreferencesController: {
bar: 'baz',
},
foo: 'bar',
})
})
it('should do nothing if currentAccountTab state does not exist', async function () {
const oldStorage = {
meta: {},
data: {
PreferencesController: {
bar: 'baz',
},
foo: 'bar',
},
}
const newStorage = await migration43.migrate(oldStorage)
assert.deepEqual(oldStorage.data, newStorage.data)
})
})

@ -1174,11 +1174,6 @@ export function lockMetamask () {
} }
} }
export function setCurrentAccountTab (newTabName) {
log.debug(`background.setCurrentAccountTab: ${newTabName}`)
return callBackgroundThenUpdateNoSpinner(background.setCurrentAccountTab, newTabName)
}
export function setSelectedToken (tokenAddress) { export function setSelectedToken (tokenAddress) {
return { return {
type: actionConstants.SET_SELECTED_TOKEN, type: actionConstants.SET_SELECTED_TOKEN,
@ -1878,27 +1873,6 @@ export function setMouseUserState (isMouseUser) {
} }
} }
/**
* A function generator for a common pattern wherein:
* * We call a background method.
* * If it errored, we show a warning.
* * If it didn't, we update the state.
*
* @param {*} method - The background method to call
* @param {...any} args - The args to invoke the background method with
*/
export function callBackgroundThenUpdateNoSpinner (method, ...args) {
return (dispatch) => {
method.call(background, ...args, (err) => {
if (err) {
return dispatch(displayWarning(err.message))
}
forceUpdateMetamaskState(dispatch)
})
}
}
export function forceUpdateMetamaskState (dispatch) { export function forceUpdateMetamaskState (dispatch) {
log.debug(`background.getState`) log.debug(`background.getState`)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

Loading…
Cancel
Save