From 87d1885b58d71c38fa820d6200d0925ed03bdb43 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 28 Oct 2025 14:16:03 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../YieldSupplyChangeTokenStatusBody.kt | 1 + .../supply/DefaultYieldSupplyRepository.kt | 13 +++++----- .../yield/supply/YieldSupplyRepository.kt | 4 +-- .../usecase/YieldSupplyActivateUseCase.kt | 9 ++++--- .../usecase/YieldSupplyDeactivateUseCase.kt | 9 ++++--- .../impl/main/model/YieldSupplyModel.kt | 9 ++++--- .../model/YieldSupplyStartEarningModel.kt | 25 +++++++++++-------- .../model/YieldSupplyStopEarningModel.kt | 18 ++++++++----- 8 files changed, 51 insertions(+), 37 deletions(-) diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/YieldSupplyChangeTokenStatusBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/YieldSupplyChangeTokenStatusBody.kt index 68db0ea530..841ecd9c81 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/YieldSupplyChangeTokenStatusBody.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/YieldSupplyChangeTokenStatusBody.kt @@ -7,4 +7,5 @@ import com.squareup.moshi.JsonClass data class YieldSupplyChangeTokenStatusBody( @Json(name = "tokenAddress") val tokenAddress: String, @Json(name = "chainId") val chainId: Int, + @Json(name = "userAddress") val userAddress: String, ) \ No newline at end of file diff --git a/data/yield-supply/src/main/java/com/tangem/data/yield/supply/DefaultYieldSupplyRepository.kt b/data/yield-supply/src/main/java/com/tangem/data/yield/supply/DefaultYieldSupplyRepository.kt index 4aebbdf08e..082d68a3d2 100644 --- a/data/yield-supply/src/main/java/com/tangem/data/yield/supply/DefaultYieldSupplyRepository.kt +++ b/data/yield-supply/src/main/java/com/tangem/data/yield/supply/DefaultYieldSupplyRepository.kt @@ -5,12 +5,12 @@ import com.tangem.blockchain.yieldsupply.YieldSupplyProvider import com.tangem.blockchainsdk.utils.fromNetworkId import com.tangem.blockchainsdk.utils.toBlockchain import com.tangem.blockchainsdk.utils.toNetworkId -import com.tangem.datasource.api.common.response.getOrThrow -import com.tangem.datasource.local.yieldsupply.YieldMarketsStore import com.tangem.data.yield.supply.converters.YieldMarketTokenConverter -import com.tangem.datasource.api.tangemTech.YieldSupplyApi import com.tangem.data.yield.supply.converters.YieldTokenChartConverter +import com.tangem.datasource.api.common.response.getOrThrow +import com.tangem.datasource.api.tangemTech.YieldSupplyApi import com.tangem.datasource.api.tangemTech.models.YieldSupplyChangeTokenStatusBody +import com.tangem.datasource.local.yieldsupply.YieldMarketsStore import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.walletmanager.WalletManagersFacade @@ -23,7 +23,6 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext import java.util.concurrent.ConcurrentHashMap -import kotlin.collections.map internal class DefaultYieldSupplyRepository( private val yieldSupplyApi: YieldSupplyApi, @@ -77,7 +76,7 @@ internal class DefaultYieldSupplyRepository( (walletManager as? YieldSupplyProvider)?.isSupported() ?: false } - override suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token): Boolean = + 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") @@ -85,11 +84,12 @@ internal class DefaultYieldSupplyRepository( YieldSupplyChangeTokenStatusBody( tokenAddress = cryptoCurrencyToken.contractAddress, chainId = chainId, + userAddress = address, ), ).getOrThrow().isActive } - override suspend fun deactivateProtocol(cryptoCurrencyToken: CryptoCurrency.Token): Boolean = + override suspend fun deactivateProtocol(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") @@ -97,6 +97,7 @@ internal class DefaultYieldSupplyRepository( YieldSupplyChangeTokenStatusBody( tokenAddress = cryptoCurrencyToken.contractAddress, chainId = chainId, + userAddress = address, ), ).getOrThrow().isActive } diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/YieldSupplyRepository.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/YieldSupplyRepository.kt index 58c3c160d8..deb3c44851 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/YieldSupplyRepository.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/YieldSupplyRepository.kt @@ -46,7 +46,7 @@ interface YieldSupplyRepository { * May throw on network/backend errors or if required chain id cannot be resolved. */ @Throws - suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token): Boolean + suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean /** * Deactivate yield protocol for the specified token. @@ -56,7 +56,7 @@ interface YieldSupplyRepository { * network/backend errors or if required chain id cannot be resolved. */ @Throws - suspend fun deactivateProtocol(cryptoCurrencyToken: CryptoCurrency.Token): Boolean + suspend fun deactivateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean /** * Save the last user-initiated yield protocol action for the given currency. diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyActivateUseCase.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyActivateUseCase.kt index 3ca5a7b0e8..5b2126f395 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyActivateUseCase.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyActivateUseCase.kt @@ -8,8 +8,9 @@ class YieldSupplyActivateUseCase( private val yieldSupplyRepository: YieldSupplyRepository, ) { - suspend operator fun invoke(cryptoCurrency: CryptoCurrency): Either = Either.catch { - val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected") - yieldSupplyRepository.activateProtocol(token) - } + suspend operator fun invoke(cryptoCurrency: CryptoCurrency, address: String): Either = + Either.catch { + val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected") + yieldSupplyRepository.activateProtocol(token, address) + } } \ No newline at end of file diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyDeactivateUseCase.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyDeactivateUseCase.kt index fc666ada1a..ba431ae585 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyDeactivateUseCase.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyDeactivateUseCase.kt @@ -8,8 +8,9 @@ class YieldSupplyDeactivateUseCase( private val yieldSupplyRepository: YieldSupplyRepository, ) { - suspend operator fun invoke(cryptoCurrency: CryptoCurrency): Either = Either.catch { - val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected") - yieldSupplyRepository.deactivateProtocol(token) - } + suspend operator fun invoke(cryptoCurrency: CryptoCurrency, address: String): Either = + Either.catch { + val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected") + yieldSupplyRepository.deactivateProtocol(token, address) + } } \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/main/model/YieldSupplyModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/main/model/YieldSupplyModel.kt index 9d5b7885d9..fa03433676 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/main/model/YieldSupplyModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/main/model/YieldSupplyModel.kt @@ -27,19 +27,19 @@ import com.tangem.domain.yield.supply.usecase.YieldSupplyActivateUseCase import com.tangem.domain.yield.supply.usecase.YieldSupplyDeactivateUseCase import com.tangem.domain.yield.supply.usecase.YieldSupplyGetTokenStatusUseCase import com.tangem.domain.yield.supply.usecase.YieldSupplyIsAvailableUseCase -import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.api.YieldSupplyComponent import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics +import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.impl.main.entity.YieldSupplyUM import com.tangem.features.yield.supply.impl.main.model.transformers.YieldSupplyTokenStatusSuccessTransformer import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.DelayedWork +import com.tangem.utils.transformer.update import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import timber.log.Timber -import com.tangem.utils.transformer.update import javax.inject.Inject import kotlin.properties.Delegates @@ -276,13 +276,14 @@ internal class YieldSupplyModel @Inject constructor( private fun sendInfoAboutProtocolStatus(cryptoCurrencyStatus: CryptoCurrencyStatus) { if (lastYieldSupplyStatus == cryptoCurrencyStatus.value.yieldSupplyStatus) return val token = cryptoCurrency as? CryptoCurrency.Token ?: return + val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value ?: return modelScope.launch(dispatchers.default) { if (cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive == true) { - yieldSupplyActivateUseCase(token).onRight { + yieldSupplyActivateUseCase(token, address).onRight { lastYieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus } } else { - yieldSupplyDeactivateUseCase(token).onRight { + yieldSupplyDeactivateUseCase(token, address).onRight { lastYieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus } } diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt index 8e409ddc3d..fdb9493169 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt @@ -22,13 +22,9 @@ import com.tangem.domain.transaction.usecase.SendTransactionUseCase import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.domain.yield.supply.YieldSupplyRepository import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus -import com.tangem.domain.yield.supply.usecase.YieldSupplyActivateUseCase -import com.tangem.domain.yield.supply.usecase.YieldSupplyEstimateEnterFeeUseCase -import com.tangem.domain.yield.supply.usecase.YieldSupplyGetTokenStatusUseCase -import com.tangem.domain.yield.supply.usecase.YieldSupplyMinAmountUseCase -import com.tangem.domain.yield.supply.usecase.YieldSupplyStartEarningUseCase -import com.tangem.features.yield.supply.impl.R +import com.tangem.domain.yield.supply.usecase.* import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics +import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.impl.common.YieldSupplyAlertFactory import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyActionUM import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyFeeUM @@ -234,10 +230,12 @@ internal class YieldSupplyStartEarningModel @Inject constructor( ifLeft = { error -> Timber.e(error.toString()) uiState.update(YieldSupplyTransactionReadyTransformer) - analytics.send(YieldSupplyAnalytics.EarnErrors( - action = YieldSupplyAnalytics.Action.Approve, - errorDescription = error.getAnalyticsDescription(), - )) + analytics.send( + YieldSupplyAnalytics.EarnErrors( + action = YieldSupplyAnalytics.Action.Approve, + errorDescription = error.getAnalyticsDescription(), + ), + ) yieldSupplyAlertFactory.getSendTransactionErrorState( error = error, popBack = params.callback::onBackClick, @@ -255,7 +253,12 @@ internal class YieldSupplyStartEarningModel @Inject constructor( ifRight = { yieldSupplyRepository.saveTokenProtocolStatus(cryptoCurrency, YieldSupplyEnterStatus.Enter) analytics.send(YieldSupplyAnalytics.FundsEarned) - yieldSupplyActivateUseCase(cryptoCurrency) + + val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value + if (address != null) { + yieldSupplyActivateUseCase(cryptoCurrency, address) + } + modelScope.launch { params.callback.onTransactionSent() } diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt index 4ab5059e24..73cfd703d0 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt @@ -20,8 +20,8 @@ import com.tangem.domain.yield.supply.YieldSupplyRepository import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus import com.tangem.domain.yield.supply.usecase.YieldSupplyDeactivateUseCase import com.tangem.domain.yield.supply.usecase.YieldSupplyStopEarningUseCase -import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics +import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.impl.common.YieldSupplyAlertFactory import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyActionUM import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyFeeUM @@ -140,10 +140,12 @@ internal class YieldSupplyStopEarningModel @Inject constructor( ifLeft = { error -> Timber.e(error.toString()) uiState.update(YieldSupplyTransactionReadyTransformer) - analytics.send(YieldSupplyAnalytics.EarnErrors( - action = YieldSupplyAnalytics.Action.Stop, - errorDescription = error.getAnalyticsDescription(), - )) + analytics.send( + YieldSupplyAnalytics.EarnErrors( + action = YieldSupplyAnalytics.Action.Stop, + errorDescription = error.getAnalyticsDescription(), + ), + ) yieldSupplyAlertFactory.getSendTransactionErrorState( error = error, popBack = params.callback::onBackClick, @@ -166,7 +168,11 @@ internal class YieldSupplyStopEarningModel @Inject constructor( blockchain = cryptoCurrency.network.name, ), ) - yieldSupplyDeactivateUseCase(cryptoCurrency) + val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value + if (address != null) { + yieldSupplyDeactivateUseCase(cryptoCurrency, address) + } + modelScope.launch { params.callback.onTransactionSent() }