diff options
author | Alexander Tseung <alextsg@users.noreply.github.com> | 2017-12-23 02:43:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-23 02:43:02 +0800 |
commit | a218008adf85dfb5fa8ca93c789e14d9f2090813 (patch) | |
tree | 863dd34eed719074277a8c65397d9e5081b2084b /app | |
parent | 4acd48966edf2e6cf4ced6e3e0983a44dcb2ec13 (diff) | |
download | tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar.gz tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar.bz2 tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar.lz tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar.xz tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.tar.zst tangerine-wallet-browser-a218008adf85dfb5fa8ca93c789e14d9f2090813.zip |
Track usage of old and new UI (#2794)
[NewUI] Track usage of old and new UI
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/config.js | 22 | ||||
-rw-r--r-- | app/scripts/controllers/network.js | 40 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 1 |
3 files changed, 57 insertions, 6 deletions
diff --git a/app/scripts/config.js b/app/scripts/config.js index 1d4ff7c0d..74c5b576e 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -4,6 +4,15 @@ const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' const RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask' const LOCALHOST_RPC_URL = 'http://localhost:8545' +const MAINET_RPC_URL_BETA = 'https://mainnet.infura.io/metamask2' +const ROPSTEN_RPC_URL_BETA = 'https://ropsten.infura.io/metamask2' +const KOVAN_RPC_URL_BETA = 'https://kovan.infura.io/metamask2' +const RINKEBY_RPC_URL_BETA = 'https://rinkeby.infura.io/metamask2' + +const DEFAULT_RPC = 'rinkeby' +const OLD_UI_NETWORK_TYPE = 'network' +const BETA_UI_NETWORK_TYPE = 'networkBeta' + global.METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' module.exports = { @@ -14,9 +23,22 @@ module.exports = { kovan: KOVAN_RPC_URL, rinkeby: RINKEBY_RPC_URL, }, + // Used for beta UI + networkBeta: { + localhost: LOCALHOST_RPC_URL, + mainnet: MAINET_RPC_URL_BETA, + ropsten: ROPSTEN_RPC_URL_BETA, + kovan: KOVAN_RPC_URL_BETA, + rinkeby: RINKEBY_RPC_URL_BETA, + }, networkNames: { 3: 'Ropsten', 4: 'Rinkeby', 42: 'Kovan', }, + enums: { + DEFAULT_RPC, + OLD_UI_NETWORK_TYPE, + BETA_UI_NETWORK_TYPE, + }, } diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 377ba6eca..db1a5b374 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -7,14 +7,19 @@ const ComposedStore = require('obs-store/lib/composed') const extend = require('xtend') const EthQuery = require('eth-query') const createEventEmitterProxy = require('../lib/events-proxy.js') -const RPC_ADDRESS_LIST = require('../config.js').network -const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] +const networkConfig = require('../config.js') +const { OLD_UI_NETWORK_TYPE, DEFAULT_RPC } = networkConfig.enums const INFURA_PROVIDER_TYPES = ['ropsten', 'rinkeby', 'kovan', 'mainnet'] module.exports = class NetworkController extends EventEmitter { constructor (config) { super() + + this._networkEndpointVersion = OLD_UI_NETWORK_TYPE + this._networkEndpoints = this.getNetworkEndpoints(OLD_UI_NETWORK_TYPE) + this._defaultRpc = this._networkEndpoints[DEFAULT_RPC] + config.provider.rpcTarget = this.getRpcAddressForType(config.provider.type, config.provider) this.networkStore = new ObservableStore('loading') this.providerStore = new ObservableStore(config.provider) @@ -24,6 +29,23 @@ module.exports = class NetworkController extends EventEmitter { this.on('networkDidChange', this.lookupNetwork) } + async setNetworkEndpoints (version) { + if (version === this._networkEndpointVersion) { + return + } + + this._networkEndpointVersion = version + this._networkEndpoints = this.getNetworkEndpoints(version) + this._defaultRpc = this._networkEndpoints[DEFAULT_RPC] + const { type } = this.getProviderConfig() + + return this.setProviderType(type, true) + } + + getNetworkEndpoints (version = OLD_UI_NETWORK_TYPE) { + return networkConfig[version] + } + initializeProvider (_providerParams) { this._baseProviderParams = _providerParams const { type, rpcTarget } = this.providerStore.getState() @@ -83,10 +105,13 @@ module.exports = class NetworkController extends EventEmitter { return this.getRpcAddressForType(provider.type) } - async setProviderType (type) { + async setProviderType (type, forceUpdate = false) { assert(type !== 'rpc', `NetworkController.setProviderType - cannot connect by type "rpc"`) // skip if type already matches - if (type === this.getProviderConfig().type) return + if (type === this.getProviderConfig().type && !forceUpdate) { + return + } + const rpcTarget = this.getRpcAddressForType(type) assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`) this.providerStore.updateState({ type, rpcTarget }) @@ -98,8 +123,11 @@ module.exports = class NetworkController extends EventEmitter { } getRpcAddressForType (type, provider = this.getProviderConfig()) { - if (RPC_ADDRESS_LIST[type]) return RPC_ADDRESS_LIST[type] - return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC + if (this._networkEndpoints[type]) { + return this._networkEndpoints[type] + } + + return provider && provider.rpcTarget ? provider.rpcTarget : this._defaultRpc } // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e2a911598..b50a04703 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -353,6 +353,7 @@ module.exports = class MetamaskController extends EventEmitter { submitPassword: nodeify(keyringController.submitPassword, keyringController), // network management + setNetworkEndpoints: nodeify(networkController.setNetworkEndpoints, networkController), setProviderType: nodeify(networkController.setProviderType, networkController), setCustomRpc: nodeify(this.setCustomRpc, this), |