diff options
author | Dan Finlay <dan@danfinlay.com> | 2018-01-25 07:28:15 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2018-01-25 07:28:15 +0800 |
commit | 2f13790653cb20d9d967700133df6cf31ff02d14 (patch) | |
tree | de4fc846025fd1829a478b32f97a72f0ceb7a7e2 /app | |
parent | 76521cf7399c1e694a7202dcb9725ed5e1e2a0d7 (diff) | |
download | tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar.gz tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar.bz2 tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar.lz tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar.xz tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.tar.zst tangerine-wallet-browser-2f13790653cb20d9d967700133df6cf31ff02d14.zip |
Remove local storage writes, add log
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 3e04a31b3..a77763c41 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -35,6 +35,7 @@ let popupIsOpen = false // state persistence const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) const localStore = new LocalStore() +let versionedData // initialization flow initialize().catch(log.error) @@ -53,7 +54,7 @@ async function loadStateFromPersistence () { // migrations const migrator = new Migrator({ migrations }) // read from disk - let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState) + versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState) // fetch from extension store and merge in data if (localStore.isSupported) { @@ -64,13 +65,24 @@ async function loadStateFromPersistence () { log.error('error fetching state from local store:', err) } - versionedData = Object.keys(localData).length > 0 ? localData : versionedData + console.log('Comparing localdata and versionedData') + console.dir({ localData }) + + if (Object.keys(localData).length > 0) { + console.log('using the local store data') + versionedData = localData + } } // migrate data versionedData = await migrator.migrateData(versionedData) + // write to disk - diskStore.putState(versionedData) + localStore.set(versionedData) + .catch((reason) => { + log.error('Problem saving migrated data', versionedData) + }) + // return just the data return versionedData.data } @@ -107,11 +119,9 @@ function setupController (initState) { asStream(controller.store), storeTransform(versionifyData), storeTransform(syncDataWithExtension), - asStream(diskStore) ) function versionifyData (state) { - const versionedData = diskStore.getState() versionedData.data = state return versionedData } @@ -119,6 +129,7 @@ function setupController (initState) { function syncDataWithExtension(state) { if (localStore.isSupported) { try { + console.log('persisting state', state) localStore.set(state) } catch (err) { log.error('error setting state in local store:', err) |