diff options
Diffstat (limited to 'app')
-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), |