From 00eac75c3a115655edd00c3f5af13f128d2f7e84 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 21 Apr 2020 23:34:45 -0230 Subject: [PATCH] Skip adding history entry for empty txMeta diffs --- .../transactions/tx-state-manager.js | 4 +++- .../transactions/tx-state-manager-test.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 9674529c94b2..0d986881a2f1 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -202,7 +202,9 @@ class TransactionStateManager extends EventEmitter { const previousState = replayHistory(txMeta.history) // generate history entry and add to history const entry = generateHistoryEntry(previousState, currentState, note) - txMeta.history.push(entry) + if (entry.length) { + txMeta.history.push(entry) + } // commit txMeta to state const txId = txMeta.id diff --git a/test/unit/app/controllers/transactions/tx-state-manager-test.js b/test/unit/app/controllers/transactions/tx-state-manager-test.js index ae30308ddebe..ec6483f80b72 100644 --- a/test/unit/app/controllers/transactions/tx-state-manager-test.js +++ b/test/unit/app/controllers/transactions/tx-state-manager-test.js @@ -256,6 +256,23 @@ describe('TransactionStateManager', function () { assert.deepEqual(result.history[1][0].value, expectedEntry.value, 'two history items (initial + diff) value') assert.ok(result.history[1][0].timestamp >= before && result.history[1][0].timestamp <= after) }) + + it('does NOT add empty history items', function () { + const txMeta = { + id: '1', + status: 'unapproved', + metamaskNetworkId: currentNetworkId, + txParams: { + gasPrice: '0x01', + }, + } + + txStateManager.addTx(txMeta) + txStateManager.updateTx(txMeta) + + const { history } = txStateManager.getTx('1') + assert.equal(history.length, 1, 'two history items (initial + diff)') + }) }) describe('#getUnapprovedTxList', function () {