diff --git a/src/subdomains/core/buy-crypto/process/services/buy-crypto-preparation.service.ts b/src/subdomains/core/buy-crypto/process/services/buy-crypto-preparation.service.ts index 2d3ee947f5..b9f7f5ee58 100644 --- a/src/subdomains/core/buy-crypto/process/services/buy-crypto-preparation.service.ts +++ b/src/subdomains/core/buy-crypto/process/services/buy-crypto-preparation.service.ts @@ -205,7 +205,7 @@ export class BuyCryptoPreparationService { cryptoInput: true, buy: true, cryptoRoute: true, - transaction: { user: { wallet: true, userData: true }, userData: true }, + transaction: { user: { wallet: true }, userData: true }, }, }); @@ -240,6 +240,7 @@ export class BuyCryptoPreparationService { bankIn, undefined, entity.user, + entity.userData, ); const maxNetworkFee = fee.network ? fee.network : referenceChfPrice.invert().convert(Config.maxBlockchainFee); diff --git a/src/subdomains/core/history/controllers/transaction.controller.ts b/src/subdomains/core/history/controllers/transaction.controller.ts index a911434407..9ad556ed7c 100644 --- a/src/subdomains/core/history/controllers/transaction.controller.ts +++ b/src/subdomains/core/history/controllers/transaction.controller.ts @@ -304,7 +304,7 @@ export class TransactionController { cryptoInput: true, checkoutTx: true, bankTxReturn: true, - userData: true, + userData: { wallet: true }, buyCrypto: { cryptoInput: true, bankTx: true, checkoutTx: true }, buyFiat: { cryptoInput: true }, refReward: true, diff --git a/src/subdomains/core/sell-crypto/process/services/buy-fiat-preparation.service.ts b/src/subdomains/core/sell-crypto/process/services/buy-fiat-preparation.service.ts index 85c8d2adca..554ea26dc5 100644 --- a/src/subdomains/core/sell-crypto/process/services/buy-fiat-preparation.service.ts +++ b/src/subdomains/core/sell-crypto/process/services/buy-fiat-preparation.service.ts @@ -159,7 +159,7 @@ export class BuyFiatPreparationService { relations: { sell: true, cryptoInput: true, - transaction: { user: { wallet: true, userData: true }, userData: true }, + transaction: { user: { wallet: true }, userData: true }, }, }); @@ -185,6 +185,7 @@ export class BuyFiatPreparationService { undefined, IbanBankName.MAERKI, entity.user, + entity.userData, ); await this.buyFiatRepo.update( diff --git a/src/subdomains/generic/user/models/user/user.service.ts b/src/subdomains/generic/user/models/user/user.service.ts index 262e3bfb10..37a8905fa0 100644 --- a/src/subdomains/generic/user/models/user/user.service.ts +++ b/src/subdomains/generic/user/models/user/user.service.ts @@ -418,7 +418,8 @@ export class UserService { if (!user) throw new NotFoundException('User not found'); return this.feeService.getUserFee({ - user, + userData: user.userData, + wallet: user.wallet, paymentMethodIn, paymentMethodOut, from, diff --git a/src/subdomains/supporting/payment/services/fee.service.ts b/src/subdomains/supporting/payment/services/fee.service.ts index 1975323bc7..a249a2723d 100644 --- a/src/subdomains/supporting/payment/services/fee.service.ts +++ b/src/subdomains/supporting/payment/services/fee.service.ts @@ -30,7 +30,8 @@ import { BlockchainFeeRepository } from '../repositories/blockchain-fee.reposito import { FeeRepository } from '../repositories/fee.repository'; export interface UserFeeRequest extends FeeRequestBase { - user: User; + userData: UserData; + wallet: Wallet; } export interface FeeRequest extends FeeRequestBase { @@ -40,7 +41,6 @@ export interface FeeRequest extends FeeRequestBase { } export interface OptionalFeeRequest extends FeeRequestBase { - user?: User; userData?: UserData; wallet?: Wallet; accountType?: AccountType; @@ -230,7 +230,7 @@ export class FeeService { request.from, request.to, request.allowCachedBlockchainFee, - request.user.userData?.id, + request.userData?.id, ); } catch (e) { this.logger.error(`Fee exception, request: ${JSON.stringify(request)}`); @@ -438,15 +438,8 @@ export class FeeService { } private async getValidFees(request: OptionalFeeRequest): Promise { - const accountType = - request.user?.userData?.accountType ?? - request.userData?.accountType ?? - request.accountType ?? - AccountType.PERSONAL; - const wallet = request.wallet ?? request.user?.wallet; - const userDataId = request.user?.userData?.id ?? request.userData?.id; - - const discountFeeIds = request.user?.userData?.individualFeeList ?? request.userData?.individualFeeList ?? []; + const accountType = request.userData?.accountType ?? request.accountType ?? AccountType.PERSONAL; + const discountFeeIds = request.userData?.individualFeeList ?? []; const userFees = await this.getAllFees().then((fees) => fees.filter( @@ -464,15 +457,17 @@ export class FeeService { !f.specialCode) || discountFeeIds.includes(f.id) || request.specialCodes.includes(f.specialCode) || - (f.wallet && f.wallet.id === wallet?.id), + (f.wallet && f.wallet.id === request.wallet?.id), ), ); // remove ExpiredFee userFees - .filter((fee) => discountFeeIds.includes(fee.id) && fee.isExpired(userDataId)) - .forEach((fee) => this.userDataService.removeFee(request.user?.userData ?? request.userData, fee.id)); + .filter((fee) => discountFeeIds.includes(fee.id) && fee.isExpired(request.userData?.id)) + .forEach((fee) => this.userDataService.removeFee(request.userData, fee.id)); - return userFees.filter((fee) => fee.verifyForTx({ ...request, accountType, wallet, userDataId })); + return userFees.filter((fee) => + fee.verifyForTx({ ...request, accountType, wallet: request.wallet, userDataId: request.userData?.id }), + ); } } diff --git a/src/subdomains/supporting/payment/services/transaction-helper.ts b/src/subdomains/supporting/payment/services/transaction-helper.ts index 321b357979..68cd7ba269 100644 --- a/src/subdomains/supporting/payment/services/transaction-helper.ts +++ b/src/subdomains/supporting/payment/services/transaction-helper.ts @@ -196,11 +196,13 @@ export class TransactionHelper implements OnModuleInit { bankIn: CardBankName | IbanBankName | undefined, bankOut: CardBankName | IbanBankName | undefined, user: User, + userData: UserData, ): Promise { // get fee const [fee, networkStartFee] = await this.getAllFees( user, - undefined, + userData, + user.wallet, paymentMethodIn, paymentMethodOut, bankIn, @@ -271,6 +273,7 @@ export class TransactionHelper implements OnModuleInit { // get fee const [fee, networkStartFee] = await this.getAllFees( user, + user.userData, wallet, paymentMethodIn, paymentMethodOut, @@ -406,6 +409,7 @@ export class TransactionHelper implements OnModuleInit { specialCodes: [], allowCachedBlockchainFee: false, userData, + wallet: userData.wallet, }); const dfxFeeAmount = inputAmount * chargebackFee.rate + price.convert(chargebackFee.fixed); @@ -514,6 +518,7 @@ export class TransactionHelper implements OnModuleInit { private async getAllFees( user: User | undefined, + userData: UserData | undefined, wallet: Wallet | undefined, paymentMethodIn: PaymentMethod, paymentMethodOut: PaymentMethod, @@ -528,7 +533,7 @@ export class TransactionHelper implements OnModuleInit { ): Promise<[InternalFeeDto, number]> { const [fee, networkStartFee] = await Promise.all([ this.getTxFee( - user, + userData, wallet, paymentMethodIn, paymentMethodOut, @@ -586,7 +591,7 @@ export class TransactionHelper implements OnModuleInit { } private async getTxFee( - user: User | undefined, + userData: UserData | undefined, wallet: Wallet | undefined, paymentMethodIn: PaymentMethod, paymentMethodOut: PaymentMethod, @@ -599,7 +604,7 @@ export class TransactionHelper implements OnModuleInit { allowCachedBlockchainFee: boolean, ): Promise { const feeRequest: UserFeeRequest = { - user, + userData, wallet, paymentMethodIn, paymentMethodOut, @@ -612,7 +617,7 @@ export class TransactionHelper implements OnModuleInit { allowCachedBlockchainFee, }; - return user ? this.feeService.getUserFee(feeRequest) : this.feeService.getDefaultFee(feeRequest); + return userData ? this.feeService.getUserFee(feeRequest) : this.feeService.getDefaultFee(feeRequest); } private async getTargetEstimation(