From fa0bbd66b6896188c5a47ed6978fc992068ae22c Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 23 Mar 2017 11:28:06 -0400 Subject: Fix persistence of transactions between networks. --- app/scripts/transaction-manager.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index 31c1c8431..7227bdc87 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -47,27 +47,39 @@ module.exports = class TransactionManager extends EventEmitter { // Returns the tx list getTxList () { let network = this.getNetwork() - let fullTxList = this.store.getState().transactions + let fullTxList = this.getFullTxList() return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network) } + // Returns the number of txs for the current network. + getTxCount () { + return this.getTxList().length + } + + // Returns the full tx list across all networks + getFullTxList () { + return this.store.getState().transactions + } + // Adds a tx to the txlist addTx (txMeta) { - var txList = this.getTxList() - var txHistoryLimit = this.txHistoryLimit + let txCount = this.getTxCount() + let network = this.getNetwork() + let fullTxList = this.getFullTxList() + let txHistoryLimit = this.txHistoryLimit - // checks if the length of th tx history is + // checks if the length of the tx history is // longer then desired persistence limit // and then if it is removes only confirmed // or rejected tx's. // not tx's that are pending or unapproved - if (txList.length > txHistoryLimit - 1) { - var index = txList.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected') - txList.splice(index, 1) + if (txCount > txHistoryLimit - 1) { + var index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId)) + fullTxList.splice(index, 1) } - txList.push(txMeta) + fullTxList.push(txMeta) - this._saveTxList(txList) + this._saveTxList(fullTxList) this.once(`${txMeta.id}:signed`, function (txId) { this.removeAllListeners(`${txMeta.id}:rejected`) }) @@ -89,7 +101,7 @@ module.exports = class TransactionManager extends EventEmitter { // updateTx (txMeta) { var txId = txMeta.id - var txList = this.getTxList() + var txList = this.getFullTxList() var index = txList.findIndex(txData => txData.id === txId) txList[index] = txMeta this._saveTxList(txList) -- cgit v1.2.3 From 2e446eb5880396716d919e10e97a7ab824cc0fc1 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 23 Mar 2017 11:28:52 -0400 Subject: Add to changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b77ceb864..2490dfb8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fixed bug where spinner wouldn't disappear on incorrect password submission on seed word reveal. - Polish the private key UI. - Add Kovan as an option on our network list. +- Fixed bug where transactions on other networks would disappear when submitting a transaction on another network. ## 3.4.0 2017-3-8 -- cgit v1.2.3 From 360afacd7093b16ae5dbfeb77a9f305e15b30297 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 24 Mar 2017 17:21:58 -0400 Subject: Add tests. --- test/unit/tx-manager-test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index f64f048e3..2912a03d3 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -59,6 +59,17 @@ describe('Transaction Manager', function() { assert.equal(result[0].id, 1) }) + it('does not override txs from other networks', function() { + var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} } + var tx2 = { id: 2, status: 'confirmed', metamaskNetworkId: 'another net', txParams: {} } + txManager.addTx(tx, noop) + txManager.addTx(tx2, noop) + var result = txManager.getFullTxList() + var result2 = txManager.getTxList() + assert.equal(result.length, 2, 'txs were deleted') + assert.equal(result.length, 1, 'incorrect number of txs on network.') + }) + it('cuts off early txs beyond a limit', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { -- cgit v1.2.3 From f8b404a478caa3057c1a7271afa70599755b8eab Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 24 Mar 2017 17:23:56 -0400 Subject: correct bug in test. --- test/unit/tx-manager-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index 2912a03d3..d4bffdd9b 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -67,7 +67,7 @@ describe('Transaction Manager', function() { var result = txManager.getFullTxList() var result2 = txManager.getTxList() assert.equal(result.length, 2, 'txs were deleted') - assert.equal(result.length, 1, 'incorrect number of txs on network.') + assert.equal(result2.length, 1, 'incorrect number of txs on network.') }) it('cuts off early txs beyond a limit', function() { -- cgit v1.2.3