mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add identity synchronizing code
Addresses #4475, where entries in the identities object do not necessarily have corresponding accounts in the vault. On password submission, this change passes known accounts to the preferencesController (responsible for nickname management), and removes unknown entries. Includes "TODO" notes for where we could log the issue to sentry or notify the user.
This commit is contained in:
parent
797e63b37b
commit
7382bd0847
@ -98,6 +98,37 @@ class PreferencesController {
|
||||
this.store.updateState({ identities })
|
||||
}
|
||||
|
||||
/*
|
||||
* Synchronizes identity entries with known accounts.
|
||||
* Removes any unknown identities, and returns the resulting selected address.
|
||||
*
|
||||
* @param {Array<string>} addresses known to the vault.
|
||||
* @returns {Promise<string>} selectedAddress the selected address.
|
||||
*/
|
||||
syncAddresses (addresses) {
|
||||
const identities = this.store.getState().identities
|
||||
|
||||
Object.keys(identities).forEach((identity) => {
|
||||
if (!addresses.includes(identity)) {
|
||||
delete identities[identity]
|
||||
|
||||
// TODO: Report the bug to Sentry including the now-lost identity.
|
||||
// TODO: Inform the user of the lost identity.
|
||||
}
|
||||
})
|
||||
|
||||
this.store.updateState({ identities })
|
||||
this.addAddresses(addresses)
|
||||
|
||||
let selected = this.getSelectedAddress()
|
||||
if (!addresses.includes(selected)) {
|
||||
selected = addresses[0]
|
||||
this.setSelectedAddress(selected)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the `selectedAddress` property
|
||||
*
|
||||
|
@ -356,7 +356,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
|
||||
|
||||
// vault management
|
||||
submitPassword: nodeify(keyringController.submitPassword, keyringController),
|
||||
submitPassword: nodeify(this.submitPassword, this),
|
||||
|
||||
// network management
|
||||
setProviderType: nodeify(networkController.setProviderType, networkController),
|
||||
@ -474,6 +474,22 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Submits the user's password and attempts to unlock the vault.
|
||||
* Also synchronizes the preferencesController, to ensure its schema
|
||||
* is up to date with known accounts once the vault is decrypted.
|
||||
*
|
||||
* @param {string} password - The user's password
|
||||
* @returns {Promise<object>} - The keyringController update.
|
||||
*/
|
||||
async submitPassword (password) {
|
||||
await this.keyringController.submitPassword(password)
|
||||
const accounts = await this.keyringController.getAccounts()
|
||||
|
||||
await this.preferencesController.syncAddresses(accounts)
|
||||
return this.keyringController.fullUpdate()
|
||||
}
|
||||
|
||||
/**
|
||||
* @type Identity
|
||||
* @property {string} name - The account nickname.
|
||||
|
Loading…
Reference in New Issue
Block a user