Skip to content

Commit

Permalink
[DEV-3501] integrate wallet in quote (#1884)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick1712 authored Jan 6, 2025
1 parent 85412ed commit b2649c7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class BuyController {
CryptoPaymentMethod.CRYPTO,
true,
undefined,
dto.wallet,
specialCode ? [specialCode] : [],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ export class GetBuyQuoteDto {
@IsOptional()
@IsString()
specialCode: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
wallet: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ export class GetSwapQuoteDto {
@IsOptional()
@IsString()
specialCode: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
wallet: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class SwapController {
CryptoPaymentMethod.CRYPTO,
true,
undefined,
dto.wallet,
specialCode ? [specialCode] : [],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ export class GetSellQuoteDto {
@IsOptional()
@IsString()
specialCode: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
wallet: string;
}
1 change: 1 addition & 0 deletions src/subdomains/core/sell-crypto/route/sell.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class SellController {
FiatPaymentMethod.BANK,
true,
undefined,
dto.wallet,
specialCode ? [specialCode] : [],
);

Expand Down
4 changes: 3 additions & 1 deletion src/subdomains/supporting/payment/services/fee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export interface FeeRequest extends FeeRequestBase {

export interface OptionalFeeRequest extends FeeRequestBase {
user?: User;
wallet?: Wallet;
accountType?: AccountType;
}

export interface FeeRequestBase {
wallet?: Wallet;
paymentMethodIn: PaymentMethod;
paymentMethodOut: PaymentMethod;
bankIn: CardBankName | IbanBankName;
Expand Down Expand Up @@ -400,7 +402,7 @@ export class FeeService implements OnModuleInit {

private async getValidFees(request: OptionalFeeRequest): Promise<Fee[]> {
const accountType = request.user?.userData?.accountType ?? request.accountType ?? AccountType.PERSONAL;
const wallet = request.user?.wallet;
const wallet = request.wallet ?? request.user?.wallet;
const userDataId = request.user?.userData?.id;

const discountFeeIds = request.user?.userData?.individualFeeList ?? [];
Expand Down
23 changes: 22 additions & 1 deletion src/subdomains/supporting/payment/services/transaction-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { BuyCryptoService } from 'src/subdomains/core/buy-crypto/process/service
import { BuyFiatService } from 'src/subdomains/core/sell-crypto/process/services/buy-fiat.service';
import { KycLevel, UserDataStatus } from 'src/subdomains/generic/user/models/user-data/user-data.entity';
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { Wallet } from 'src/subdomains/generic/user/models/wallet/wallet.entity';
import { WalletService } from 'src/subdomains/generic/user/models/wallet/wallet.service';
import { MinAmount } from 'src/subdomains/supporting/payment/dto/transaction-helper/min-amount.dto';
import { FeeService, UserFeeRequest } from 'src/subdomains/supporting/payment/services/fee.service';
import { Price } from 'src/subdomains/supporting/pricing/domain/entities/price';
Expand Down Expand Up @@ -47,6 +49,7 @@ export class TransactionHelper implements OnModuleInit {
private readonly buyCryptoService: BuyCryptoService,
private readonly buyFiatService: BuyFiatService,
private readonly blockchainRegistryService: BlockchainRegistryService,
private readonly walletService: WalletService,
) {}

onModuleInit() {
Expand Down Expand Up @@ -165,7 +168,19 @@ export class TransactionHelper implements OnModuleInit {
): Promise<InternalFeeDto & FeeDto> {
// get fee
const [fee, networkStartFee] = await Promise.all([
this.getTxFee(user, paymentMethodIn, paymentMethodOut, bankIn, bankOut, from, to, inputAmountChf, [], false),
this.getTxFee(
user,
undefined,
paymentMethodIn,
paymentMethodOut,
bankIn,
bankOut,
from,
to,
inputAmountChf,
[],
false,
),
this.getNetworkStartFee(to, false, user),
]);

Expand Down Expand Up @@ -210,6 +225,7 @@ export class TransactionHelper implements OnModuleInit {
paymentMethodOut: PaymentMethod,
allowExpiredPrice: boolean,
user?: User,
walletName?: string,
specialCodes: string[] = [],
): Promise<TransactionDetails> {
const txAsset = targetAmount ? to : from;
Expand All @@ -221,10 +237,13 @@ export class TransactionHelper implements OnModuleInit {
const bankIn = this.getDefaultBankByPaymentMethod(paymentMethodIn);
const bankOut = this.getDefaultBankByPaymentMethod(paymentMethodOut);

const wallet = walletName ? await this.walletService.getByIdOrName(undefined, walletName) : undefined;

// get fee
const [fee, networkStartFee] = await Promise.all([
this.getTxFee(
user,
wallet,
paymentMethodIn,
paymentMethodOut,
bankIn,
Expand Down Expand Up @@ -360,6 +379,7 @@ export class TransactionHelper implements OnModuleInit {

private async getTxFee(
user: User | undefined,
wallet: Wallet | undefined,
paymentMethodIn: PaymentMethod,
paymentMethodOut: PaymentMethod,
bankIn: CardBankName | IbanBankName,
Expand All @@ -372,6 +392,7 @@ export class TransactionHelper implements OnModuleInit {
): Promise<InternalFeeDto> {
const feeRequest: UserFeeRequest = {
user,
wallet,
paymentMethodIn,
paymentMethodOut,
bankIn,
Expand Down

0 comments on commit b2649c7

Please sign in to comment.