aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/inpage.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-05-20 07:53:16 +0800
committerkumavis <aaron@kumavis.me>2016-05-20 07:53:16 +0800
commita703706cb115c17d072f277045a2ef7d838d9762 (patch)
tree7cf4eda7c3d0a2f69fd55cc20e93062d33ca2b36 /app/scripts/inpage.js
parentcd7fd6353febfc796b9f67be18dff293f4f67120 (diff)
downloadtangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar.gz
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar.bz2
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar.lz
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar.xz
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.tar.zst
tangerine-wallet-browser-a703706cb115c17d072f277045a2ef7d838d9762.zip
sync rpc fix
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r--app/scripts/inpage.js39
1 files changed, 28 insertions, 11 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 33e2c9358..91d782a32 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -4,6 +4,7 @@ const StreamProvider = require('./lib/stream-provider.js')
const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const RemoteStore = require('./lib/remote-store.js').RemoteStore
+const MetamaskConfig = require('./config.js')
const Web3 = require('web3')
const once = require('once')
restoreContextAfterImports()
@@ -12,8 +13,6 @@ restoreContextAfterImports()
delete window.Web3
window.MetamaskWeb3 = Web3
-const DEFAULT_RPC_URL = 'https://rpc.metamask.io/'
-
//
// setup plugin communication
@@ -93,15 +92,33 @@ publicConfigStore.subscribe(function(state){
})
// setup sync http provider
-var providerConfig = publicConfigStore.get('provider') || {}
-var providerUrl = providerConfig.rpcTarget ? providerConfig.rpcTarget : DEFAULT_RPC_URL
-var syncProvider = new Web3.providers.HttpProvider(providerUrl)
-publicConfigStore.subscribe(function(state){
- if (!state.provider) return
- if (!state.provider.rpcTarget || state.provider.rpcTarget === providerUrl) return
- providerUrl = state.provider.rpcTarget
- syncProvider = new Web3.providers.HttpProvider(providerUrl)
-})
+updateProvider({ provider: publicConfigStore.get('provider') })
+publicConfigStore.subscribe(updateProvider)
+
+var syncProvider = null
+var syncProviderUrl = null
+
+function updateProvider(state){
+ var providerConfig = state.provider || {}
+ var newSyncProviderUrl = undefined
+
+ if (providerConfig.rpcTarget) {
+ newSyncProviderUrl = providerConfig.rpcTarget
+ } else {
+ switch(providerConfig.type) {
+ case 'testnet':
+ newSyncProviderUrl = MetamaskConfig.network.testnet
+ break
+ case 'mainnet':
+ newSyncProviderUrl = MetamaskConfig.network.mainnet
+ break
+ default:
+ newSyncProviderUrl = MetamaskConfig.network.default
+ }
+ }
+ if (newSyncProviderUrl === syncProviderUrl) return
+ syncProvider = new Web3.providers.HttpProvider(newSyncProviderUrl)
+}
// handle sync methods
remoteProvider.send = function(payload){