mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
keyring - move identities into memStore
This commit is contained in:
parent
41c93ceb7e
commit
cd5d952600
@ -34,14 +34,14 @@ 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({
|
||||||
keyrings: [],
|
|
||||||
keyringTypes: this.keyringTypes.map(krt => krt.type),
|
keyringTypes: this.keyringTypes.map(krt => krt.type),
|
||||||
|
keyrings: [],
|
||||||
|
identities: {},
|
||||||
})
|
})
|
||||||
this.configManager = opts.configManager
|
this.configManager = opts.configManager
|
||||||
this.ethStore = opts.ethStore
|
this.ethStore = opts.ethStore
|
||||||
this.encryptor = encryptor
|
this.encryptor = encryptor
|
||||||
this.keyrings = []
|
this.keyrings = []
|
||||||
this.identities = {} // Essentially a name hash
|
|
||||||
|
|
||||||
this._unconfMsgCbs = {}
|
this._unconfMsgCbs = {}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ class KeyringController extends EventEmitter {
|
|||||||
isUnlocked: (!!this.password),
|
isUnlocked: (!!this.password),
|
||||||
// memStore
|
// memStore
|
||||||
keyringTypes: memState.keyringTypes,
|
keyringTypes: memState.keyringTypes,
|
||||||
identities: this.identities,
|
identities: memState.identities,
|
||||||
keyrings: memState.keyrings,
|
keyrings: memState.keyrings,
|
||||||
// messageManager
|
// messageManager
|
||||||
unconfMsgs: messageManager.unconfirmedMsgs(),
|
unconfMsgs: messageManager.unconfirmedMsgs(),
|
||||||
@ -245,7 +245,9 @@ class KeyringController extends EventEmitter {
|
|||||||
walletNicknames[hexAddress] = label
|
walletNicknames[hexAddress] = label
|
||||||
this.store.updateState({ walletNicknames })
|
this.store.updateState({ walletNicknames })
|
||||||
// update state on memStore
|
// update state on memStore
|
||||||
this.identities[hexAddress].name = label
|
const identities = this.memStore.getState().identities
|
||||||
|
identities[hexAddress].name = label
|
||||||
|
this.memStore.updateState({ identities })
|
||||||
return Promise.resolve(label)
|
return Promise.resolve(label)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
@ -439,14 +441,16 @@ class KeyringController extends EventEmitter {
|
|||||||
// Takes an address, and assigns it an incremented nickname, persisting it.
|
// Takes an address, and assigns it an incremented nickname, persisting it.
|
||||||
createNickname (address) {
|
createNickname (address) {
|
||||||
const hexAddress = normalizeAddress(address)
|
const hexAddress = normalizeAddress(address)
|
||||||
const currentIdentityCount = Object.keys(this.identities).length + 1
|
const identities = this.memStore.getState().identities
|
||||||
|
const currentIdentityCount = Object.keys(identities).length + 1
|
||||||
const nicknames = this.store.getState().walletNicknames || {}
|
const nicknames = this.store.getState().walletNicknames || {}
|
||||||
const existingNickname = nicknames[hexAddress]
|
const existingNickname = nicknames[hexAddress]
|
||||||
const name = existingNickname || `Account ${currentIdentityCount}`
|
const name = existingNickname || `Account ${currentIdentityCount}`
|
||||||
this.identities[hexAddress] = {
|
identities[hexAddress] = {
|
||||||
address: hexAddress,
|
address: hexAddress,
|
||||||
name,
|
name,
|
||||||
}
|
}
|
||||||
|
this.memStore.updateState({ identities })
|
||||||
return this.saveAccountLabel(hexAddress, name)
|
return this.saveAccountLabel(hexAddress, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,8 +639,12 @@ class KeyringController extends EventEmitter {
|
|||||||
this.ethStore.removeAccount(address)
|
this.ethStore.removeAccount(address)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// clear keyrings from memory
|
||||||
this.keyrings = []
|
this.keyrings = []
|
||||||
this.identities = {}
|
this.memStore.updateState({
|
||||||
|
keyrings: [],
|
||||||
|
identities: {},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateMemStoreKeyrings() {
|
_updateMemStoreKeyrings() {
|
||||||
|
@ -104,7 +104,7 @@ describe('KeyringController', function() {
|
|||||||
it('should add the address to the identities hash', function() {
|
it('should add the address to the identities hash', function() {
|
||||||
const fakeAddress = '0x12345678'
|
const fakeAddress = '0x12345678'
|
||||||
keyringController.createNickname(fakeAddress)
|
keyringController.createNickname(fakeAddress)
|
||||||
const identities = keyringController.identities
|
const identities = keyringController.memStore.getState().identities
|
||||||
const identity = identities[fakeAddress]
|
const identity = identities[fakeAddress]
|
||||||
assert.equal(identity.address, fakeAddress)
|
assert.equal(identity.address, fakeAddress)
|
||||||
})
|
})
|
||||||
@ -114,7 +114,9 @@ describe('KeyringController', function() {
|
|||||||
it ('sets the nickname', function(done) {
|
it ('sets the nickname', function(done) {
|
||||||
const account = addresses[0]
|
const account = addresses[0]
|
||||||
var nick = 'Test nickname'
|
var nick = 'Test nickname'
|
||||||
keyringController.identities[ethUtil.addHexPrefix(account)] = {}
|
const identities = keyringController.memStore.getState().identities
|
||||||
|
identities[ethUtil.addHexPrefix(account)] = {}
|
||||||
|
keyringController.memStore.updateState({ identities })
|
||||||
keyringController.saveAccountLabel(account, nick)
|
keyringController.saveAccountLabel(account, nick)
|
||||||
.then((label) => {
|
.then((label) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user