aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/keyring-controller.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-02-01 12:02:38 +0800
committerkumavis <aaron@kumavis.me>2017-02-01 12:02:38 +0800
commitc0d3db6a8ce2fe0522fa4e3cba1e01d10469280f (patch)
tree252d5235f19bd10800150bae2af4663249226628 /app/scripts/keyring-controller.js
parent82578538198de74955d7bc5cfd3c9a02d1b69a6d (diff)
downloadtangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar.gz
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar.bz2
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar.lz
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar.xz
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.tar.zst
tangerine-wallet-browser-c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f.zip
keyring - synchronous getState
Diffstat (limited to 'app/scripts/keyring-controller.js')
-rw-r--r--app/scripts/keyring-controller.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index f7a4e4010..3737d1b55 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -2,6 +2,7 @@ const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const bip39 = require('bip39')
const EventEmitter = require('events').EventEmitter
+const extend = require('xtend')
const ObservableStore = require('obs-store')
const filter = require('promise-filter')
const encryptor = require('browser-passworder')
@@ -32,6 +33,7 @@ class KeyringController extends EventEmitter {
super()
const initState = opts.initState || {}
this.store = new ObservableStore(initState)
+ this.memStore = new ObservableStore({})
this.configManager = opts.configManager
this.ethStore = opts.ethStore
this.encryptor = encryptor
@@ -74,30 +76,27 @@ class KeyringController extends EventEmitter {
// in this class, but will need to be Promisified when we move our
// persistence to an async model.
getState () {
- return Promise.all(this.keyrings.map(this.displayForKeyring))
- .then((displayKeyrings) => {
- const state = this.store.getState()
- // old wallet
- const wallet = this.configManager.getWallet()
- return {
- // computed
- isInitialized: (!!wallet || !!state.vault),
- isUnlocked: (!!this.password),
- keyrings: displayKeyrings,
- // hard coded
- keyringTypes: this.keyringTypes.map(krt => krt.type),
- // memStore
- identities: this.identities,
- // configManager
- seedWords: this.configManager.getSeedWords(),
- isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
- currentFiat: this.configManager.getCurrentFiat(),
- conversionRate: this.configManager.getConversionRate(),
- conversionDate: this.configManager.getConversionDate(),
- // messageManager
- unconfMsgs: messageManager.unconfirmedMsgs(),
- messages: messageManager.getMsgList(),
- }
+ const state = this.store.getState()
+ // old wallet
+ const wallet = this.configManager.getWallet()
+ const memState = this.memStore.getState()
+ return extend(memState, {
+ // computed
+ isInitialized: (!!wallet || !!state.vault),
+ isUnlocked: (!!this.password),
+ // hard coded
+ keyringTypes: this.keyringTypes.map(krt => krt.type),
+ // memStore
+ identities: this.identities,
+ // configManager
+ seedWords: this.configManager.getSeedWords(),
+ isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
+ currentFiat: this.configManager.getCurrentFiat(),
+ conversionRate: this.configManager.getConversionRate(),
+ conversionDate: this.configManager.getConversionDate(),
+ // messageManager
+ unconfMsgs: messageManager.unconfirmedMsgs(),
+ messages: messageManager.getMsgList(),
})
}
@@ -164,6 +163,7 @@ class KeyringController extends EventEmitter {
setLocked () {
this.password = null
this.keyrings = []
+ this._updateMemStoreKeyrings()
return this.fullUpdate()
}
@@ -639,6 +639,13 @@ class KeyringController extends EventEmitter {
this.identities = {}
}
+ _updateMemStoreKeyrings() {
+ Promise.all(this.keyrings.map(this.displayForKeyring))
+ .then((keyrings) => {
+ this.memStore.updateState({ keyrings })
+ })
+ }
+
}
module.exports = KeyringController