From 5a61a6d57af62bd4dea8f1563a9edde6a03e439b Mon Sep 17 00:00:00 2001 From: Frankie Date: Mon, 26 Mar 2018 14:24:12 -0700 Subject: migration for adding submittedTime to the txMeta (#3727) * test for migration 022 * write migration 022 adding submittedTime to txMetas whove been submitted --- app/scripts/migrations/022.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/scripts/migrations/022.js (limited to 'app/scripts/migrations') diff --git a/app/scripts/migrations/022.js b/app/scripts/migrations/022.js new file mode 100644 index 000000000..c3c0d53ef --- /dev/null +++ b/app/scripts/migrations/022.js @@ -0,0 +1,39 @@ + +const version = 22 + +/* + +This migration adds submittedTime to the txMeta if it is not their + +*/ + +const clone = require('clone') + +module.exports = { + version, + + migrate: function (originalVersionedData) { + const 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 = state + const transactions = newState.TransactionController.transactions + + newState.TransactionController.transactions = transactions.map((txMeta) => { + if (txMeta.status !== 'submitted' || txMeta.submittedTime) return txMeta + txMeta.submittedTime = (new Date()).getTime() + return txMeta + }) + return newState +} -- cgit v1.2.3