Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-06 22:12:26 +05:00
parent 3c80a53254
commit 5514e3a195
7 changed files with 48 additions and 22 deletions

View file

@ -8,6 +8,7 @@ import com.tangem.datasource.api.tangemTech.models.YieldSupplyMarketTokenDto
import com.tangem.datasource.api.tangemTech.models.YieldTokenChartResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query
@ -34,6 +35,7 @@ interface YieldSupplyApi {
@POST("api/v1/module/activate")
suspend fun activateYieldModule(
@Body body: YieldSupplyChangeTokenStatusBody,
@Header("userWalletId") userWalletId: String,
): ApiResponse<YieldModuleStatusResponse>
@POST("api/v1/module/deactivate")

View file

@ -76,18 +76,22 @@ internal class DefaultYieldSupplyRepository(
(walletManager as? YieldSupplyProvider)?.isSupported() ?: false
}
override suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean =
withContext(dispatchers.io) {
val chainId = Blockchain.fromNetworkId(cryptoCurrencyToken.network.backendId)?.getChainId()
?: error("Chain id is required for evm's")
yieldSupplyApi.activateYieldModule(
YieldSupplyChangeTokenStatusBody(
tokenAddress = cryptoCurrencyToken.contractAddress,
chainId = chainId,
userAddress = address,
),
).getOrThrow().isActive
}
override suspend fun activateProtocol(
userWalletId: UserWalletId,
cryptoCurrencyToken: CryptoCurrency.Token,
address: String,
): Boolean = withContext(dispatchers.io) {
val chainId = Blockchain.fromNetworkId(cryptoCurrencyToken.network.backendId)?.getChainId()
?: error("Chain id is required for evm's")
yieldSupplyApi.activateYieldModule(
body = YieldSupplyChangeTokenStatusBody(
tokenAddress = cryptoCurrencyToken.contractAddress,
chainId = chainId,
userAddress = address,
),
userWalletId = userWalletId.stringValue,
).getOrThrow().isActive
}
override suspend fun deactivateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean =
withContext(dispatchers.io) {

View file

@ -46,7 +46,11 @@ interface YieldSupplyRepository {
* May throw on network/backend errors or if required chain id cannot be resolved.
*/
@Throws
suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean
suspend fun activateProtocol(
userWalletId: UserWalletId,
cryptoCurrencyToken: CryptoCurrency.Token,
address: String,
): Boolean
/**
* Deactivate yield protocol for the specified token.

View file

@ -2,15 +2,23 @@ package com.tangem.domain.yield.supply.usecase
import arrow.core.Either
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.yield.supply.YieldSupplyRepository
class YieldSupplyActivateUseCase(
private val yieldSupplyRepository: YieldSupplyRepository,
) {
suspend operator fun invoke(cryptoCurrency: CryptoCurrency, address: String): Either<Throwable, Boolean> =
Either.catch {
val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected")
yieldSupplyRepository.activateProtocol(token, address)
}
suspend operator fun invoke(
userWalletId: UserWalletId,
cryptoCurrency: CryptoCurrency,
address: String,
): Either<Throwable, Boolean> = Either.catch {
val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected")
yieldSupplyRepository.activateProtocol(
userWalletId = userWalletId,
cryptoCurrencyToken = token,
address = address,
)
}
}

View file

@ -311,7 +311,11 @@ internal class YieldSupplyModel @Inject constructor(
val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value ?: return
modelScope.launch(dispatchers.default) {
if (cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive == true) {
yieldSupplyActivateUseCase(token, address).onRight {
yieldSupplyActivateUseCase(
userWalletId = userWallet.walletId,
cryptoCurrency = token,
address = address,
).onRight {
lastYieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus
}
} else {

View file

@ -278,7 +278,11 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value
if (address != null) {
yieldSupplyActivateUseCase(cryptoCurrency, address)
yieldSupplyActivateUseCase(
userWalletId = userWallet.walletId,
cryptoCurrency = cryptoCurrency,
address = address,
)
}
modelScope.launch {

View file

@ -37,11 +37,11 @@ internal class YieldSupplyStartEarningFeeContentTransformer(
val feeFiat = feeFiatRate?.let(feeValue::multiply)
val feeFiatValueText = feeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }
val estimatedFeeFiat = feeFiatRate?.let(estimatedFeeValue::multiply)
val estimatedFeeFiat = estimatedFeeValue
val estimatedFeeFiatValueText = estimatedFeeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }
val tokenCryptoFee = tokenFiatRate?.let { rate ->
estimatedFeeFiat?.divide(rate, cryptoCurrency.decimals, RoundingMode.HALF_UP)
estimatedFeeFiat.divide(rate, cryptoCurrency.decimals, RoundingMode.HALF_UP)
}
val tokenCryptoFeeValueText = tokenCryptoFee.format { crypto(cryptoCurrency) }
val tokenFiatFeeValueText = estimatedFeeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }