aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/background.js15
-rw-r--r--app/scripts/lib/local-store.js25
2 files changed, 33 insertions, 7 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index d9a2b0a6e..9790129aa 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -4,7 +4,7 @@ const pump = require('pump')
const log = require('loglevel')
const extension = require('extensionizer')
const LocalStorageStore = require('obs-store/lib/localStorage')
-const ExtensionStore = require('./lib/extension-store')
+const LocalStore = require('./lib/local-store')
const storeTransform = require('obs-store/lib/transform')
const asStream = require('obs-store/lib/asStream')
const ExtensionPlatform = require('./platforms/extension')
@@ -29,7 +29,7 @@ let popupIsOpen = false
// state persistence
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
-const extensionStore = new ExtensionStore()
+const localStore = new LocalStore()
// initialization flow
initialize().catch(log.error)
@@ -51,9 +51,10 @@ async function loadStateFromPersistence () {
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
// fetch from extension store and merge in data
- 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 }
+ if (localStore.isSupported) {
+ const localData = await localStore.get()
+ // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
+ versionedData = localData || versionedData
}
// migrate data
@@ -96,8 +97,8 @@ function setupController (initState) {
}
function syncDataWithExtension(state) {
- if (extensionStore.isSupported && extensionStore.isEnabled) {
- extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
+ if (localStore.isSupported) {
+ localStore.set(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
}
return state
}
diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js
new file mode 100644
index 000000000..32faac96b
--- /dev/null
+++ b/app/scripts/lib/local-store.js
@@ -0,0 +1,25 @@
+// We should not rely on local storage in an extension!
+// We should use this instead!
+// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
+
+const extension = require('extensionizer')
+const STORAGE_KEY = 'metamask-config'
+
+module.exports = class ExtensionStore {
+ constructor() {
+ this.isSupported = !!(extension.storage.local)
+ if (!this.isSupported) {
+ log.error('Storage local API not available.')
+ }
+ }
+ async get() {
+ return new Promise((resolve) => {
+ extension.storage.local.get(STORAGE_KEY, resolve)
+ })
+ }
+ async set(state) {
+ return new Promise((resolve) => {
+ extension.storage.local.set(state, resolve)
+ })
+ }
+}