Skip to content

Commit

Permalink
Merge pull request #611 from EdgeApp/william/spam-filter
Browse files Browse the repository at this point in the history
Add a spam filter to `streamTransactions`
  • Loading branch information
swansontec authored Aug 12, 2024
2 parents fa70285 + 913a6a3 commit 97d16fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: `EdgeStreamTransactionOptions.spamThreshold`.

## 2.12.0 (2024-08-12)

- added: `EdgeCurrencyEngine.otherMethodsWithKeys`. These methods will be added to `EdgeCurrencyEngine.otherMethods`, but the core will insert private keys as the first parameter.
Expand Down
14 changes: 11 additions & 3 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { div, eq, mul } from 'biggystring'
import { abs, div, eq, lt, mul } from 'biggystring'
import { Disklet } from 'disklet'
import { base64 } from 'rfc4648'
import { bridgifyObject, onMethod, watchMethod } from 'yaob'
Expand Down Expand Up @@ -251,6 +251,7 @@ export function makeCurrencyWalletApi(
beforeDate,
firstBatchSize = batchSize,
searchString,
spamThreshold = '0',
tokenId = null
} = opts
const { currencyCode } =
Expand Down Expand Up @@ -326,6 +327,7 @@ export function makeCurrencyWalletApi(
const edgeTx = combineTxWithFile(input, tx, file, tokenId)
if (!searchStringFilter(ai, edgeTx, searchString)) continue
if (!dateFilter(edgeTx, afterDate, beforeDate)) continue
if (!tx.isSend && lt(abs(nativeAmount), spamThreshold)) continue

out.push(edgeTx)
}
Expand All @@ -339,7 +341,12 @@ export function makeCurrencyWalletApi(
async getTransactions(
opts: EdgeGetTransactionsOptions
): Promise<EdgeTransaction[]> {
const { endDate: beforeDate, startDate: afterDate, searchString } = opts
const {
endDate: beforeDate,
startDate: afterDate,
searchString,
spamThreshold
} = opts
const upgradedCurrency = upgradeCurrencyCode({
allTokens: input.props.state.accounts[accountId].allTokens[pluginId],
currencyInfo: plugin.currencyInfo,
Expand All @@ -350,7 +357,8 @@ export function makeCurrencyWalletApi(
...upgradedCurrency,
afterDate,
beforeDate,
searchString
searchString,
spamThreshold
})

// We have no length, so iterate to get everything:
Expand Down
4 changes: 4 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ export interface EdgeGetTransactionsOptions {
startDate?: Date
endDate?: Date
searchString?: string
spamThreshold?: string
tokenId: EdgeTokenId
}

Expand All @@ -816,6 +817,9 @@ export interface EdgeStreamTransactionOptions {
/** Only return transactions matching this string */
searchString?: string

/** Filter incoming transactions with a `nativeAmount` below this */
spamThreshold?: string

/** The token to query, or undefined for the main currency */
tokenId: EdgeTokenId
}
Expand Down

0 comments on commit 97d16fb

Please sign in to comment.