diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-01-31 07:57:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-31 07:57:49 +0800 |
commit | 82578538198de74955d7bc5cfd3c9a02d1b69a6d (patch) | |
tree | aad1a62ee4ed4b7e34c0bd78b9f680dc2aeaaded /app/scripts/lib | |
parent | b6909574a7036c396ed85809cbd90aa2171b012f (diff) | |
parent | 0b9d37c6c8e714eb26bec5156e984a6b0cd268ad (diff) | |
download | tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar.gz tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar.bz2 tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar.lz tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar.xz tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.tar.zst tangerine-wallet-browser-82578538198de74955d7bc5cfd3c9a02d1b69a6d.zip |
Merge pull request #1069 from MetaMask/i1066
Introduce Preferences Controller
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/controllers/preferences.js | 33 | ||||
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 10 |
2 files changed, 38 insertions, 5 deletions
diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js new file mode 100644 index 000000000..dc9464c4e --- /dev/null +++ b/app/scripts/lib/controllers/preferences.js @@ -0,0 +1,33 @@ +const ObservableStore = require('obs-store') +const normalizeAddress = require('../sig-util').normalize + +class PreferencesController { + + constructor (opts = {}) { + const initState = 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 + } + + // + // PRIVATE METHODS + // + +} + +module.exports = PreferencesController diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 066916b4d..faecac137 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -63,20 +63,20 @@ function MetamaskInpageProvider (connectionStream) { MetamaskInpageProvider.prototype.send = function (payload) { const self = this - let selectedAccount + let selectedAddress let result = null switch (payload.method) { case 'eth_accounts': // read from localStorage - selectedAccount = self.publicConfigStore.getState().selectedAccount - result = selectedAccount ? [selectedAccount] : [] + selectedAddress = self.publicConfigStore.getState().selectedAddress + result = selectedAddress ? [selectedAddress] : [] break case 'eth_coinbase': // read from localStorage - selectedAccount = self.publicConfigStore.getState().selectedAccount - result = selectedAccount || '0x0000000000000000000000000000000000000000' + selectedAddress = self.publicConfigStore.getState().selectedAddress + result = selectedAddress break case 'eth_uninstallFilter': |