aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-03-09 02:07:15 +0800
committerGitHub <noreply@github.com>2017-03-09 02:07:15 +0800
commit26cac57838edc0783e42350d71c45d989329cf2a (patch)
tree42c6db90a39fb691f26ec8443bd18114ee7cff4d /app
parentde5a30c5ff3acbcda7a46a3caba70a622308dbb2 (diff)
parent6fd3d6e0d0887ac01760b436be5dfabc89e28960 (diff)
downloadtangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar.gz
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar.bz2
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar.lz
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar.xz
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.tar.zst
tangerine-wallet-browser-26cac57838edc0783e42350d71c45d989329cf2a.zip
Merge pull request #1147 from MetaMask/i1144-moarrpc
Save recently used RPCs
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/currency.js (renamed from app/scripts/lib/controllers/currency.js)0
-rw-r--r--app/scripts/controllers/preferences.js63
-rw-r--r--app/scripts/controllers/shapeshift.js (renamed from app/scripts/lib/controllers/shapeshift.js)0
-rw-r--r--app/scripts/lib/controllers/preferences.js33
-rw-r--r--app/scripts/metamask-controller.js24
5 files changed, 81 insertions, 39 deletions
diff --git a/app/scripts/lib/controllers/currency.js b/app/scripts/controllers/currency.js
index c4904f8ac..c4904f8ac 100644
--- a/app/scripts/lib/controllers/currency.js
+++ b/app/scripts/controllers/currency.js
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
new file mode 100644
index 000000000..18fccf11b
--- /dev/null
+++ b/app/scripts/controllers/preferences.js
@@ -0,0 +1,63 @@
+const ObservableStore = require('obs-store')
+const normalizeAddress = require('eth-sig-util').normalize
+const extend = require('xtend')
+
+class PreferencesController {
+
+ constructor (opts = {}) {
+ const initState = extend({ frequentRpcList: [] }, opts.initState)
+ this.store = new ObservableStore(initState)
+ }
+
+ //
+ // PUBLIC METHODS
+ //
+
+ setSelectedAddress (_address) {
+ return new Promise((resolve, reject) => {
+ const address = normalizeAddress(_address)
+ this.store.updateState({ selectedAddress: address })
+ resolve()
+ })
+ }
+
+ getSelectedAddress (_address) {
+ return this.store.getState().selectedAddress
+ }
+
+ updateFrequentRpcList (_url) {
+ return this.addToFrequentRpcList(_url)
+ .then((rpcList) => {
+ this.store.updateState({ frequentRpcList: rpcList })
+ return Promise.resolve()
+ })
+ }
+
+ addToFrequentRpcList (_url) {
+ let rpcList = this.getFrequentRpcList()
+ let index = rpcList.findIndex((element) => { return element === _url })
+ if (index !== -1) {
+ rpcList.splice(index, 1)
+ }
+ if (_url !== 'http://localhost:8545') {
+ rpcList.push(_url)
+ }
+ if (rpcList.length > 2) {
+ rpcList.shift()
+ }
+ return Promise.resolve(rpcList)
+ }
+
+ getFrequentRpcList () {
+ return this.store.getState().frequentRpcList
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+
+
+}
+
+module.exports = PreferencesController
diff --git a/app/scripts/lib/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js
index 3d955c01f..3d955c01f 100644
--- a/app/scripts/lib/controllers/shapeshift.js
+++ b/app/scripts/controllers/shapeshift.js
diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js
deleted file mode 100644
index c5e93a5b9..000000000
--- a/app/scripts/lib/controllers/preferences.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const ObservableStore = require('obs-store')
-const normalizeAddress = require('eth-sig-util').normalize
-
-class PreferencesController {
-
- constructor (opts = {}) {
- const initState = opts.initState || {}
- this.store = new ObservableStore(initState)
- }
-
- //
- // PUBLIC METHODS
- //
-
- setSelectedAddress(_address) {
- return new Promise((resolve, reject) => {
- const address = normalizeAddress(_address)
- this.store.updateState({ selectedAddress: address })
- resolve()
- })
- }
-
- getSelectedAddress(_address) {
- return this.store.getState().selectedAddress
- }
-
- //
- // PRIVATE METHODS
- //
-
-}
-
-module.exports = PreferencesController
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 3dddf7065..536891dc6 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -11,10 +11,10 @@ const streamIntoProvider = require('web3-stream-provider/handler')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const KeyringController = require('./keyring-controller')
-const PreferencesController = require('./lib/controllers/preferences')
-const CurrencyController = require('./lib/controllers/currency')
+const PreferencesController = require('./controllers/preferences')
+const CurrencyController = require('./controllers/currency')
const NoticeController = require('./notice-controller')
-const ShapeShiftController = require('./lib/controllers/shapeshift')
+const ShapeShiftController = require('./controllers/shapeshift')
const MessageManager = require('./lib/message-manager')
const PersonalMessageManager = require('./lib/personal-message-manager')
const TxManager = require('./transaction-manager')
@@ -244,7 +244,6 @@ module.exports = class MetamaskController extends EventEmitter {
return {
// etc
getState: (cb) => cb(null, this.getState()),
- setRpcTarget: this.setRpcTarget.bind(this),
setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this),
setCurrentCurrency: this.setCurrentCurrency.bind(this),
@@ -265,6 +264,8 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
+ setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
+ setCustomRpc: nodeify(this.setCustomRpc).bind(this),
// KeyringController
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
@@ -661,10 +662,21 @@ module.exports = class MetamaskController extends EventEmitter {
if (this.isNetworkLoading()) this.lookupNetwork()
}
- setRpcTarget (rpcTarget) {
- this.configManager.setRpcTarget(rpcTarget)
+ setDefaultRpc () {
+ this.configManager.setRpcTarget('http://localhost:8545')
extension.runtime.reload()
this.lookupNetwork()
+ return Promise.resolve('http://localhost:8545')
+ }
+
+ setCustomRpc (rpcTarget, rpcList) {
+ this.configManager.setRpcTarget(rpcTarget)
+ return this.preferencesController.updateFrequentRpcList(rpcTarget)
+ .then(() => {
+ extension.runtime.reload()
+ this.lookupNetwork()
+ return Promise.resolve(rpcTarget)
+ })
}
setProviderType (type) {