diff options
author | Frankie <frankie.diamond@gmail.com> | 2019-08-29 20:57:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-29 20:57:28 +0800 |
commit | f6d25357dbd5ee12a3841e863549961f7ea1a88d (patch) | |
tree | 93b88e06e9245d926ac70ce4a13e86c9382f0ef2 /app/scripts/controllers/transactions/tx-state-manager.js | |
parent | b8e69369d54763cc58695687738ac3885014f3b4 (diff) | |
download | tangerine-wallet-browser-f6d25357dbd5ee12a3841e863549961f7ea1a88d.tar.gz tangerine-wallet-browser-f6d25357dbd5ee12a3841e863549961f7ea1a88d.tar.zst tangerine-wallet-browser-f6d25357dbd5ee12a3841e863549961f7ea1a88d.zip |
transactions:tx-state-manager - optionally take a function as a search param (#7078)
Diffstat (limited to 'app/scripts/controllers/transactions/tx-state-manager.js')
-rw-r--r-- | app/scripts/controllers/transactions/tx-state-manager.js | 14 |
1 files changed, 9 insertions, 5 deletions
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 <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]) } }) } |