From f6d25357dbd5ee12a3841e863549961f7ea1a88d Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 29 Aug 2019 14:57:28 +0200 Subject: transactions:tx-state-manager - optionally take a function as a search param (#7078) --- app/scripts/controllers/transactions/tx-state-manager.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index a91b59918..6a92c0601 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -250,9 +250,11 @@ class TransactionStateManager extends EventEmitter { let thingsToLookFor = {
to: '0x0..',
from: '0x0..',
- status: 'signed',
+ status: 'signed', \\ (status) => status !== 'rejected' give me all txs who's status is not rejected
err: undefined,
}
+ 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]) } }) } -- cgit