aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/inpage-provider.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/lib/inpage-provider.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/lib/inpage-provider.js')
-rw-r--r--app/scripts/lib/inpage-provider.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index 11bd5cc3a..64301be78 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -1,7 +1,7 @@
const Streams = require('mississippi')
const StreamProvider = require('web3-stream-provider')
const ObjectMultiplex = require('./obj-multiplex')
-const RemoteStore = require('./remote-store.js').RemoteStore
+const RemoteStore = require('./observable/remote')
const createRandomId = require('./random-id')
module.exports = MetamaskInpageProvider
@@ -72,13 +72,13 @@ MetamaskInpageProvider.prototype.send = function (payload) {
case 'eth_accounts':
// read from localStorage
- selectedAccount = self.publicConfigStore.get('selectedAccount')
+ selectedAccount = self.publicConfigStore.get().selectedAccount
result = selectedAccount ? [selectedAccount] : []
break
case 'eth_coinbase':
// read from localStorage
- selectedAccount = self.publicConfigStore.get('selectedAccount')
+ selectedAccount = self.publicConfigStore.get().selectedAccount
result = selectedAccount || '0x0000000000000000000000000000000000000000'
break
@@ -117,9 +117,15 @@ MetamaskInpageProvider.prototype.isMetaMask = true
function remoteStoreWithLocalStorageCache (storageKey) {
// read local cache
- var initState = JSON.parse(localStorage[storageKey] || '{}')
- var store = new RemoteStore(initState)
- // cache the latest state locally
+ let initState
+ try {
+ initState = JSON.parse(localStorage[storageKey] || '{}')
+ } catch (err) {
+ initState = {}
+ }
+ // intialize store
+ const store = new RemoteStore(initState)
+ // write local cache
store.subscribe(function (state) {
localStorage[storageKey] = JSON.stringify(state)
})