Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-27 19:53:49 +05:00
parent 68f800a495
commit 2883c49098
32 changed files with 578 additions and 634 deletions

View file

@ -70,7 +70,7 @@ class YieldSupplyEstimateEnterFeeUseCase(
if (estimatedFees.estimatedGasList.isEmpty()) return null
val fee = feeRepository.getEthereumFeeWithoutGas(
userWallet = userWallet,
userWalletId = userWallet.walletId,
cryptoCurrency = cryptoCurrency,
)

View file

@ -2,14 +2,14 @@ package com.tangem.domain.yield.supply.usecase
import arrow.core.Either
import arrow.core.Either.Companion.catch
import com.tangem.domain.yield.supply.fixFee
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.quote.QuoteStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.quotes.QuotesRepository
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.transaction.FeeRepository
import com.tangem.domain.yield.supply.YieldSupplyConst.YIELD_SUPPLY_EVM_CONSTANT_GAS_LIMIT
import com.tangem.domain.yield.supply.fixFee
import java.math.BigDecimal
import java.math.RoundingMode
@ -23,16 +23,16 @@ class YieldSupplyGetCurrentFeeUseCase(
) {
suspend operator fun invoke(
userWallet: UserWallet,
userWalletId: UserWalletId,
cryptoCurrencyStatus: CryptoCurrencyStatus,
): Either<Throwable, BigDecimal> = catch {
val feeWithoutGas = feeRepository.getEthereumFeeWithoutGas(userWallet, cryptoCurrencyStatus.currency)
val feeWithoutGas = feeRepository.getEthereumFeeWithoutGas(userWalletId, cryptoCurrencyStatus.currency)
val fiatRate = cryptoCurrencyStatus.value.fiatRate ?: error("Fiat rate is missing")
require(fiatRate > BigDecimal.ZERO) { "Fiat rate for token must be > 0" }
val nativeCryptoCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
userWalletId = userWalletId,
networkId = cryptoCurrencyStatus.currency.network.id,
derivationPath = cryptoCurrencyStatus.currency.network.derivationPath,
)

View file

@ -6,7 +6,7 @@ import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.currency.yieldSupplyKey
import com.tangem.domain.models.quote.QuoteStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.quotes.QuotesRepository
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.yield.supply.YieldSupplyRepository
@ -32,7 +32,7 @@ class YieldSupplyGetMaxFeeUseCase(
) {
suspend operator fun invoke(
userWallet: UserWallet,
userWalletId: UserWalletId,
cryptoCurrencyStatus: CryptoCurrencyStatus,
): Either<Throwable, YieldSupplyMaxFee> = catch {
val token = cryptoCurrencyStatus.currency as? CryptoCurrency.Token
@ -42,7 +42,7 @@ class YieldSupplyGetMaxFeeUseCase(
require(fiatRate > BigDecimal.ZERO) { "Fiat rate for token must be > 0" }
val nativeCryptoCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
userWalletId = userWalletId,
networkId = cryptoCurrencyStatus.currency.network.id,
derivationPath = cryptoCurrencyStatus.currency.network.derivationPath,
)

View file

@ -2,14 +2,14 @@ package com.tangem.domain.yield.supply.usecase
import arrow.core.Either
import arrow.core.Either.Companion.catch
import com.tangem.domain.yield.supply.fixFee
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.quote.QuoteStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.quotes.QuotesRepository
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.transaction.FeeRepository
import com.tangem.domain.yield.supply.YieldSupplyConst.YIELD_SUPPLY_EVM_CONSTANT_GAS_LIMIT
import com.tangem.domain.yield.supply.fixFee
import java.math.BigDecimal
import java.math.RoundingMode
@ -20,16 +20,16 @@ class YieldSupplyMinAmountUseCase(
) {
suspend operator fun invoke(
userWallet: UserWallet,
userWalletId: UserWalletId,
cryptoCurrencyStatus: CryptoCurrencyStatus,
): Either<Throwable, BigDecimal> = catch {
val feeWithoutGas = feeRepository.getEthereumFeeWithoutGas(userWallet, cryptoCurrencyStatus.currency)
val feeWithoutGas = feeRepository.getEthereumFeeWithoutGas(userWalletId, cryptoCurrencyStatus.currency)
val fiatRate = cryptoCurrencyStatus.value.fiatRate ?: error("Fiat rate is missing")
require(fiatRate > BigDecimal.ZERO) { "Fiat rate for token must be > 0" }
val nativeCryptoCurrency = currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
userWalletId = userWalletId,
networkId = cryptoCurrencyStatus.currency.network.id,
derivationPath = cryptoCurrencyStatus.currency.network.derivationPath,
)

View file

@ -34,7 +34,9 @@ class YieldSupplyEstimateEnterFeeUseCaseTest {
private val blockAidGasEstimate: BlockAidGasEstimate = mockk()
private val useCase = YieldSupplyEstimateEnterFeeUseCase(feeRepository, feeErrorResolver, blockAidGasEstimate)
private val userWallet: UserWallet = mockk()
private val userWallet: UserWallet = mockk {
every { walletId } returns mockk()
}
private val cryptoCurrency: CryptoCurrency = mockk(relaxed = true) {
every { decimals } returns 18
}

View file

@ -65,7 +65,7 @@ class YieldSupplyMinAmountUseCaseTest {
val maxFeePerGas = BigInteger("158320679232")
val fee = createEip1559Fee(maxFeePerGas)
coEvery { feeRepository.getEthereumFeeWithoutGas(userWallet, token) } returns fee
coEvery { feeRepository.getEthereumFeeWithoutGas(userWallet.walletId, token) } returns fee
coEvery {
currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
@ -88,7 +88,7 @@ class YieldSupplyMinAmountUseCaseTest {
),
)
val expected = expectedMinAmount(maxFeePerGas, nativeFiatRate, tokenFiatRate, token.decimals)
val result = useCase(userWallet, tokenStatus).getOrNull()
val result = useCase(userWallet.walletId, tokenStatus).getOrNull()
Truth.assertThat(result).isEqualTo(expected)
}
@ -114,7 +114,7 @@ class YieldSupplyMinAmountUseCaseTest {
),
)
val userWallet = createUserWallet()
val result = useCase(userWallet, tokenStatus)
val result = useCase(userWallet.walletId, tokenStatus)
Truth.assertThat(result.isLeft()).isTrue()
Truth.assertThat(result.leftOrNull()?.message).isEqualTo("Fiat rate is missing")
}
@ -145,7 +145,7 @@ class YieldSupplyMinAmountUseCaseTest {
val maxFeePerGas = BigInteger("158320679232")
val fee = createEip1559Fee(maxFeePerGas)
coEvery { feeRepository.getEthereumFeeWithoutGas(userWallet, token) } returns fee
coEvery { feeRepository.getEthereumFeeWithoutGas(userWallet.walletId, token) } returns fee
coEvery {
currenciesRepository.getNetworkCoin(
userWalletId = userWallet.walletId,
@ -157,7 +157,7 @@ class YieldSupplyMinAmountUseCaseTest {
coEvery {
quotesRepository.getMultiQuoteSyncOrNull(setOf(nativeCoin.id.rawCurrencyId!!))
} returns null
val result = useCase(userWallet, tokenStatus)
val result = useCase(userWallet.walletId, tokenStatus)
Truth.assertThat(result.isLeft()).isTrue()
Truth.assertThat(result.leftOrNull()?.message).isEqualTo("Quotes for native coin are unavailable")
}