1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

keyring - manage isUnlocked in memStore

This commit is contained in:
kumavis 2017-02-02 16:59:15 -08:00
parent 5c5aa6ea01
commit 134a4c7bc3

View File

@ -29,6 +29,7 @@ class KeyringController extends EventEmitter {
this.keyringTypes = keyringTypes this.keyringTypes = keyringTypes
this.store = new ObservableStore(initState) this.store = new ObservableStore(initState)
this.memStore = new ObservableStore({ this.memStore = new ObservableStore({
isUnlocked: false,
keyringTypes: this.keyringTypes.map(krt => krt.type), keyringTypes: this.keyringTypes.map(krt => krt.type),
keyrings: [], keyrings: [],
identities: {}, identities: {},
@ -74,7 +75,7 @@ class KeyringController extends EventEmitter {
const memState = this.memStore.getState() const memState = this.memStore.getState()
const result = { const result = {
// computed // computed
isUnlocked: (!!this.password), isUnlocked: memState.isUnlocked,
// memStore // memStore
keyringTypes: memState.keyringTypes, keyringTypes: memState.keyringTypes,
identities: memState.identities, identities: memState.identities,
@ -144,7 +145,10 @@ class KeyringController extends EventEmitter {
// //
// This method deallocates all secrets, and effectively locks metamask. // This method deallocates all secrets, and effectively locks metamask.
setLocked () { setLocked () {
// set locked
this.password = null this.password = null
this.memStore.updateState({ isUnlocked: false })
// remove keyrings
this.keyrings = [] this.keyrings = []
this._updateMemStoreKeyrings() this._updateMemStoreKeyrings()
return this.fullUpdate() return this.fullUpdate()
@ -382,6 +386,7 @@ class KeyringController extends EventEmitter {
persistAllKeyrings (password = this.password) { persistAllKeyrings (password = this.password) {
if (typeof password === 'string') { if (typeof password === 'string') {
this.password = password this.password = password
this.memStore.updateState({ isUnlocked: true })
} }
return Promise.all(this.keyrings.map((keyring) => { return Promise.all(this.keyrings.map((keyring) => {
return Promise.all([keyring.type, keyring.serialize()]) return Promise.all([keyring.type, keyring.serialize()])
@ -418,6 +423,7 @@ class KeyringController extends EventEmitter {
return this.encryptor.decrypt(password, encryptedVault) return this.encryptor.decrypt(password, encryptedVault)
.then((vault) => { .then((vault) => {
this.password = password this.password = password
this.memStore.updateState({ isUnlocked: true })
vault.forEach(this.restoreKeyring.bind(this)) vault.forEach(this.restoreKeyring.bind(this))
return this.keyrings return this.keyrings
}) })