From 2d13fac476cfbb7b0140611dca00fa95ee8d91ab Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 19 Apr 2018 01:03:51 -0230 Subject: Add migration to move identities from KeyringController --- app/scripts/migrations/026.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/scripts/migrations/026.js (limited to 'app/scripts/migrations/026.js') diff --git a/app/scripts/migrations/026.js b/app/scripts/migrations/026.js new file mode 100644 index 000000000..ef0ed0542 --- /dev/null +++ b/app/scripts/migrations/026.js @@ -0,0 +1,40 @@ +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 = state.KeyringController.walletNicknames + delete state.KeyringController.walletNicknames + return state +} -- cgit From 67310e151ea75c7aa4fc00bfd63bf41cd4f2db51 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 17 May 2018 13:35:38 -0230 Subject: Fix migration 026 to produce the correct shape for state.identities --- app/scripts/migrations/026.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/scripts/migrations/026.js') diff --git a/app/scripts/migrations/026.js b/app/scripts/migrations/026.js index ef0ed0542..1b8a91a45 100644 --- a/app/scripts/migrations/026.js +++ b/app/scripts/migrations/026.js @@ -34,7 +34,14 @@ function transformState (state) { return state } - state.PreferencesController.identities = state.KeyringController.walletNicknames + 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 } -- cgit