aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/preferences.js
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/scripts/controllers/preferences.js
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/scripts/controllers/preferences.js')
-rw-r--r--app/scripts/controllers/preferences.js63
1 files changed, 63 insertions, 0 deletions
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