Skip to content

Commit

Permalink
fix: add time condition to filter out old transactions (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriem-BM authored Sep 9, 2024
1 parent 082848e commit e643491
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/services/cronJobs/checkQRTransactionJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,24 @@ export async function checkTransactions(
if (!transactions.length) return;

for (const transaction of transactions) {
const transactionCreatedAt = new Date(transaction.created_at).getTime();
const transactionAge = Date.now() - transactionCreatedAt;

const TWO_MINUTES = 2 * 60 * 1000;

const isNativePayment =
transaction.asset_type === 'native' &&
transaction.type === 'payment' &&
transaction.to === toWalletAddress &&
Number(transaction.amount) === amount;

const isCreateAccount =
transaction.type === 'create_account' &&
transaction.account === toWalletAddress &&
Number(transaction.starting_balance) === amount;

const isMatchingTransaction =
(transaction.asset_type === 'native' &&
transaction.type === 'payment' &&
transaction.to === toWalletAddress &&
Number(transaction.amount) === amount) ||
(transaction.type === 'create_account' &&
transaction.account === toWalletAddress &&
Number(transaction.starting_balance) === amount);
(isNativePayment || isCreateAccount) && transactionAge < TWO_MINUTES;

if (isMatchingTransaction) {
if (
Expand Down

0 comments on commit e643491

Please sign in to comment.