diff options
author | kumavis <aaron@kumavis.me> | 2018-03-28 08:17:04 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2018-03-28 08:17:04 +0800 |
commit | 5290570c8fc635856823e8f66b8f810f07b7948a (patch) | |
tree | cb98ac01c290f0c9786fc285469bb37e6a851910 /app | |
parent | 4ee48acf5672f00d59c49ec68452cd1dd57afa31 (diff) | |
parent | b6b18339e2de92afd2fb5364ec5bc4c29b4d10a3 (diff) | |
download | tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.gz tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.zst tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.zip |
Merge branch 'master' of github.com:MetaMask/metamask-extension into i18n-translator-redux
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/tx-state-manager.js | 7 | ||||
-rw-r--r-- | app/scripts/migrations/023.js | 50 | ||||
-rw-r--r-- | app/scripts/migrations/index.js | 1 |
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'), ] |