mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
sync rpc fix
This commit is contained in:
parent
cd7fd6353f
commit
a703706cb1
12
app/scripts/config.js
Normal file
12
app/scripts/config.js
Normal file
@ -0,0 +1,12 @@
|
||||
const MAINET_RPC_URL = 'https://mainnet.infura.io/'
|
||||
const TESTNET_RPC_URL = 'https://morden.infura.io/'
|
||||
const DEFAULT_RPC_URL = TESTNET_RPC_URL
|
||||
|
||||
module.exports = {
|
||||
network: {
|
||||
default: DEFAULT_RPC_URL,
|
||||
mainnet: MAINET_RPC_URL,
|
||||
testnet: TESTNET_RPC_URL,
|
||||
},
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -1,11 +1,12 @@
|
||||
const Migrator = require('pojo-migrator')
|
||||
const extend = require('xtend')
|
||||
const MetamaskConfig = require('./config.js')
|
||||
const migrations = require('./migrations')
|
||||
|
||||
const STORAGE_KEY = 'metamask-config'
|
||||
const TESTNET_RPC = 'https://morden.infura.io'
|
||||
const MAINNET_RPC = 'https://mainnet.infura.io/'
|
||||
const TESTNET_RPC = MetamaskConfig.network.testnet
|
||||
const MAINNET_RPC = MetamaskConfig.network.mainnet
|
||||
|
||||
const migrations = require('./migrations')
|
||||
|
||||
/* The config-manager is a convenience object
|
||||
* wrapping a pojo-migrator.
|
||||
|
Loading…
Reference in New Issue
Block a user