From b5da8a237ec40a43435f3aa4d7d645141fb5cd06 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 16 Sep 2019 19:29:26 -0300 Subject: [PATCH] Remove the disk store (#7170) The disk store has not been written to since MetaMask v4.3.0, as it was removed in #3083. It was kept around so that anything written to disk prior to v4.3.0 could still be restored. It has been a year and a half since that release, so I think it's time to remove the disk store altogether. The consequences of losing locally stored data are small anyway - it's an inconvenience at worst. --- app/scripts/background.js | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 37ccba44e..613c426ac 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -14,7 +14,6 @@ const pump = require('pump') const debounce = require('debounce-stream') const log = require('loglevel') const extension = require('extensionizer') -const LocalStorageStore = require('obs-store/lib/localStorage') const LocalStore = require('./lib/local-store') const storeTransform = require('obs-store/lib/transform') const asStream = require('obs-store/lib/asStream') @@ -43,7 +42,6 @@ const { // METAMASK_TEST_CONFIG is used in e2e tests to set the default network to localhost const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_TEST_CONFIG) -const STORAGE_KEY = 'metamask-config' const METAMASK_DEBUG = process.env.METAMASK_DEBUG log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn') @@ -67,7 +65,6 @@ let notificationIsOpen = false const openMetamaskTabsIDs = {} // state persistence -const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) const localStore = new LocalStore() let versionedData @@ -180,7 +177,6 @@ async function loadStateFromPersistence () { // read from disk // first from preferred, async API: versionedData = (await localStore.get()) || - diskStore.getState() || migrator.generateInitialState(firstTimeState) // check if somehow state is empty @@ -188,21 +184,9 @@ async function loadStateFromPersistence () { // for a small number of users // https://github.com/metamask/metamask-extension/issues/3919 if (versionedData && !versionedData.data) { - // try to recover from diskStore incase only localStore is bad - const diskStoreState = diskStore.getState() - if (diskStoreState && diskStoreState.data) { - // we were able to recover (though it might be old) - versionedData = diskStoreState - const vaultStructure = getObjStructure(versionedData) - sentry.captureMessage('MetaMask - Empty vault found - recovered from diskStore', { - // "extra" key is required by Sentry - extra: { vaultStructure }, - }) - } else { - // unable to recover, clear state - versionedData = migrator.generateInitialState(firstTimeState) - sentry.captureMessage('MetaMask - Empty vault found - unable to recover') - } + // unable to recover, clear state + versionedData = migrator.generateInitialState(firstTimeState) + sentry.captureMessage('MetaMask - Empty vault found - unable to recover') } // report migration errors to sentry