aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-03-28 08:01:01 +0800
committerGitHub <noreply@github.com>2018-03-28 08:01:01 +0800
commitb6b18339e2de92afd2fb5364ec5bc4c29b4d10a3 (patch)
tree406c402960ec4e6016328ddf065e2f8be794e230 /app/scripts
parentcd3e092c14ce4541b36cd0fa15973057c7f2d561 (diff)
parentfefbf40a06aa4af7d5cf08767fa96ad75427dd20 (diff)
downloadtangerine-wallet-browser-b6b18339e2de92afd2fb5364ec5bc4c29b4d10a3.tar.gz
tangerine-wallet-browser-b6b18339e2de92afd2fb5364ec5bc4c29b4d10a3.tar.zst
tangerine-wallet-browser-b6b18339e2de92afd2fb5364ec5bc4c29b4d10a3.zip
Merge pull request #3758 from MetaMask/i#3731
I#3731
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/lib/tx-state-manager.js7
-rw-r--r--app/scripts/migrations/023.js50
-rw-r--r--app/scripts/migrations/index.js1
3 files changed, 52 insertions, 6 deletions
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index ad07c813f..ab344ae9b 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -38,11 +38,6 @@ module.exports = class TransactionStateManager extends EventEmitter {
}, opts)
}
- // Returns the number of txs for the current network.
- getTxCount () {
- return this.getTxList().length
- }
-
getTxList () {
const network = this.getNetwork()
const fullTxList = this.getFullTxList()
@@ -88,7 +83,7 @@ module.exports = class TransactionStateManager extends EventEmitter {
txMeta.history.push(snapshot)
const transactions = this.getFullTxList()
- const txCount = this.getTxCount()
+ const txCount = transactions.length
const txHistoryLimit = this.txHistoryLimit
// checks if the length of the tx history is
diff --git a/app/scripts/migrations/023.js b/app/scripts/migrations/023.js
new file mode 100644
index 000000000..bce0a5bea
--- /dev/null
+++ b/app/scripts/migrations/023.js
@@ -0,0 +1,50 @@
+
+const version = 23
+
+/*
+
+This migration removes transactions that are no longer usefull down to 40 total
+
+*/
+
+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
+
+ if (transactions.length <= 40) return newState
+
+ let reverseTxList = transactions.reverse()
+ let stripping = true
+ while (reverseTxList.length > 40 && stripping) {
+ let txIndex = reverseTxList.findIndex((txMeta) => {
+ return (txMeta.status === 'failed' ||
+ txMeta.status === 'rejected' ||
+ txMeta.status === 'confirmed' ||
+ txMeta.status === 'dropped')
+ })
+ if (txIndex < 0) stripping = false
+ else reverseTxList.splice(txIndex, 1)
+ }
+
+ newState.TransactionController.transactions = reverseTxList.reverse()
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index b49a40c65..811e06b6b 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -33,4 +33,5 @@ module.exports = [
require('./020'),
require('./021'),
require('./022'),
+ require('./023'),
]