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

conditionally use extension store if supported or enabled

This commit is contained in:
Ellie Day 2018-01-02 21:53:11 -08:00
parent 7184db7632
commit 3c6a5b16ad
2 changed files with 13 additions and 3 deletions

View File

@ -50,8 +50,12 @@ async function loadStateFromPersistence () {
// read from disk
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
// fetch from extension store and merge in data
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
versionedData = { ...versionedData, ...extensionData }
if (extensionStore.isSupported && extensionStore.isEnabled) {
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
versionedData = { ...versionedData, ...extensionData }
}
// migrate data
versionedData = await migrator.migrateData(versionedData)
// write to disk
@ -92,7 +96,9 @@ function setupController (initState) {
}
function syncDataWithExtension(state) {
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
if (extensionStore.isSupported && extensionStore.isEnabled) {
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
}
return state
}

View File

@ -14,6 +14,10 @@ const handleDisabledSyncAndResolve = (resolve, toResolve) => {
}
module.exports = class ExtensionStore {
constructor() {
this.isSupported = !!(extension.storage.sync)
this.isEnabled = true // TODO: get value from user settings
}
async fetch() {
return new Promise((resolve) => {
extension.storage.sync.get(KEYS_TO_SYNC, (data) => {