diff options
author | Dan Finlay <flyswatter@users.noreply.github.com> | 2017-03-09 02:16:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-09 02:16:50 +0800 |
commit | 67c3126e63aa073d4426b751004c357ee7ed7d60 (patch) | |
tree | 815f163d7983225c56a165dd26b7bc33d96bdad1 /app/scripts/controllers/preferences.js | |
parent | 92b8443824bffca219b146028d5685e6aa1ffabf (diff) | |
parent | 26cac57838edc0783e42350d71c45d989329cf2a (diff) | |
download | tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.gz tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.bz2 tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.lz tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.xz tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.zst tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.zip |
Merge branch 'master' into kumavis-patch-1
Diffstat (limited to 'app/scripts/controllers/preferences.js')
-rw-r--r-- | app/scripts/controllers/preferences.js | 63 |
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 |