Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/subdomains/supporting/log/log-job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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],
Expand Down
12 changes: 11 additions & 1 deletion src/subdomains/supporting/payout/services/payout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -79,6 +79,16 @@ export class PayoutService {
};
}

async getRecentPayoutSentCorrelationIds(context: PayoutOrderContext): Promise<Set<string>> {
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<FeeResult> {
const prepareStrategy = this.prepareStrategyRegistry.getPrepareStrategy(targetAsset);
const payoutStrategy = this.payoutStrategyRegistry.getPayoutStrategy(targetAsset);
Expand Down
Loading