mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update unlock logic to not overwrite existing selected address
This commit is contained in:
parent
1e8e8bdfc8
commit
003d445a98
@ -137,19 +137,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
encryptor: opts.encryptor || undefined,
|
encryptor: opts.encryptor || undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
// If only one account exists, make sure it is selected.
|
this.keyringController.memStore.subscribe((s) => this._onKeyringControllerUpdate(s))
|
||||||
this.keyringController.memStore.subscribe((state) => {
|
|
||||||
const addresses = state.keyrings.reduce((res, keyring) => {
|
|
||||||
return res.concat(keyring.accounts)
|
|
||||||
}, [])
|
|
||||||
if (addresses.length === 1) {
|
|
||||||
const address = addresses[0]
|
|
||||||
this.preferencesController.setSelectedAddress(address)
|
|
||||||
}
|
|
||||||
// ensure preferences + identities controller know about all addresses
|
|
||||||
this.preferencesController.addAddresses(addresses)
|
|
||||||
this.accountTracker.syncWithAddresses(addresses)
|
|
||||||
})
|
|
||||||
|
|
||||||
// detect tokens controller
|
// detect tokens controller
|
||||||
this.detectTokensController = new DetectTokensController({
|
this.detectTokensController = new DetectTokensController({
|
||||||
@ -1278,6 +1266,34 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a KeyringController update
|
||||||
|
* @param {object} state the KC state
|
||||||
|
* @return {Promise<void>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
async _onKeyringControllerUpdate (state) {
|
||||||
|
const {isUnlocked, keyrings} = state
|
||||||
|
const addresses = keyrings.reduce((acc, {accounts}) => acc.concat(accounts), [])
|
||||||
|
|
||||||
|
if (!addresses.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure preferences + identities controller know about all addresses
|
||||||
|
this.preferencesController.addAddresses(addresses)
|
||||||
|
this.accountTracker.syncWithAddresses(addresses)
|
||||||
|
|
||||||
|
const wasLocked = !isUnlocked
|
||||||
|
if (wasLocked) {
|
||||||
|
const oldSelectedAddress = this.preferencesController.getSelectedAddress()
|
||||||
|
if (!addresses.includes(oldSelectedAddress)) {
|
||||||
|
const address = addresses[0]
|
||||||
|
await this.preferencesController.setSelectedAddress(address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method for emitting the full MetaMask state to all registered listeners.
|
* A method for emitting the full MetaMask state to all registered listeners.
|
||||||
* @private
|
* @private
|
||||||
|
Loading…
Reference in New Issue
Block a user