aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-04-16 04:04:17 +0800
committerkumavis <aaron@kumavis.me>2016-04-16 04:04:17 +0800
commitd6114292d0c05b42b1d28d75baad8af0c06509a1 (patch)
treea93d1f15590ddfce886392bca175803184bb66c4 /app/scripts/background.js
parentd840e81a101351bd661668cf0b1f9e5b73683890 (diff)
downloadtangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.gz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.bz2
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.lz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.xz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.zst
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.zip
inpage - use publicConfigStore for selectedAccount and sync provider
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js48
1 files changed, 41 insertions, 7 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 0bd7031d8..db4927083 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -71,13 +71,6 @@ provider.on('block', function(block){
var ethStore = new EthStore(provider)
idStore.setStore(ethStore)
-// copy idStore substate into public store
-var publicConfigStore = new HostStore()
-idStore.on('update', function(state){
- publicConfigStore.set('selectedAddress', state.selectedAddress)
-})
-
-
function getState(){
var state = extend(
ethStore.getState(),
@@ -87,6 +80,47 @@ function getState(){
return state
}
+//
+// public store
+//
+
+// get init state
+var initPublicState = extend(
+ idStoreToPublic(idStore.getState()),
+ configToPublic(configManager.getConfig())
+)
+
+var publicConfigStore = new HostStore(initPublicState)
+
+// subscribe to changes
+configManager.subscribe(function(state){
+ storeSetFromObj(publicConfigStore, configToPublic(state))
+})
+idStore.on('update', function(state){
+ storeSetFromObj(publicConfigStore, idStoreToPublic(state))
+})
+
+// idStore substate
+function idStoreToPublic(state){
+ return {
+ selectedAddress: state.selectedAddress,
+ }
+}
+// config substate
+function configToPublic(state){
+ return {
+ provider: state.provider,
+ }
+}
+// dump obj into store
+function storeSetFromObj(store, obj){
+ Object.keys(obj).forEach(function(key){
+ store.set(key, obj[key])
+ })
+}
+
+
+
// handle rpc requests
function onRpcRequest(remoteStream, payload){
// console.log('MetaMaskPlugin - incoming payload:', payload)