diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/controllers/currency.js (renamed from app/scripts/lib/controllers/currency.js) | 0 | ||||
-rw-r--r-- | app/scripts/controllers/preferences.js | 63 | ||||
-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.js | 33 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 7 |
5 files changed, 67 insertions, 36 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..8fd5fb8a0 --- /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 rpcList + }) + } + + 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..f6dbf899d 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') @@ -265,6 +265,7 @@ module.exports = class MetamaskController extends EventEmitter { // PreferencesController setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), + updateFrequentRpcList: nodeify(preferencesController.updateFrequentRpcList).bind(preferencesController), // KeyringController setLocked: nodeify(keyringController.setLocked).bind(keyringController), |