diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-03-02 02:04:25 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2017-03-02 02:04:25 +0800 |
commit | e66035254f1778ec8e614cabecaf1a9493509888 (patch) | |
tree | ab0ab43a9792075dfd2e1a23a95ea35a86d6d962 /app/scripts/controllers/preferences.js | |
parent | 0a3849ec8477b4a61c50d715bd72b3e8f1ea8b66 (diff) | |
parent | 6fb33853f2ceeb6ef48988a7ee9334dfc87a8223 (diff) | |
download | tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar.gz tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar.bz2 tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar.lz tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar.xz tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.tar.zst tangerine-wallet-browser-e66035254f1778ec8e614cabecaf1a9493509888.zip |
More conflict resolution.
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..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 |