mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Got bad account detection working and added to state
This commit is contained in:
parent
ab9e15b782
commit
7b9749e30c
@ -623,16 +623,17 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
// may be completed without interruption.
|
||||
migrateOldVaultIfAny (password) {
|
||||
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
|
||||
if (!shouldMigrate) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return this.idStoreMigrator.migratedVaultForPassword(password)
|
||||
.then((result) => {
|
||||
console.log('migrator called back with')
|
||||
console.dir(result)
|
||||
const { serialized, lostAccounts } = result
|
||||
console.dir({ serialized, lostAccounts })
|
||||
this.configManager.setLostAccounts(lostAccounts)
|
||||
this.password = password
|
||||
|
||||
if (serialized && shouldMigrate) {
|
||||
if (result && shouldMigrate) {
|
||||
const { serialized, lostAccounts } = result
|
||||
this.configManager.setLostAccounts(lostAccounts)
|
||||
return this.restoreKeyring(serialized)
|
||||
.then(keyring => keyring.getAccounts())
|
||||
.then((accounts) => {
|
||||
|
@ -38,7 +38,6 @@ class HdKeyring extends EventEmitter {
|
||||
}
|
||||
|
||||
if ('numberOfAccounts' in opts) {
|
||||
console.log('number of accounts detected, adding accounts.')
|
||||
return this.addAccounts(opts.numberOfAccounts)
|
||||
}
|
||||
|
||||
@ -49,7 +48,6 @@ class HdKeyring extends EventEmitter {
|
||||
if (!this.root) {
|
||||
this._initFromMnemonic(bip39.generateMnemonic())
|
||||
}
|
||||
console.log('attempting to add %s accounts', numberOfAccounts)
|
||||
|
||||
const oldLen = this.wallets.length
|
||||
const newWallets = []
|
||||
@ -59,9 +57,7 @@ class HdKeyring extends EventEmitter {
|
||||
newWallets.push(wallet)
|
||||
this.wallets.push(wallet)
|
||||
}
|
||||
console.log('hd has %s wallets', this.wallets.length)
|
||||
const hexWallets = newWallets.map(w => w.getAddress().toString('hex'))
|
||||
console.log('hd calling back w promise of hex wallets ' + hexWallets)
|
||||
return Promise.resolve(hexWallets)
|
||||
}
|
||||
|
||||
|
@ -14,31 +14,21 @@ module.exports = class IdentityStoreMigrator {
|
||||
}
|
||||
|
||||
migratedVaultForPassword (password) {
|
||||
console.log('migrating vault for password')
|
||||
const hasOldVault = this.hasOldVault()
|
||||
const configManager = this.configManager
|
||||
|
||||
if (!this.idStore) {
|
||||
console.log('initializing id store')
|
||||
this.idStore = new IdentityStore({ configManager })
|
||||
console.log('initialized')
|
||||
}
|
||||
|
||||
if (!hasOldVault) {
|
||||
console.log('no old vault recognized')
|
||||
return Promise.resolve(null)
|
||||
}
|
||||
|
||||
console.log('returning new promise')
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('submitting password to idStore')
|
||||
this.idStore.submitPassword(password, (err) => {
|
||||
console.log('returned ' + err)
|
||||
if (err) return reject(err)
|
||||
console.log('serializing vault')
|
||||
const serialized = this.serializeVault()
|
||||
console.log('migrated and serialized into')
|
||||
console.dir(serialized)
|
||||
this.checkForErrors(serialized)
|
||||
.then(resolve)
|
||||
.catch(reject)
|
||||
@ -57,16 +47,9 @@ module.exports = class IdentityStoreMigrator {
|
||||
}
|
||||
|
||||
checkForErrors (serialized) {
|
||||
console.log('checking for errors, first making hd wallet')
|
||||
const hd = new HdKeyring()
|
||||
return hd.deserialize(serialized)
|
||||
.then(() => {
|
||||
console.log('deserialized, now getting accounts')
|
||||
console.dir(arguments)
|
||||
return hd.getAccounts()
|
||||
})
|
||||
return hd.deserialize(serialized.data)
|
||||
.then((hexAccounts) => {
|
||||
console.log('hd returned accounts', hexAccounts)
|
||||
const newAccounts = hexAccounts.map(normalize)
|
||||
const oldAccounts = this.idStore._getAddresses().map(normalize)
|
||||
const lostAccounts = oldAccounts.reduce((result, account) => {
|
||||
@ -78,9 +61,6 @@ module.exports = class IdentityStoreMigrator {
|
||||
}
|
||||
}, [])
|
||||
|
||||
console.log('migrator has')
|
||||
console.dir({ newAccounts, oldAccounts, lostAccounts, hexAccounts })
|
||||
|
||||
return {
|
||||
serialized,
|
||||
lostAccounts,
|
||||
|
@ -8,6 +8,8 @@ var STORAGE_KEY = 'metamask-config'
|
||||
var PASSWORD = '12345678'
|
||||
var FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase()
|
||||
|
||||
var BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9'
|
||||
|
||||
|
||||
QUnit.module('Old Style Vaults', {
|
||||
beforeEach: function () {
|
||||
@ -87,7 +89,7 @@ QUnit.module('Old Style Vaults with bad HD seed', {
|
||||
})
|
||||
|
||||
QUnit.test('keyringController:isInitialized', function (assert) {
|
||||
assert.ok(this.keyringController.getState().isInitialized)
|
||||
assert.ok(this.keyringController.getState().isInitialized, 'vault is initialized')
|
||||
})
|
||||
|
||||
QUnit.test('keyringController:submitPassword', function (assert) {
|
||||
@ -95,9 +97,9 @@ QUnit.test('keyringController:submitPassword', function (assert) {
|
||||
|
||||
this.keyringController.submitPassword(PASSWORD)
|
||||
.then((state) => {
|
||||
assert.ok(state.identities[FIRST_ADDRESS])
|
||||
assert.ok(state.identities[BAD_STYLE_FIRST_ADDRESS])
|
||||
assert.equal(state.lostAccounts.length, 1, 'one lost account')
|
||||
assert.equal(state.lostAccounts[0], 'e15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase())
|
||||
assert.equal(state.lostAccounts[0], '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase())
|
||||
assert.deepEqual(this.configManager.getLostAccounts(), state.lostAccounts, 'persisted')
|
||||
done()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user