diff --git a/src/subdomains/core/buy-crypto/routes/buy/buy.controller.ts b/src/subdomains/core/buy-crypto/routes/buy/buy.controller.ts index a30b13b6b..95a9e9dd6 100644 --- a/src/subdomains/core/buy-crypto/routes/buy/buy.controller.ts +++ b/src/subdomains/core/buy-crypto/routes/buy/buy.controller.ts @@ -124,6 +124,7 @@ export class BuyController { CryptoPaymentMethod.CRYPTO, true, undefined, + dto.wallet, specialCode ? [specialCode] : [], ); diff --git a/src/subdomains/core/buy-crypto/routes/buy/dto/get-buy-quote.dto.ts b/src/subdomains/core/buy-crypto/routes/buy/dto/get-buy-quote.dto.ts index e37be0794..7dee7be6a 100644 --- a/src/subdomains/core/buy-crypto/routes/buy/dto/get-buy-quote.dto.ts +++ b/src/subdomains/core/buy-crypto/routes/buy/dto/get-buy-quote.dto.ts @@ -58,4 +58,9 @@ export class GetBuyQuoteDto { @IsOptional() @IsString() specialCode: string; + + @ApiPropertyOptional() + @IsOptional() + @IsString() + wallet: string; } diff --git a/src/subdomains/core/buy-crypto/routes/swap/dto/get-swap-quote.dto.ts b/src/subdomains/core/buy-crypto/routes/swap/dto/get-swap-quote.dto.ts index b5c841ad1..7cb2fbda9 100644 --- a/src/subdomains/core/buy-crypto/routes/swap/dto/get-swap-quote.dto.ts +++ b/src/subdomains/core/buy-crypto/routes/swap/dto/get-swap-quote.dto.ts @@ -50,4 +50,9 @@ export class GetSwapQuoteDto { @IsOptional() @IsString() specialCode: string; + + @ApiPropertyOptional() + @IsOptional() + @IsString() + wallet: string; } diff --git a/src/subdomains/core/buy-crypto/routes/swap/swap.controller.ts b/src/subdomains/core/buy-crypto/routes/swap/swap.controller.ts index 0245956ad..10cc0095b 100644 --- a/src/subdomains/core/buy-crypto/routes/swap/swap.controller.ts +++ b/src/subdomains/core/buy-crypto/routes/swap/swap.controller.ts @@ -117,6 +117,7 @@ export class SwapController { CryptoPaymentMethod.CRYPTO, true, undefined, + dto.wallet, specialCode ? [specialCode] : [], ); diff --git a/src/subdomains/core/sell-crypto/route/dto/get-sell-quote.dto.ts b/src/subdomains/core/sell-crypto/route/dto/get-sell-quote.dto.ts index e629a952e..e8809b11c 100644 --- a/src/subdomains/core/sell-crypto/route/dto/get-sell-quote.dto.ts +++ b/src/subdomains/core/sell-crypto/route/dto/get-sell-quote.dto.ts @@ -51,4 +51,9 @@ export class GetSellQuoteDto { @IsOptional() @IsString() specialCode: string; + + @ApiPropertyOptional() + @IsOptional() + @IsString() + wallet: string; } diff --git a/src/subdomains/core/sell-crypto/route/sell.controller.ts b/src/subdomains/core/sell-crypto/route/sell.controller.ts index c25ccc83a..48f19f54b 100644 --- a/src/subdomains/core/sell-crypto/route/sell.controller.ts +++ b/src/subdomains/core/sell-crypto/route/sell.controller.ts @@ -120,6 +120,7 @@ export class SellController { FiatPaymentMethod.BANK, true, undefined, + dto.wallet, specialCode ? [specialCode] : [], ); diff --git a/src/subdomains/supporting/payment/services/fee.service.ts b/src/subdomains/supporting/payment/services/fee.service.ts index 408135184..297d3e116 100644 --- a/src/subdomains/supporting/payment/services/fee.service.ts +++ b/src/subdomains/supporting/payment/services/fee.service.ts @@ -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; @@ -400,7 +402,7 @@ export class FeeService implements OnModuleInit { private async getValidFees(request: OptionalFeeRequest): Promise { 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 ?? []; diff --git a/src/subdomains/supporting/payment/services/transaction-helper.ts b/src/subdomains/supporting/payment/services/transaction-helper.ts index e9f51d2fd..4a63cca18 100644 --- a/src/subdomains/supporting/payment/services/transaction-helper.ts +++ b/src/subdomains/supporting/payment/services/transaction-helper.ts @@ -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'; @@ -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() { @@ -165,7 +168,19 @@ export class TransactionHelper implements OnModuleInit { ): Promise { // 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), ]); @@ -210,6 +225,7 @@ export class TransactionHelper implements OnModuleInit { paymentMethodOut: PaymentMethod, allowExpiredPrice: boolean, user?: User, + walletName?: string, specialCodes: string[] = [], ): Promise { const txAsset = targetAmount ? to : from; @@ -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, @@ -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, @@ -372,6 +392,7 @@ export class TransactionHelper implements OnModuleInit { ): Promise { const feeRequest: UserFeeRequest = { user, + wallet, paymentMethodIn, paymentMethodOut, bankIn,