Skip to content

Commit e4cde51

Browse files
authored
Merge pull request #3454 from DFXswiss/develop
Release: develop -> main
2 parents ade1fc1 + 4751ae7 commit e4cde51

8 files changed

Lines changed: 63 additions & 26 deletions

File tree

src/subdomains/core/buy-crypto/process/entities/buy-crypto.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ export class BuyCrypto extends IEntity {
715715
refFactor: null,
716716
usedFees: null,
717717
networkStartFeeAmount: null,
718-
status: null,
718+
status: BuyCryptoStatus.CREATED,
719719
};
720720

721721
Object.assign(this, update);

src/subdomains/core/referral/referral.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ import { RefRewardService } from './reward/services/ref-reward.service';
4646
RefRewardOutService,
4747
RefRewardJobService,
4848
],
49-
exports: [RefService, RefRewardService, RefRewardRepository],
49+
exports: [RefService, RefRewardService],
5050
})
5151
export class ReferralModule {}

src/subdomains/core/referral/reward/services/ref-reward.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,22 @@ export class RefRewardService {
239239
cryptoCurrency: v.outputAsset.dexName,
240240
}));
241241
}
242+
243+
async getRewardRecipients(from?: Date): Promise<{ userDataId: number; count: number; totalChf: number }[]> {
244+
const query = this.rewardRepo
245+
.createQueryBuilder('r')
246+
.innerJoin('r.user', 'u')
247+
.select('u.userDataId', 'userDataId')
248+
.addSelect('COUNT(*)', 'count')
249+
.addSelect('ROUND(SUM(r.amountInChf), 0)', 'totalChf')
250+
.where('r.status != :excluded', { excluded: RewardStatus.USER_SWITCH })
251+
.groupBy('u.userDataId')
252+
.orderBy('totalChf', 'DESC');
253+
254+
if (from) {
255+
query.andWhere('r.created >= :from', { from });
256+
}
257+
258+
return query.getRawMany();
259+
}
242260
}

