mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
transactions:tx-state-manager - optionally take a function as a search param (#7078)
This commit is contained in:
parent
b8e69369d5
commit
f6d25357db
@ -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…
Reference in New Issue
Block a user