aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-12 11:04:19 +0800
committerkumavis <aaron@kumavis.me>2017-01-12 11:31:21 +0800
commit8012ede12698477692b80769781096b559159a32 (patch)
tree17f75325da8f5d0abf2c1f37fa0573320730b6a7 /app/scripts/background.js
parentcc5e9aca4fa2a1e78c49be680405d93ac918bccf (diff)
downloadtangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar.gz
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar.bz2
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar.lz
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar.xz
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.tar.zst
tangerine-wallet-browser-8012ede12698477692b80769781096b559159a32.zip
background - introduce ObservableStore
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js45
1 files changed, 13 insertions, 32 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 6b7926526..f3c0b52b3 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -13,15 +13,18 @@ const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
var popupIsOpen = false
+
const controller = new MetamaskController({
// User confirmation callbacks:
showUnconfirmedMessage: triggerUi,
unlockAccountMessage: triggerUi,
showUnapprovedTx: triggerUi,
- // Persistence Methods:
- setData,
- loadData,
+ // initial state
+ initState: loadData(),
})
+// setup state persistence
+controller.store.subscribe(setData)
+
const txManager = controller.txManager
function triggerUi () {
if (!popupIsOpen) notification.show()
@@ -112,13 +115,7 @@ function updateBadge () {
// data :: setters/getters
function loadData () {
- var oldData = getOldStyleData()
- var newData
- try {
- newData = JSON.parse(window.localStorage[STORAGE_KEY])
- } catch (e) {}
-
- var data = extend({
+ let defaultData = {
meta: {
version: 0,
},
@@ -129,32 +126,16 @@ function loadData () {
},
},
},
- }, oldData || null, newData || null)
- return data
-}
-
-function getOldStyleData () {
- var config, wallet, seedWords
-
- var result = {
- meta: { version: 0 },
- data: {},
}
+ var persisted
try {
- config = JSON.parse(window.localStorage['config'])
- result.data.config = config
- } catch (e) {}
- try {
- wallet = JSON.parse(window.localStorage['lightwallet'])
- result.data.wallet = wallet
- } catch (e) {}
- try {
- seedWords = window.localStorage['seedWords']
- result.data.seedWords = seedWords
- } catch (e) {}
+ persisted = JSON.parse(window.localStorage[STORAGE_KEY])
+ } catch (err) {
+ persisted = null
+ }
- return result
+ return extend(defaultData, persisted)
}
function setData (data) {