src/subdomains/generic/kyc/dto/kyc-error.enum.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export enum KycError {
3636
DENIED_RECOMMENDATION = 'DeniedRecommendation',
3737
RECOMMENDER_BLOCKED = 'RecommenderBlocked',
3838

39-
// FinancialData errors
39+
// FinancialData errors/reasons
4040
MISSING_INFO = 'MissingInfo',
4141
RISKY_BUSINESS = 'RiskyBusiness',
4242
INCORRECT_INFO = 'IncorrectInfo',
@@ -50,6 +50,8 @@ export enum KycError {
5050
// DfxApproval errors
5151
BANK_RECALL_FEE_NOT_PAID = 'BankRecallFeeNotPaid',
5252
OPEN_SANCTIONED_NAME_CHECK = 'OpenSanctionedNameCheck',
53+
RISK_ACCEPTED = 'RiskAccepted',
54+
NO_GWG_RISK = 'NoGwgRisk',
5355

5456
// Deactivated userData errors
5557
USER_DATA_DEACTIVATED = 'UserDataDeactivated',
@@ -95,6 +97,8 @@ export const KycErrorMap: Record<KycError, string> = {
9597
[KycError.RESIDENCE_PERMIT_CHECK_REQUIRED]: undefined,
9698
[KycError.EXPIRED_STEP]: 'Your documents are expired',
9799
[KycError.MANUAL_REVIEW_REQUIRED]: undefined,
100+
[KycError.RISK_ACCEPTED]: undefined,
101+
[KycError.NO_GWG_RISK]: undefined,
98102
};
99103

100104
export const KycReasonMap: { [e in KycError]?: KycStepReason } = {

src/subdomains/generic/kyc/services/kyc-log.service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ export class KycLogService {
9191
}
9292

9393
async getLogsByUserDataId(userDataId: number): Promise<KycLog[]> {
94-
return this.kycLogRepo
95-
.createQueryBuilder('log')
96-
.where('log.userDataId = :userDataId', { userDataId })
97-
.orderBy('log.created', 'DESC')
98-
.getMany();
94+
return this.kycLogRepo.find({
95+
where: { userData: { id: userDataId } },
96+
order: { created: 'DESC' },
97+
});
9998
}
10099

101100
async createKycFileLog(log: string, user?: UserData) {

src/subdomains/generic/kyc/services/kyc.service.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,39 @@ export class KycService {
468468

469469
async initializeProcess(userData: UserData): Promise<UserData> {
470470
const user = await this.getUser(userData.kycHash);
471-
if (user.getStepsWith(KycStepName.CONTACT_DATA).length > 0) return user;
471+
472+
const contactSteps = user.getStepsWith(KycStepName.CONTACT_DATA);
473+
if (contactSteps.length > 0) {
474+
// Complete pending ContactData step if user now has an email
475+
const pendingStep = contactSteps.find((s) => s.isInProgress);
476+
if (pendingStep && user.mail) {
477+
const result = await this.trySetMail(user, pendingStep, user.mail);
478+
await this.kycStepRepo.update(...result);
479+
await this.createStepLog(user, pendingStep);
480+
await this.updateProgress(user, false);
481+
}
482+
return user;
483+
}
472484

473485
return this.updateProgress(user, true, false);
474486
}
475487

488+
async failContactStepForMail(userData: UserData, mail: string, error: string): Promise<void> {
489+
try {
490+
const user = await this.getUser(userData.kycHash);
491+
const pendingStep = user.getStepsWith(KycStepName.CONTACT_DATA).find((s) => s.isInProgress);
492+
if (!pendingStep) return;
493+
494+
const kycError = error.includes('account merge request sent')
495+
? KycError.USER_DATA_MERGE_REQUESTED
496+
: KycError.USER_DATA_EXISTING;
497+
await this.kycStepRepo.update(...pendingStep.fail({ mail }, kycError));
498+
await this.createStepLog(user, pendingStep);
499+
} catch (e) {
500+
this.logger.error(`Failed to update ContactData step for account ${userData.id}:`, e);
501+
}
502+
}
503+
476504
public getMailFailedReason(comment: string, language: string): string {
477505
return `<ul>${comment
478506
?.split(';')

src/subdomains/generic/user/models/user-data/user-data.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ export class UserDataService {
731731
if (mergeRequested) errorMessage += ' - account merge request sent';
732732
}
733733

734+
await this.kycService.failContactStepForMail(userData, mail, errorMessage);
735+
734736
throw new ConflictException(errorMessage);
735737
}
736738

src/subdomains/supporting/dashboard/dashboard-financial.service.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { AssetService } from 'src/shared/models/asset/asset.service';
3-
import { RefRewardRepository } from '../../core/referral/reward/ref-reward.repository';
3+
import { RefRewardService } from '../../core/referral/reward/services/ref-reward.service';
44
import { Log } from '../log/log.entity';
55
import { LogService } from '../log/log.service';
66
import { FinanceLog } from '../log/dto/log.dto';
@@ -19,7 +19,7 @@ export class DashboardFinancialService {
1919
constructor(
2020
private readonly logService: LogService,
2121
private readonly assetService: AssetService,
22-
private readonly refRewardRepo: RefRewardRepository,
22+
private readonly refRewardService: RefRewardService,
2323
) {}
2424

2525
async getFinancialLog(from?: Date, dailySample?: boolean): Promise<FinancialLogResponseDto> {
@@ -37,21 +37,7 @@ export class DashboardFinancialService {
3737
}
3838

3939
async getRefRewardRecipients(from?: Date): Promise<RefRewardRecipientDto[]> {
40-
const query = this.refRewardRepo
41-
.createQueryBuilder('r')
42-
.innerJoin('r.user', 'u')
43-
.select('u.userDataId', 'userDataId')
44-
.addSelect('COUNT(*)', 'count')
45-
.addSelect('ROUND(SUM(r.amountInChf), 0)', 'totalChf')
46-
.where('r.status != :excluded', { excluded: 'UserSwitch' })
47-
.groupBy('u.userDataId')
48-
.orderBy('totalChf', 'DESC');
49-
50-
if (from) {
51-
query.andWhere('r.created >= :from', { from });
52-
}
53-
54-
return query.getRawMany();
40+
return this.refRewardService.getRewardRecipients(from);
5541
}
5642

5743
async getLatestFinancialChanges(): Promise<FinancialChangesEntryDto | undefined> {

0 commit comments

Comments
 (0)