diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-02-22 04:32:13 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2017-02-22 04:32:13 +0800 |
commit | db48f8984f8e16b2831aab36cd538d241cb41402 (patch) | |
tree | 43e557683cf2d7e162d0b823d927905049f36c0e /app/scripts | |
parent | 09c7b9d242f66db99c80f22fae00dfdb894e2adc (diff) | |
download | tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar.gz tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar.bz2 tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar.lz tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar.xz tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.tar.zst tangerine-wallet-browser-db48f8984f8e16b2831aab36cd538d241cb41402.zip |
Basic infrasture for RPC list added.
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/lib/controllers/preferences.js | 26 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 1 |
2 files changed, 24 insertions, 3 deletions
diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js index dc9464c4e..2d5a1addd 100644 --- a/app/scripts/lib/controllers/preferences.js +++ b/app/scripts/lib/controllers/preferences.js @@ -4,7 +4,7 @@ const normalizeAddress = require('../sig-util').normalize class PreferencesController { constructor (opts = {}) { - const initState = opts.initState || {} + const initState = opts.initState || { frequentRPCList: [] } this.store = new ObservableStore(initState) } @@ -12,7 +12,7 @@ class PreferencesController { // PUBLIC METHODS // - setSelectedAddress(_address) { + setSelectedAddress (_address) { return new Promise((resolve, reject) => { const address = normalizeAddress(_address) this.store.updateState({ selectedAddress: address }) @@ -20,10 +20,30 @@ class PreferencesController { }) } - getSelectedAddress(_address) { + getSelectedAddress (_address) { return this.store.getState().selectedAddress } + addToFrequentRPCList (_url) { + return new Promise((resolve, reject) => { + let rpcList = this.getFrequentRPCList() + let index = rpcList.findIndex((element) => { element === _url }) + if (index) { + rpcList.splice(index, 1) + } + if (rpcList.length >= 3) { + rpcList.shift() + } + rpcList.push(_url) + this.store.updateState({ frequentRPCList: rpcList }) + resolve() + }) + } + + getFrequentRPCList () { + return this.store.getState().frequentRPCList + } + // // PRIVATE METHODS // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 29b13dc62..54c2ebb2c 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -259,6 +259,7 @@ module.exports = class MetamaskController extends EventEmitter { // PreferencesController setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), + setFrequentRPCList: nodeify(preferencesController.setFrequentRPCList).bind(preferencesController), // KeyringController setLocked: nodeify(keyringController.setLocked).bind(keyringController), |