diff --git a/src/subdomains/supporting/log/log-job.service.ts b/src/subdomains/supporting/log/log-job.service.ts index ec2a043176..989b256596 100644 --- a/src/subdomains/supporting/log/log-job.service.ts +++ b/src/subdomains/supporting/log/log-job.service.ts @@ -261,6 +261,10 @@ export class LogJobService { const pendingPayIns = await this.payInService.getPendingPayIns(); const pendingBuyFiat = await this.buyFiatService.getPendingTransactions(); const pendingBuyCrypto = await this.buyCryptoService.getPendingTransactions(); + const payoutSentBuyCryptoIds = await this.payoutService.getRecentPayoutSentCorrelationIds( + PayoutOrderContext.BUY_CRYPTO, + ); + const filteredPendingBuyCrypto = pendingBuyCrypto.filter((tx) => !payoutSentBuyCryptoIds.has(tx.id.toString())); const pendingBankTx = await this.bankTxService.getPendingTx(); const pendingBankTxRepeat = await this.bankTxRepeatService.getPendingTx(); const pendingBankTxReturn = await this.bankTxReturnService.getPendingTx(); @@ -822,7 +826,7 @@ export class LogJobService { const manualDebtPosition = manualDebtPositions.find((p) => p.assetId === curr.id)?.value ?? 0; const { input: buyFiat, output: buyFiatPass } = this.getPendingAmounts([curr], pendingBuyFiat); - const { input: buyCrypto, output: buyCryptoPass } = this.getPendingAmounts([curr], pendingBuyCrypto); + const { input: buyCrypto, output: buyCryptoPass } = this.getPendingAmounts([curr], filteredPendingBuyCrypto); const bankTxNull = this.getPendingAmounts( [curr], diff --git a/src/subdomains/supporting/payout/services/payout.service.ts b/src/subdomains/supporting/payout/services/payout.service.ts index d96496be56..da3b82e7c1 100644 --- a/src/subdomains/supporting/payout/services/payout.service.ts +++ b/src/subdomains/supporting/payout/services/payout.service.ts @@ -7,7 +7,7 @@ import { DfxCron } from 'src/shared/utils/cron'; import { Util } from 'src/shared/utils/util'; import { MailContext, MailType } from 'src/subdomains/supporting/notification/enums'; import { NotificationService } from 'src/subdomains/supporting/notification/services/notification.service'; -import { FindOptionsRelations, IsNull, MoreThan, Not } from 'typeorm'; +import { FindOptionsRelations, In, IsNull, MoreThan, Not } from 'typeorm'; import { MailRequest } from '../../notification/interfaces'; import { PayoutOrder, PayoutOrderContext, PayoutOrderStatus } from '../entities/payout-order.entity'; import { PayoutOrderFactory } from '../factories/payout-order.factory'; @@ -79,6 +79,16 @@ export class PayoutService { }; } + async getRecentPayoutSentCorrelationIds(context: PayoutOrderContext): Promise> { + const since = new Date(Date.now() - 3600_000); // 1 hour + const orders = await this.payoutOrderRepo.findBy({ + context, + status: In([PayoutOrderStatus.PAYOUT_PENDING, PayoutOrderStatus.COMPLETE]), + updated: MoreThan(since), + }); + return new Set(orders.map((o) => o.correlationId)); + } + async estimateFee(targetAsset: Asset, address: string, amount: number, asset: Asset): Promise { const prepareStrategy = this.prepareStrategyRegistry.getPrepareStrategy(targetAsset); const payoutStrategy = this.payoutStrategyRegistry.getPayoutStrategy(targetAsset);