From 7ec068d279276a7e0fcc862d18e3fd3e1648728b Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 4 Oct 2017 23:21:30 -0700 Subject: [PATCH] mascara/background: use async await --- mascara/src/background.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/mascara/src/background.js b/mascara/src/background.js index cf043a4f0..8aa1d8fe2 100644 --- a/mascara/src/background.js +++ b/mascara/src/background.js @@ -54,7 +54,7 @@ async function loadStateFromPersistence () { return migratedData.data } -function setupController (initState, client) { +async function setupController (initState, client) { // // MetaMask Controller @@ -74,20 +74,19 @@ function setupController (initState, client) { }) global.metamaskController = controller - controller.store.subscribe((state) => { - versionifyData(state) - .then((versionedData) => dbController.put(versionedData)) - .catch((err) => { console.error(err) }) + controller.store.subscribe(async (state) => { + try { + const versionedData = await versionifyData(state) + await dbController.put(versionedData) + } catch (e) { console.error('METAMASK Error:', e) } }) - function versionifyData (state) { - return dbController.get() - .then((rawData) => { - return Promise.resolve({ - data: state, - meta: rawData.meta, - }) -} - ) + + async function versionifyData (state) { + const rawData = await dbController.get() + return { + data: state, + meta: rawData.meta, + } } // @@ -118,12 +117,6 @@ function setupController (initState, client) { controller.setupProviderConnection(mx.createStream('provider'), originDomain) controller.setupPublicConfig(mx.createStream('publicConfig')) } - - // - // User Interface setup - // - return Promise.resolve() - } // // this will be useful later but commented out for linting for now (liiiinting) // function sendMessageToAllClients (message) {