commit
58b9afff4f
@ -0,0 +1,47 @@ |
||||
const version = 26 |
||||
|
||||
/* |
||||
|
||||
This migration moves the identities stored in the KeyringController |
||||
into the PreferencesController |
||||
|
||||
*/ |
||||
|
||||
const clone = require('clone') |
||||
|
||||
module.exports = { |
||||
version, |
||||
migrate (originalVersionedData) { |
||||
const versionedData = clone(originalVersionedData) |
||||
versionedData.meta.version = version |
||||
try { |
||||
const state = versionedData.data |
||||
versionedData.data = transformState(state) |
||||
} catch (err) { |
||||
console.warn(`MetaMask Migration #${version}` + err.stack) |
||||
return Promise.reject(err) |
||||
} |
||||
return Promise.resolve(versionedData) |
||||
}, |
||||
} |
||||
|
||||
function transformState (state) { |
||||
if (!state.KeyringController || !state.PreferencesController) { |
||||
return |
||||
} |
||||
|
||||
if (!state.KeyringController.walletNicknames) { |
||||
return state |
||||
} |
||||
|
||||
state.PreferencesController.identities = Object.keys(state.KeyringController.walletNicknames) |
||||
.reduce((identities, address) => { |
||||
identities[address] = { |
||||
name: state.KeyringController.walletNicknames[address], |
||||
address, |
||||
} |
||||
return identities |
||||
}, {}) |
||||
delete state.KeyringController.walletNicknames |
||||
return state |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,35 +0,0 @@ |
||||
// var jsdom = require('mocha-jsdom')
|
||||
var assert = require('assert') |
||||
var freeze = require('deep-freeze-strict') |
||||
var path = require('path') |
||||
|
||||
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) |
||||
var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) |
||||
|
||||
describe('SAVE_ACCOUNT_LABEL', function () { |
||||
it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () { |
||||
var initialState = { |
||||
metamask: { |
||||
identities: { |
||||
foo: { |
||||
name: 'bar', |
||||
}, |
||||
}, |
||||
}, |
||||
} |
||||
freeze(initialState) |
||||
|
||||
const action = { |
||||
type: actions.SAVE_ACCOUNT_LABEL, |
||||
value: { |
||||
account: 'foo', |
||||
label: 'baz', |
||||
}, |
||||
} |
||||
freeze(action) |
||||
|
||||
var resultingState = reducers(initialState, action) |
||||
assert.equal(resultingState.metamask.identities.foo.name, action.value.label) |
||||
}) |
||||
}) |
||||
|
@ -0,0 +1,34 @@ |
||||
const assert = require('assert') |
||||
const freeze = require('deep-freeze-strict') |
||||
const path = require('path') |
||||
|
||||
const actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) |
||||
const reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) |
||||
|
||||
describe('SET_ACCOUNT_LABEL', function () { |
||||
it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () { |
||||
const initialState = { |
||||
metamask: { |
||||
identities: { |
||||
foo: { |
||||
name: 'bar', |
||||
}, |
||||
}, |
||||
}, |
||||
} |
||||
freeze(initialState) |
||||
|
||||
const action = { |
||||
type: actions.SET_ACCOUNT_LABEL, |
||||
value: { |
||||
account: 'foo', |
||||
label: 'baz', |
||||
}, |
||||
} |
||||
freeze(action) |
||||
|
||||
const resultingState = reducers(initialState, action) |
||||
assert.equal(resultingState.metamask.identities.foo.name, action.value.label) |
||||
}) |
||||
}) |
||||
|
@ -0,0 +1,41 @@ |
||||
const assert = require('assert') |
||||
const migration26 = require('../../../app/scripts/migrations/026') |
||||
const oldStorage = { |
||||
'meta': {'version': 25}, |
||||
'data': { |
||||
'PreferencesController': {}, |
||||
'KeyringController': { |
||||
'walletNicknames': { |
||||
'0x1e77e2': 'Test Account 1', |
||||
'0x7e57e2': 'Test Account 2', |
||||
}, |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
describe('migration #26', () => { |
||||
it('should move the identities from KeyringController', (done) => { |
||||
migration26.migrate(oldStorage) |
||||
.then((newStorage) => { |
||||
const identities = newStorage.data.PreferencesController.identities |
||||
assert.deepEqual(identities, { |
||||
'0x1e77e2': {name: 'Test Account 1', address: '0x1e77e2'}, |
||||
'0x7e57e2': {name: 'Test Account 2', address: '0x7e57e2'}, |
||||
}) |
||||
assert.strictEqual(newStorage.data.KeyringController.walletNicknames, undefined) |
||||
done() |
||||
}) |
||||
.catch(done) |
||||
}) |
||||
|
||||
it('should successfully migrate first time state', (done) => { |
||||
migration26.migrate({ |
||||
meta: {}, |
||||
data: require('../../../app/scripts/first-time-state'), |
||||
}) |
||||
.then((migratedData) => { |
||||
assert.equal(migratedData.meta.version, migration26.version) |
||||
done() |
||||
}).catch(done) |
||||
}) |
||||
}) |
Loading…
Reference in new issue