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 LocalMessageDuplexStream = require('./lib/local-message-stream.js')
|
||||||
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||||
const RemoteStore = require('./lib/remote-store.js').RemoteStore
|
const RemoteStore = require('./lib/remote-store.js').RemoteStore
|
||||||
|
const MetamaskConfig = require('./config.js')
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const once = require('once')
|
const once = require('once')
|
||||||
restoreContextAfterImports()
|
restoreContextAfterImports()
|
||||||
@ -12,8 +13,6 @@ restoreContextAfterImports()
|
|||||||
delete window.Web3
|
delete window.Web3
|
||||||
window.MetamaskWeb3 = Web3
|
window.MetamaskWeb3 = Web3
|
||||||
|
|
||||||
const DEFAULT_RPC_URL = 'https://rpc.metamask.io/'
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// setup plugin communication
|
// setup plugin communication
|
||||||
@ -93,15 +92,33 @@ publicConfigStore.subscribe(function(state){
|
|||||||
})
|
})
|
||||||
|
|
||||||
// setup sync http provider
|
// setup sync http provider
|
||||||
var providerConfig = publicConfigStore.get('provider') || {}
|
updateProvider({ provider: publicConfigStore.get('provider') })
|
||||||
var providerUrl = providerConfig.rpcTarget ? providerConfig.rpcTarget : DEFAULT_RPC_URL
|
publicConfigStore.subscribe(updateProvider)
|
||||||
var syncProvider = new Web3.providers.HttpProvider(providerUrl)
|
|
||||||
publicConfigStore.subscribe(function(state){
|
var syncProvider = null
|
||||||
if (!state.provider) return
|
var syncProviderUrl = null
|
||||||
if (!state.provider.rpcTarget || state.provider.rpcTarget === providerUrl) return
|
|
||||||
providerUrl = state.provider.rpcTarget
|
function updateProvider(state){
|
||||||
syncProvider = new Web3.providers.HttpProvider(providerUrl)
|
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
|
// handle sync methods
|
||||||
remoteProvider.send = function(payload){
|
remoteProvider.send = function(payload){
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
const Migrator = require('pojo-migrator')
|
const Migrator = require('pojo-migrator')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
|
const MetamaskConfig = require('./config.js')
|
||||||
|
const migrations = require('./migrations')
|
||||||
|
|
||||||
const STORAGE_KEY = 'metamask-config'
|
const STORAGE_KEY = 'metamask-config'
|
||||||
const TESTNET_RPC = 'https://morden.infura.io'
|
const TESTNET_RPC = MetamaskConfig.network.testnet
|
||||||
const MAINNET_RPC = 'https://mainnet.infura.io/'
|
const MAINNET_RPC = MetamaskConfig.network.mainnet
|
||||||
|
|
||||||
const migrations = require('./migrations')
|
|
||||||
|
|
||||||
/* The config-manager is a convenience object
|
/* The config-manager is a convenience object
|
||||||
* wrapping a pojo-migrator.
|
* wrapping a pojo-migrator.
|
||||||
|
Loading…
Reference in New Issue
Block a user