aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/keyring-controller.js
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-02-03 16:17:17 +0800
committerGitHub <noreply@github.com>2017-02-03 16:17:17 +0800
commit66be5ff2756e611c7af6973e704d27ce9bbd0d45 (patch)
tree43b5dcab6686e3db06218bfff17a943c72e6ddf3 /app/scripts/keyring-controller.js
parent270808c206934cf7d75fefcdd092c9595de45f29 (diff)
parent970d4fd69519bab1de972839190a4ede888914bb (diff)
downloadtangerine-wallet-browser-66be5ff2756e611c7af6973e704d27ce9bbd0d45.tar.gz
tangerine-wallet-browser-66be5ff2756e611c7af6973e704d27ce9bbd0d45.tar.zst
tangerine-wallet-browser-66be5ff2756e611c7af6973e704d27ce9bbd0d45.zip
Merge pull request #1083 from MetaMask/kumavis-refactor6
Refactor round 6
Diffstat (limited to 'app/scripts/keyring-controller.js')
-rw-r--r--app/scripts/keyring-controller.js39
1 files changed, 7 insertions, 32 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index d1d706165..348f81fc9 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -29,11 +29,11 @@ class KeyringController extends EventEmitter {
this.keyringTypes = keyringTypes
this.store = new ObservableStore(initState)
this.memStore = new ObservableStore({
+ isUnlocked: false,
keyringTypes: this.keyringTypes.map(krt => krt.type),
keyrings: [],
identities: {},
})
- this.configManager = opts.configManager
this.ethStore = opts.ethStore
this.encryptor = encryptor
this.keyrings = []
@@ -53,37 +53,7 @@ class KeyringController extends EventEmitter {
// Not all methods end with this, that might be a nice refactor.
fullUpdate () {
this.emit('update')
- return Promise.resolve(this.getState())
- }
-
- // Get State
- // returns @object state
- //
- // This method returns a hash representing the current state
- // that the keyringController manages.
- //
- // It is extended in the MetamaskController along with the EthStore
- // state, and its own state, to create the metamask state branch
- // that is passed to the UI.
- //
- // This is currently a rare example of a synchronously resolving method
- // in this class, but will need to be Promisified when we move our
- // persistence to an async model.
- getState () {
-
- // old wallet
- const memState = this.memStore.getState()
- const result = {
- // computed
- isUnlocked: (!!this.password),
- // memStore
- keyringTypes: memState.keyringTypes,
- identities: memState.identities,
- keyrings: memState.keyrings,
- // configManager
- seedWords: this.configManager.getSeedWords(),
- }
- return result
+ return Promise.resolve(this.memStore.getState())
}
// Create New Vault And Keychain
@@ -147,7 +117,10 @@ class KeyringController extends EventEmitter {
//
// This method deallocates all secrets, and effectively locks metamask.
setLocked () {
+ // set locked
this.password = null
+ this.memStore.updateState({ isUnlocked: false })
+ // remove keyrings
this.keyrings = []
this._updateMemStoreKeyrings()
return this.fullUpdate()
@@ -385,6 +358,7 @@ class KeyringController extends EventEmitter {
persistAllKeyrings (password = this.password) {
if (typeof password === 'string') {
this.password = password
+ this.memStore.updateState({ isUnlocked: true })
}
return Promise.all(this.keyrings.map((keyring) => {
return Promise.all([keyring.type, keyring.serialize()])
@@ -421,6 +395,7 @@ class KeyringController extends EventEmitter {
return this.encryptor.decrypt(password, encryptedVault)
.then((vault) => {
this.password = password
+ this.memStore.updateState({ isUnlocked: true })
vault.forEach(this.restoreKeyring.bind(this))
return this.keyrings
})