diff options
Merge branch 'kumavis-patch-1' of github.com:MetaMask/metamask-plugin into kumavis-patch-1
Diffstat (limited to 'app/scripts/migrations/009.js')
-rw-r--r-- | app/scripts/migrations/009.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/scripts/migrations/009.js b/app/scripts/migrations/009.js new file mode 100644 index 000000000..4612fefdc --- /dev/null +++ b/app/scripts/migrations/009.js @@ -0,0 +1,43 @@ +const version = 9 + +/* + +This migration breaks out the CurrencyController substate + +*/ + +const merge = require('deep-extend') +const clone = require('clone') + +module.exports = { + version, + + migrate: function (originalVersionedData) { + let versionedData = clone(originalVersionedData) + versionedData.meta.version = version + try { + const state = versionedData.data + const newState = transformState(state) + versionedData.data = newState + } catch (err) { + console.warn(`MetaMask Migration #${version}` + err.stack) + } + return Promise.resolve(versionedData) + }, +} + +function transformState (state) { + const newState = merge({}, state, { + CurrencyController: { + currentCurrency: state.currentFiat || state.fiatCurrency || 'USD', + conversionRate: state.conversionRate, + conversionDate: state.conversionDate, + }, + }) + delete newState.currentFiat + delete newState.fiatCurrency + delete newState.conversionRate + delete newState.conversionDate + + return newState +} |