mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Make account tracking much more reactive
This commit is contained in:
parent
75177ce34c
commit
d89394a7c9
@ -41,19 +41,24 @@ class AccountTracker extends EventEmitter {
|
|||||||
syncWithAddresses (addresses) {
|
syncWithAddresses (addresses) {
|
||||||
const accounts = this.store.getState().accounts
|
const accounts = this.store.getState().accounts
|
||||||
const locals = Object.keys(accounts)
|
const locals = Object.keys(accounts)
|
||||||
.map(account => accounts[account.address])
|
|
||||||
|
|
||||||
|
const toAdd = []
|
||||||
addresses.forEach((upstream) => {
|
addresses.forEach((upstream) => {
|
||||||
if (!locals.includes(upstream)) {
|
if (!locals.includes(upstream)) {
|
||||||
this.addAccount(upstream)
|
toAdd.push(upstream)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const toRemove = []
|
||||||
locals.forEach((local) => {
|
locals.forEach((local) => {
|
||||||
if (!addresses.includes(local)) {
|
if (!addresses.includes(local)) {
|
||||||
this.removeAccount(local)
|
toRemove.push(local)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
toAdd.forEach(upstream => this.addAccount(upstream))
|
||||||
|
toRemove.forEach(local=> this.removeAccount(local))
|
||||||
|
this._updateAccounts()
|
||||||
}
|
}
|
||||||
|
|
||||||
addAccount (address) {
|
addAccount (address) {
|
||||||
|
@ -117,8 +117,10 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// If only one account exists, make sure it is selected.
|
// If only one account exists, make sure it is selected.
|
||||||
this.keyringController.store.subscribe((state) => {
|
this.keyringController.memStore.subscribe((state) => {
|
||||||
const addresses = Object.keys(state.walletNicknames || {})
|
const addresses = state.keyrings.reduce((res, keyring) => {
|
||||||
|
return res.concat(keyring.accounts)
|
||||||
|
}, [])
|
||||||
if (addresses.length === 1) {
|
if (addresses.length === 1) {
|
||||||
const address = addresses[0]
|
const address = addresses[0]
|
||||||
this.preferencesController.setSelectedAddress(address)
|
this.preferencesController.setSelectedAddress(address)
|
||||||
@ -314,7 +316,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
|
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
|
||||||
|
|
||||||
// vault management
|
// vault management
|
||||||
submitPassword: this.submitPassword.bind(this),
|
submitPassword: nodeify(keyringController.submitPassword, keyringController),
|
||||||
|
|
||||||
// network management
|
// network management
|
||||||
setProviderType: nodeify(networkController.setProviderType, networkController),
|
setProviderType: nodeify(networkController.setProviderType, networkController),
|
||||||
@ -470,12 +472,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
this.preferencesController.setSelectedAddress(address)
|
this.preferencesController.setSelectedAddress(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
submitPassword (password, cb) {
|
|
||||||
return this.keyringController.submitPassword(password)
|
|
||||||
.then((newState) => { cb(null, newState) })
|
|
||||||
.catch((reason) => { cb(reason) })
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Opinionated Keyring Management
|
// Opinionated Keyring Management
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user