Updated on 2026-08-14

This commit is contained in:
Tangem 2024-01-31 14:20:41 +03:00
commit 907e239a8a
32 changed files with 152 additions and 96 deletions

View file

@ -19,6 +19,7 @@ dependencies {
kapt(deps.hilt.kapt)
/** Domain */
implementation(projects.domain.appCurrency)
implementation(projects.domain.models)
implementation(projects.domain.tokens)
implementation(projects.domain.tokens.models)

View file

@ -7,6 +7,9 @@ import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.extenstions.unwrap
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
import com.tangem.domain.tokens.GetCryptoCurrencyStatusesSyncUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
@ -55,6 +58,7 @@ internal class SwapInteractorImpl @Inject constructor(
private val quotesRepository: QuotesRepository,
private val dispatcher: CoroutineDispatcherProvider,
private val swapTransactionRepository: SwapTransactionRepository,
private val appCurrencyRepository: AppCurrencyRepository,
private val initialToCurrencyResolver: InitialToCurrencyResolver,
) : SwapInteractor {
@ -62,6 +66,10 @@ internal class SwapInteractorImpl @Inject constructor(
EstimateFeeUseCase(walletManagersFacade, dispatcher)
}
private val getSelectedAppCurrencyUseCase by lazy(LazyThreadSafetyMode.NONE) {
GetSelectedAppCurrencyUseCase(appCurrencyRepository)
}
private val swapCurrencyConverter = SwapCurrencyConverter()
private val amountFormatter = AmountFormatter()
private val hundredPercent = BigInteger("100")
@ -638,8 +646,8 @@ internal class SwapInteractorImpl @Inject constructor(
type = AmountType.Coin,
)
return when (blockchain) {
Blockchain.Ethereum -> {
return when {
blockchain.isEvm() -> {
val feeAmountWithDecimals = feeAmountValue.movePointRight(fee.decimals)
Fee.Ethereum(
amount = feeAmount,
@ -647,11 +655,12 @@ internal class SwapInteractorImpl @Inject constructor(
gasPrice = (feeAmountWithDecimals / fee.gasLimit.toBigDecimal()).toBigInteger(),
)
}
Blockchain.Vechain -> Fee.Vechain(
blockchain == Blockchain.VeChain -> Fee.VeChain(
amount = feeAmount,
gasPriceCoef = fee.gasLimit,
gasPriceCoef = Fee.VeChain.getGasPriceCoef(fee.gasLimit.toLong(), fee.feeValue),
gasLimit = fee.gasLimit.toLong(),
)
Blockchain.Aptos -> {
blockchain == Blockchain.Aptos -> {
Fee.Aptos(
amount = feeAmount,
gasUnitPrice = fee.feeValue.toLong() / fee.gasLimit,
@ -754,8 +763,8 @@ internal class SwapInteractorImpl @Inject constructor(
)
}
private fun createEmptyAmountState(): SwapState {
val appCurrency = userWalletManager.getUserAppCurrency()
private suspend fun createEmptyAmountState(): SwapState {
val appCurrency = getSelectedAppCurrencyUseCase.unwrap()
return SwapState.EmptyAmountState(
zeroAmountEquivalent = BigDecimal.ZERO.toFiatString(
rateValue = BigDecimal.ONE,
@ -947,7 +956,7 @@ internal class SwapInteractorImpl @Inject constructor(
}
private suspend fun getFormattedFiatFees(networkId: String, vararg fees: BigDecimal): List<String> {
val appCurrency = userWalletManager.getUserAppCurrency()
val appCurrency = getSelectedAppCurrencyUseCase.unwrap()
val nativeToken = repository.getNativeTokenForNetwork(networkId)
val rates = getQuotes(nativeToken.id)
return rates[nativeToken.id]?.fiatRate?.let { rate ->
@ -1345,7 +1354,7 @@ internal class SwapInteractorImpl @Inject constructor(
return when (this) {
is Fee.Common -> 0
is Fee.Ethereum -> gasLimit.toInt()
is Fee.Vechain -> gasPriceCoef
is Fee.VeChain -> gasLimit.toInt()
is Fee.Aptos -> amount.longValue?.div(gasUnitPrice)?.toInt() ?: 0
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.feature.swap.domain.di
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
import com.tangem.domain.card.repository.CardSdkConfigRepository
import com.tangem.domain.demo.DemoConfig
import com.tangem.domain.demo.IsDemoCardUseCase
@ -40,6 +41,7 @@ class SwapDomainModule {
@SwapScope sendTransactionUseCase: SendTransactionUseCase,
quotesRepository: QuotesRepository,
swapTransactionRepository: SwapTransactionRepository,
appCurrencyRepository: AppCurrencyRepository,
walletManagersFacade: WalletManagersFacade,
coroutineDispatcherProvider: CoroutineDispatcherProvider,
initialToCurrencyResolver: InitialToCurrencyResolver,
@ -56,6 +58,7 @@ class SwapDomainModule {
walletManagersFacade = walletManagersFacade,
dispatcher = coroutineDispatcherProvider,
swapTransactionRepository = swapTransactionRepository,
appCurrencyRepository = appCurrencyRepository,
initialToCurrencyResolver = initialToCurrencyResolver,
)
}