mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
migrations - fix migration #9 and add safety checks to migrator
This commit is contained in:
parent
99d6a329a2
commit
77f8995568
@ -15,7 +15,7 @@ class Migrator {
|
|||||||
let remaining = this.migrations.filter(migrationIsPending)
|
let remaining = this.migrations.filter(migrationIsPending)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
asyncQ.eachSeries(remaining, (migration) => migration.migrate(versionedData))
|
asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration))
|
||||||
.then(() => versionedData)
|
.then(() => versionedData)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +26,17 @@ class Migrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runMigration(versionedData, migration) {
|
||||||
|
return (
|
||||||
|
migration.migrate(versionedData)
|
||||||
|
.then((versionedData) => {
|
||||||
|
if (!versionedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data'))
|
||||||
|
if (migration.version !== undefined && versionedData.meta.version !== migration.version) return Promise.reject(new Error('Migrator - Migration did not update version number correctly'))
|
||||||
|
return Promise.resolve(versionedData)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
generateInitialState (initState) {
|
generateInitialState (initState) {
|
||||||
return {
|
return {
|
||||||
meta: {
|
meta: {
|
||||||
|
@ -6,7 +6,7 @@ This migration breaks out the CurrencyController substate
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const merge = require('deep-merge')
|
const merge = require('deep-extend')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
version,
|
version,
|
||||||
@ -25,7 +25,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function transformState (state) {
|
function transformState (state) {
|
||||||
const newState = merge(state, {
|
const newState = merge({}, state, {
|
||||||
CurrencyController: {
|
CurrencyController: {
|
||||||
currentCurrency: state.currentFiat || 'USD',
|
currentCurrency: state.currentFiat || 'USD',
|
||||||
conversionRate: state.conversionRate,
|
conversionRate: state.conversionRate,
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
"clone": "^1.0.2",
|
"clone": "^1.0.2",
|
||||||
"copy-to-clipboard": "^2.0.0",
|
"copy-to-clipboard": "^2.0.0",
|
||||||
"debounce": "^1.0.0",
|
"debounce": "^1.0.0",
|
||||||
"deep-merge": "^1.0.0",
|
"deep-extend": "^0.4.1",
|
||||||
"denodeify": "^1.2.1",
|
"denodeify": "^1.2.1",
|
||||||
"disc": "^1.3.2",
|
"disc": "^1.3.2",
|
||||||
"dnode": "^1.2.2",
|
"dnode": "^1.2.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user