From 197e6e0b77868b0bec76cef303b2eeffda5797bf Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 23 Mar 2017 11:41:32 -0700 Subject: [PATCH] WIP: indexdb is at an err state "provider is undefined" --- app/scripts/popup-core.js | 1 - library/controllers/index-db-controller.js | 32 ++++++++++++++++------ library/lib/setup-iframe.js | 1 - library/sw-core.js | 4 +-- ui/index.js | 1 - 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js index 7ade66922..b1e521a7a 100644 --- a/app/scripts/popup-core.js +++ b/app/scripts/popup-core.js @@ -11,7 +11,6 @@ module.exports = initializePopup function initializePopup (connectionStream) { // setup app - debugger connectToAccountManager(connectionStream, setupApp) } diff --git a/library/controllers/index-db-controller.js b/library/controllers/index-db-controller.js index 3373de113..f7225c00b 100644 --- a/library/controllers/index-db-controller.js +++ b/library/controllers/index-db-controller.js @@ -51,19 +51,35 @@ module.exports = class IndexDbController extends EventEmitter { return this.requestObjectStore(key) .then((dataObject)=> { return new Promise((resolve, reject) => { - const getRequest = dataObject.get(key) - getRequest.onsuccess = (event) => resolve(event.currentTarget.result) - getRequest.onerror = (event) => reject(event) + const getRequest = dataObject.get(key) + getRequest.onsuccess = (event) => { + const serialized = event.currentTarget.result + try { + console.log('serialized:',serialized) + const state = serialized ? JSON.parse(serialized) : {} + resolve(state) + } catch (err) { + reject(err) + } + } + getRequest.onerror = (event) => reject(event) + }) }) - }) } - put (key, store) { + put (key, state) { return this.requestObjectStore(key, 'readwrite') .then((dataObject)=> { - const putRequest = dataObject.put(store) - putRequest.onsuccess = (event) => Promise.resolve(event.currentTarget.result) - putRequest.onerror = (event) => Promise.reject(event) + return new Promise((resolve, reject) => { + try { + const serialized = JSON.stringify(state) + const putRequest = dataObject.put(serialized) + putRequest.onsuccess = (event) => resolve(event.currentTarget.result) + putRequest.onerror = (event) => reject(event) + } catch (err) { + reject(err) + } + }) }) } diff --git a/library/lib/setup-iframe.js b/library/lib/setup-iframe.js index 0aa001dcf..db67163df 100644 --- a/library/lib/setup-iframe.js +++ b/library/lib/setup-iframe.js @@ -5,7 +5,6 @@ module.exports = setupIframe function setupIframe(opts) { - debugger opts = opts || {} var frame = Iframe({ src: opts.zeroClientProvider || 'https://zero.metamask.io/', diff --git a/library/sw-core.js b/library/sw-core.js index 9ceaf1dc5..60fc88039 100644 --- a/library/sw-core.js +++ b/library/sw-core.js @@ -141,8 +141,8 @@ function setupController (initState, client) { // storeTransform(versionifyData), // diskStore // ) - controller.store.subscribe((store) => { - dbController.put('dataStore', store) + controller.store.subscribe((state) => { + dbController.put('dataStore', state) // .then((event) => {debugger}) // .catch((err) => {debugger}) }) diff --git a/ui/index.js b/ui/index.js index 932054027..16875fce4 100644 --- a/ui/index.js +++ b/ui/index.js @@ -14,7 +14,6 @@ log.setLevel(debugMode ? 'debug' : 'warn') function launchApp (opts) { var accountManager = opts.accountManager actions._setBackgroundConnection(accountManager) - debugger // check if we are unlocked first accountManager.getState(function (err, metamaskState) { if (err) throw err