1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

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.
This commit is contained in:
Mark Stacey 2020-04-24 00:23:28 -03:00 committed by GitHub
parent 26dcb3af9b
commit a36e6d414b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 48 deletions

View File

@ -134,7 +134,6 @@ initialize().catch(log.error)
* @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 {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} 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.

View File

@ -11,7 +11,6 @@ class PreferencesController {
* @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 {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 {object} store.accountTokens The tokens stored per account and then per network type
* @property {object} store.assetImages Contains assets objects related to assets added
@ -29,7 +28,6 @@ class PreferencesController {
constructor (opts = {}) {
const initState = Object.assign({
frequentRpcListDetail: [],
currentAccountTab: 'history',
accountTokens: {},
assetImages: {},
tokens: [],
@ -477,20 +475,6 @@ class PreferencesController {
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
*

View File

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

View File

@ -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
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)
})
})

View File

@ -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) {
return {
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) {
log.debug(`background.getState`)
return new Promise((resolve, reject) => {