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
13 changes: 13 additions & 0 deletions src/shared/models/ip-log/ip-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ export class IpLogService {
) {}

private readonly idCache = new AsyncCache<IpLog>(CacheItemResetPeriod.EVERY_6_MONTHS);
private readonly recentLogCache = new AsyncCache<IpLog>(CacheItemResetPeriod.EVERY_10_SECONDS);

async create(ip: string, url: string, address: string, walletType?: WalletType, userData?: UserData): Promise<IpLog> {
const cacheKey = `${ip}:${address}:${url}:${walletType ?? ''}:${userData?.id ?? ''}`;

return this.recentLogCache.get(cacheKey, () => this.doCreate(ip, url, address, walletType, userData));
}

private async doCreate(
ip: string,
url: string,
address: string,
walletType?: WalletType,
userData?: UserData,
): Promise<IpLog> {
const { country, result, user } = await this.checkIpCountry(ip, address);
const ipLog = this.ipLogRepo.create({
ip,
Expand Down
56 changes: 27 additions & 29 deletions src/subdomains/supporting/fiat-output/fiat-output-job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,35 @@ export class FiatOutputJobService {
await this.checkTransmission();
await this.transmitYapealPayments();
await this.transmitOlkypayPayments();
await this.checkOlkypayOrderStatus();
await this.searchOutgoingBankTx();
}

@DfxCron(CronExpression.EVERY_HOUR, { process: Process.FIAT_OUTPUT })
async checkOlkypayOrderStatus(): Promise<void> {
if (DisabledProcess(Process.FIAT_OUTPUT_OLKYPAY_STATUS_CHECK)) return;
if (!this.olkypayService.isAvailable()) return;

const entities = await this.fiatOutputRepo.find({
where: {
olkyOrderId: Not(IsNull()),
isApprovedDate: IsNull(),
isComplete: false,
},
});

for (const entity of entities) {
try {
const order = await this.olkypayService.getPaymentOrder(+entity.olkyOrderId);

if (order.orderStatus !== OlkypayOrderStatus.TO_VALIDATE) {
await this.fiatOutputRepo.update(entity.id, { isApprovedDate: new Date() });
}
} catch (e) {
this.logger.error(`Failed to check OLKYPAY order status for fiat output ${entity.id}:`, e);
}
}
}

@DfxCron(CronExpression.EVERY_HOUR, { process: Process.FIAT_OUTPUT, timeout: 1800 })
async generateReports() {
const entities = await this.fiatOutputRepo.find({
Expand Down Expand Up @@ -196,9 +221,7 @@ export class FiatOutputJobService {

const pendingFiatOutputs = accountIbanGroup.filter(
(tx) =>
tx.isReadyDate &&
!tx.bankTx &&
(!tx.bank || ![IbanBankName.YAPEAL, IbanBankName.OLKY].includes(tx.bank.name) || !tx.isTransmittedDate),
tx.isReadyDate && !tx.bankTx && (!tx.bank || tx.bank.name !== IbanBankName.YAPEAL || !tx.isTransmittedDate),
);
const pendingBalance = Util.sumObjValue(pendingFiatOutputs, 'bankAmount');

Expand Down Expand Up @@ -445,31 +468,6 @@ export class FiatOutputJobService {
}
}

private async checkOlkypayOrderStatus(): Promise<void> {
if (DisabledProcess(Process.FIAT_OUTPUT_OLKYPAY_STATUS_CHECK)) return;
if (!this.olkypayService.isAvailable()) return;

const entities = await this.fiatOutputRepo.find({
where: {
olkyOrderId: Not(IsNull()),
isApprovedDate: IsNull(),
isComplete: false,
},
});

for (const entity of entities) {
try {
const order = await this.olkypayService.getPaymentOrder(+entity.olkyOrderId);

if (order.orderStatus !== OlkypayOrderStatus.TO_VALIDATE) {
await this.fiatOutputRepo.update(entity.id, { isApprovedDate: new Date() });
}
} catch (e) {
this.logger.error(`Failed to check OLKYPAY order status for fiat output ${entity.id}:`, e);
}
}
}

private async searchOutgoingBankTx(): Promise<void> {
if (DisabledProcess(Process.FIAT_OUTPUT_BANK_TX_SEARCH)) return;

Expand Down
Loading