diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index ab5a757b3..312345263 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -15,7 +15,7 @@ class Migrator { let remaining = this.migrations.filter(migrationIsPending) return ( - asyncQ.eachSeries(remaining, (migration) => migration.migrate(versionedData)) + asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration)) .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) { return { meta: { diff --git a/app/scripts/migrations/009.js b/app/scripts/migrations/009.js index 61b8b7fa2..38e6dcc09 100644 --- a/app/scripts/migrations/009.js +++ b/app/scripts/migrations/009.js @@ -6,7 +6,7 @@ This migration breaks out the CurrencyController substate */ -const merge = require('deep-merge') +const merge = require('deep-extend') module.exports = { version, @@ -25,7 +25,7 @@ module.exports = { } function transformState (state) { - const newState = merge(state, { + const newState = merge({}, state, { CurrencyController: { currentCurrency: state.currentFiat || 'USD', conversionRate: state.conversionRate, diff --git a/package.json b/package.json index ed0be3d4b..3337f4ac5 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "clone": "^1.0.2", "copy-to-clipboard": "^2.0.0", "debounce": "^1.0.0", - "deep-merge": "^1.0.0", + "deep-extend": "^0.4.1", "denodeify": "^1.2.1", "disc": "^1.3.2", "dnode": "^1.2.2",