aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-08-19 06:40:56 +0800
committerDan Finlay <dan@danfinlay.com>2016-08-19 06:40:56 +0800
commit7389f9d0a0e1f798607ea8eea25583f8af854358 (patch)
tree45dba4e6ef5cf1a84a92a08a558fecd32465170a
parent90d6bec3ed51ba4b2d4696132642a4d97712dec9 (diff)
downloadtangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar.gz
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar.bz2
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar.lz
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar.xz
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.tar.zst
tangerine-wallet-browser-7389f9d0a0e1f798607ea8eea25583f8af854358.zip
Enforce tx history limit
-rw-r--r--app/scripts/lib/config-manager.js6
-rw-r--r--test/unit/config-manager-test.js11
2 files changed, 17 insertions, 0 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index c56f52e48..2ecdbb0c7 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -5,6 +5,7 @@ const rp = require('request-promise')
const TESTNET_RPC = MetamaskConfig.network.testnet
const MAINNET_RPC = MetamaskConfig.network.mainnet
+const txLimit = 40
/* The config-manager is a convenience object
* wrapping a pojo-migrator.
@@ -15,6 +16,8 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
*/
module.exports = ConfigManager
function ConfigManager (opts) {
+ this.txLimit = txLimit
+
// ConfigManager is observable and will emit updates
this._subs = []
@@ -181,6 +184,9 @@ ConfigManager.prototype._saveTxList = function (txList) {
ConfigManager.prototype.addTx = function (tx) {
var transactions = this.getTxList()
+ while (transactions.length > this.txLimit - 1) {
+ transactions.shift()
+ }
transactions.push(tx)
this._saveTxList(transactions)
}
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index b34089163..eaa5376fd 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -233,6 +233,17 @@ describe('config-manager', function() {
assert.equal(result.length, 1)
assert.equal(result[0].id, 1)
})
+
+ it('cuts off early txs beyond a limit', function() {
+ const limit = configManager.txLimit
+ for (let i = 0; i < limit + 1; i++) {
+ let tx = { id: i }
+ configManager.addTx(tx)
+ }
+ var result = configManager.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 1, 'early txs truncted')
+ })
})
describe('#confirmTx', function() {