1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Some fixes for new storage strategy

- Don't persist undefined data
- Write to new storage strategy without waiting for completion.
- Continue writing to localStorage as fallback.
This commit is contained in:
Dan Finlay 2018-03-07 14:23:31 -08:00
parent 8965e59ba7
commit d58e47edec

View File

@ -93,6 +93,9 @@ async function loadStateFromPersistence () {
.catch((reason) => {
log.error('Problem saving migrated data', versionedData)
})
if (versionedData) {
diskStore.putState(versionedData)
}
// return just the data
return versionedData.data
@ -129,6 +132,7 @@ function setupController (initState) {
debounce(2000),
storeTransform(versionifyData),
storeTransform(syncDataWithExtension),
asStream(diskStore),
(error) => {
log.error('pump hit error', error)
}
@ -139,14 +143,14 @@ function setupController (initState) {
return versionedData
}
async function syncDataWithExtension(state) {
function syncDataWithExtension(state) {
if (localStore.isSupported) {
try {
await localStore.set(state)
} catch (err) {
localStore.set(state)
.catch((err) => {
log.error('error setting state in local store:', err)
}
})
} else { log.error('local store not supported') }
return state
}