aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/migrations')
-rw-r--r--app/scripts/migrations/029.js27
-rw-r--r--app/scripts/migrations/030.js49
-rw-r--r--app/scripts/migrations/031.js31
-rw-r--r--app/scripts/migrations/032.js29
-rw-r--r--app/scripts/migrations/fail-tx.js41
-rw-r--r--app/scripts/migrations/index.js3
6 files changed, 180 insertions, 0 deletions
diff --git a/app/scripts/migrations/029.js b/app/scripts/migrations/029.js
new file mode 100644
index 000000000..e17479ccc
--- /dev/null
+++ b/app/scripts/migrations/029.js
@@ -0,0 +1,27 @@
+// next version number
+const version = 29
+const failTxsThat = require('./fail-tx')
+
+// time
+const seconds = 1000
+const minutes = 60 * seconds
+const hours = 60 * minutes
+const unacceptableDelay = 12 * hours
+
+/*
+
+normalizes txParams on unconfirmed txs
+
+*/
+
+module.exports = {
+ version,
+
+ migrate: failTxsThat(version, 'Stuck in approved state for too long.', (txMeta) => {
+ const isApproved = txMeta.status === 'approved'
+ const createdTime = txMeta.submittedTime
+ const now = Date.now()
+ return isApproved && now - createdTime > unacceptableDelay
+ }),
+}
+
diff --git a/app/scripts/migrations/030.js b/app/scripts/migrations/030.js
new file mode 100644
index 000000000..10f7d33b2
--- /dev/null
+++ b/app/scripts/migrations/030.js
@@ -0,0 +1,49 @@
+// next version number
+const version = 30
+
+/*
+
+removes invalid chaids from preferences and networkController for custom rpcs
+
+*/
+
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ return versionedData
+ },
+}
+
+function transformState (state) {
+ const newState = state
+ if (state.PreferencesController) {
+ const frequentRpcListDetail = newState.PreferencesController.frequentRpcListDetail
+ if (frequentRpcListDetail) {
+ frequentRpcListDetail.forEach((rpc, index) => {
+ if (!!rpc.chainId && Number.isNaN(parseInt(rpc.chainId))) {
+ delete frequentRpcListDetail[index].chainId
+ }
+ })
+ newState.PreferencesController.frequentRpcListDetail = frequentRpcListDetail
+ }
+ }
+ if (state.NetworkController) {
+ if (newState.NetworkController.network && Number.isNaN(parseInt(newState.NetworkController.network))) {
+ delete newState.NetworkController.network
+ }
+
+ if (newState.NetworkController.provider && newState.NetworkController.provider.chainId && Number.isNaN(parseInt(newState.NetworkController.provider.chainId))) {
+ delete newState.NetworkController.provider.chainId
+ }
+ }
+
+ return newState
+}
diff --git a/app/scripts/migrations/031.js b/app/scripts/migrations/031.js
new file mode 100644
index 000000000..98d182828
--- /dev/null
+++ b/app/scripts/migrations/031.js
@@ -0,0 +1,31 @@
+// next version number
+const version = 31
+const clone = require('clone')
+
+ /*
+ * The purpose of this migration is to properly set the completedOnboarding flag baesd on the state
+ * of the KeyringController.
+ */
+module.exports = {
+ version,
+
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ return versionedData
+ },
+}
+
+ function transformState (state) {
+ const { KeyringController, PreferencesController } = state
+
+ if (KeyringController && PreferencesController) {
+ const { vault } = KeyringController
+ PreferencesController.completedOnboarding = Boolean(vault)
+ }
+
+ return state
+}
diff --git a/app/scripts/migrations/032.js b/app/scripts/migrations/032.js
new file mode 100644
index 000000000..e89fe383f
--- /dev/null
+++ b/app/scripts/migrations/032.js
@@ -0,0 +1,29 @@
+const version = 32
+const clone = require('clone')
+
+/**
+ * The purpose of this migration is to set the {@code completedUiMigration} flag based on the user's UI preferences
+ */
+module.exports = {
+ version,
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ versionedData.data = transformState(state)
+ return versionedData
+ },
+}
+
+function transformState (state) {
+ const { PreferencesController } = state
+
+ if (PreferencesController) {
+ const { betaUI } = PreferencesController.featureFlags || {}
+ // Users who have been using the "beta" UI are considered to have completed the migration
+ // as they'll see no difference in this version
+ PreferencesController.completedUiMigration = betaUI
+ }
+
+ return state
+}
diff --git a/app/scripts/migrations/fail-tx.js b/app/scripts/migrations/fail-tx.js
new file mode 100644
index 000000000..98e3ffddb
--- /dev/null
+++ b/app/scripts/migrations/fail-tx.js
@@ -0,0 +1,41 @@
+const clone = require('clone')
+
+module.exports = function (version, reason, condition) {
+ return function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ try {
+ const state = versionedData.data
+ const newState = transformState(state, condition, reason)
+ versionedData.data = newState
+ } catch (err) {
+ console.warn(`MetaMask Migration #${version}` + err.stack)
+ }
+ return Promise.resolve(versionedData)
+
+ }
+}
+
+function transformState (state, condition, reason) {
+ const newState = state
+ const { TransactionController } = newState
+ if (TransactionController && TransactionController.transactions) {
+ const transactions = TransactionController.transactions
+
+ newState.TransactionController.transactions = transactions.map((txMeta) => {
+ if (!condition(txMeta)) {
+ return txMeta
+ }
+
+ txMeta.status = 'failed'
+ txMeta.err = {
+ message: reason,
+ note: `Tx automatically failed by migration because ${reason}`,
+ }
+
+ return txMeta
+ })
+ }
+ return newState
+}
+
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index 3b512715e..eb1b51685 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -39,4 +39,7 @@ module.exports = [
require('./026'),
require('./027'),
require('./028'),
+ require('./029'),
+ require('./030'),
+ require('./031'),
]