transactions:tx-state-manager - optionally take a function as a search param (#7078)

feature/default_network_editable
Frankie 5 years ago committed by GitHub
parent b8e69369d5
commit f6d25357db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/scripts/controllers/transactions/tx-state-manager.js
  2. 3
      test/unit/app/controllers/transactions/tx-state-manager-test.js

@ -250,9 +250,11 @@ class TransactionStateManager extends EventEmitter {
let <code>thingsToLookFor = {<br>
to: '0x0..',<br>
from: '0x0..',<br>
status: 'signed',<br>
status: 'signed', \\ (status) => status !== 'rejected' give me all txs who's status is not rejected<br>
err: undefined,<br>
}<br></code>
optionally the values of the keys can be functions for situations like where
you want all but one status.
@param [initialList=this.getTxList()]
@returns a {array} of txMeta with all
options matching
@ -268,7 +270,7 @@ class TransactionStateManager extends EventEmitter {
this is for things like filtering a the tx list
for only tx's from 1 account
or for filltering for all txs from one account
or for filtering for all txs from one account
and that have been 'confirmed'
*/
getFilteredTxList (opts, initialList) {
@ -281,17 +283,19 @@ class TransactionStateManager extends EventEmitter {
/**
@param key {string} - the key to check
@param value - the value your looking for
@param value - the value your looking for can also be a function that returns a bool
@param [txList=this.getTxList()] {array} - the list to search. default is the txList
from txStateManager#getTxList
@returns {array} a list of txMetas who matches the search params
*/
getTxsByMetaData (key, value, txList = this.getTxList()) {
const filter = typeof value === 'function' ? value : (v) => v === value
return txList.filter((txMeta) => {
if (key in txMeta.txParams) {
return txMeta.txParams[key] === value
return filter(txMeta.txParams[key])
} else {
return txMeta[key] === value
return filter(txMeta[key])
}
})
}

@ -303,6 +303,9 @@ describe('TransactionStateManager', function () {
assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
filterParams = { to: '0xaa' }
assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
filterParams = { status: (status) => status !== 'confirmed' }
assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
})
})

Loading…
Cancel
Save