diff options
author | Alexander Tseung <alextsg@gmail.com> | 2017-12-23 03:00:46 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2017-12-23 03:00:46 +0800 |
commit | 06410381d4b738fe22aa24973c7f9568d295f570 (patch) | |
tree | 69bd8701cdaa417cb6c0f46deff43414122101db /app/scripts/controllers | |
parent | 06f496310ce7d719bbb5690f307db143ba57a1a7 (diff) | |
parent | a218008adf85dfb5fa8ca93c789e14d9f2090813 (diff) | |
download | tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar.gz tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar.bz2 tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar.lz tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar.xz tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.tar.zst tangerine-wallet-browser-06410381d4b738fe22aa24973c7f9568d295f570.zip |
Merge branch 'NewUI-flat' into merge-master
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/network.js | 40 | ||||
-rw-r--r-- | app/scripts/controllers/preferences.js | 37 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 4 |
3 files changed, 75 insertions, 6 deletions
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/controllers/preferences.js b/app/scripts/controllers/preferences.js index c42f47037..39d15fd83 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -9,11 +9,21 @@ class PreferencesController { frequentRpcList: [], currentAccountTab: 'history', tokens: [], + useBlockie: false, + featureFlags: {}, }, opts.initState) this.store = new ObservableStore(initState) } // PUBLIC METHODS + setUseBlockie (val) { + this.store.updateState({ useBlockie: val }) + } + + getUseBlockie () { + return this.store.getState().useBlockie + } + setSelectedAddress (_address) { return new Promise((resolve, reject) => { const address = normalizeAddress(_address) @@ -43,6 +53,17 @@ class PreferencesController { } this.store.updateState({ tokens }) + + return Promise.resolve(tokens) + } + + removeToken (rawAddress) { + const tokens = this.store.getState().tokens + + const updatedTokens = tokens.filter(token => token.address !== rawAddress) + + this.store.updateState({ tokens: updatedTokens }) + return Promise.resolve(updatedTokens) } getTokens () { @@ -82,6 +103,22 @@ class PreferencesController { getFrequentRpcList () { return this.store.getState().frequentRpcList } + + setFeatureFlag (feature, activated) { + const currentFeatureFlags = this.store.getState().featureFlags + const updatedFeatureFlags = { + ...currentFeatureFlags, + [feature]: activated, + } + + this.store.updateState({ featureFlags: updatedFeatureFlags }) + + return Promise.resolve(updatedFeatureFlags) + } + + getFeatureFlags () { + return this.store.getState().featureFlags + } // // PRIVATE METHODS // diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 7c7efb84d..7f3130540 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -193,6 +193,10 @@ module.exports = class TransactionController extends EventEmitter { this.txStateManager.updateTx(txMeta, 'retryTransaction: manual retry') } + async updateTransaction (txMeta) { + this.txStateManager.updateTx(txMeta, 'confTx: user updated transaction') + } + async updateAndApproveTransaction (txMeta) { this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction') await this.approveTransaction(txMeta.id) |