From 63125dc0f3c082943629a3c101ec239a121ecfef Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 17 Oct 2025 16:01:41 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../DefaultCurrencyChecksRepository.kt | 18 +++++---- .../tokens/GetCurrencyWarningsUseCase.kt | 2 +- .../repository/CurrencyChecksRepository.kt | 2 +- ...okenDetailsNotificationsAnalyticsSender.kt | 2 +- .../api/analytics/YieldSupplyAnalytics.kt | 37 ++++++++++++------- .../approve/model/YieldSupplyApproveModel.kt | 5 +++ .../model/YieldSupplyStopEarningModel.kt | 11 ++++++ 7 files changed, 54 insertions(+), 23 deletions(-) diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrencyChecksRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrencyChecksRepository.kt index 362d59b4a9..3583ff7332 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrencyChecksRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrencyChecksRepository.kt @@ -165,19 +165,23 @@ internal class DefaultCurrencyChecksRepository( } } - override suspend fun getProtocolBalance(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): BigDecimal? { - require(cryptoCurrency is CryptoCurrency.Token) + override suspend fun getProtocolBalance( + userWalletId: UserWalletId, + cryptoCurrencyStatus: CryptoCurrencyStatus, + ): BigDecimal? { + val token = cryptoCurrencyStatus.currency as? CryptoCurrency.Token ?: return null + if (cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive == false) return null return runCatching { val walletManager = walletManagersFacade.getOrCreateWalletManager( userWalletId = userWalletId, - blockchain = cryptoCurrency.network.toBlockchain(), - derivationPath = cryptoCurrency.network.derivationPath.value, + blockchain = token.network.toBlockchain(), + derivationPath = token.network.derivationPath.value, ) ?: error("Wallet manager not found") walletManager.getProtocolBalance( token = Token( - symbol = cryptoCurrency.symbol, - contractAddress = cryptoCurrency.contractAddress, - decimals = cryptoCurrency.decimals, + symbol = token.symbol, + contractAddress = token.contractAddress, + decimals = token.decimals, ), ) }.onFailure(Timber::e).getOrThrow() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index 3afc61c48b..d491aff2a6 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -51,7 +51,7 @@ class GetCurrencyWarningsUseCase( flowOf(currencyChecksRepository.getRentInfoWarning(userWalletId, currencyStatus)), flowOf(currencyChecksRepository.getExistentialDeposit(userWalletId, currency.network)), flowOf(currencyChecksRepository.getFeeResourceAmount(userWalletId, currency.network)), - flowOf(currencyChecksRepository.getProtocolBalance(userWalletId, currency)), + flowOf(currencyChecksRepository.getProtocolBalance(userWalletId, currencyStatus)), ) { coinRelatedWarnings, maybeRentWarning, maybeEdWarning, maybeFeeResource, yieldSupplyProtocolBalance -> setOfNotNull( maybeRentWarning, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrencyChecksRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrencyChecksRepository.kt index 46307255e9..d1b4b99d81 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrencyChecksRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrencyChecksRepository.kt @@ -67,5 +67,5 @@ interface CurrencyChecksRepository { * This represents the amount supplied to the protocol for the specified `userWalletId` * (e.g., aTokens balance). Returns null if not applicable or unknown. */ - suspend fun getProtocolBalance(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): BigDecimal? + suspend fun getProtocolBalance(userWalletId: UserWalletId, cryptoCurrencyStatus: CryptoCurrencyStatus): BigDecimal? } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/analytics/TokenDetailsNotificationsAnalyticsSender.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/analytics/TokenDetailsNotificationsAnalyticsSender.kt index 3eba98c4e1..ad3fcd0c4e 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/analytics/TokenDetailsNotificationsAnalyticsSender.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/analytics/TokenDetailsNotificationsAnalyticsSender.kt @@ -45,7 +45,7 @@ internal class TokenDetailsNotificationsAnalyticsSender( is TokenDetailsNotification.KaspaIncompleteTransactionWarning -> TokenDetailsAnalyticsEvent.Notice.Reveal( currency = cryptoCurrency, ) - is TokenDetailsNotification.YieldSupplyNotTransferedToAave -> YieldSupplyAnalytics.NoticeNotEnoughMinAmount( + is TokenDetailsNotification.YieldSupplyNotTransferedToAave -> YieldSupplyAnalytics.NoticeAmountNotDeposited( token = cryptoCurrency.symbol, blockchain = cryptoCurrency.network.name, ) diff --git a/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt index faddabab9e..596a7bb892 100644 --- a/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt +++ b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt @@ -33,6 +33,17 @@ sealed class YieldSupplyAnalytics( ), ) + data class StopEarningScreen( + val token: String, + val blockchain: String, + ) : YieldSupplyAnalytics( + event = "Stop Earning Screen", + params = mapOf( + TOKEN_PARAM to token, + BLOCKCHAIN to blockchain, + ), + ) + data class ButtonStartEarning( val token: String, val blockchain: String, @@ -55,6 +66,17 @@ sealed class YieldSupplyAnalytics( ), ) + data class ButtonGiveApprove( + val token: String, + val blockchain: String, + ) : YieldSupplyAnalytics( + event = " Button - Give Approve", + params = mapOf( + TOKEN_PARAM to token, + BLOCKCHAIN to blockchain, + ), + ) + data object ButtonFeePolicy : YieldSupplyAnalytics( event = "Button - Fee Policy", ) @@ -150,22 +172,11 @@ sealed class YieldSupplyAnalytics( event = "APY Chart", ) - data class NoticeCommissionTooHigh( + data class NoticeAmountNotDeposited( val token: String, val blockchain: String, ) : YieldSupplyAnalytics( - event = "Notice - Commission Is Too High", - params = mapOf( - TOKEN_PARAM to token, - BLOCKCHAIN to blockchain, - ), - ) - - data class NoticeNotEnoughMinAmount( - val token: String, - val blockchain: String, - ) : YieldSupplyAnalytics( - event = "Notice - Not Enough Min Amount", + event = "Notice - Amount Not Deposited", params = mapOf( TOKEN_PARAM to token, BLOCKCHAIN to blockchain, diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt index 5a7ac6bd0a..66f9d0f195 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt @@ -119,6 +119,11 @@ internal class YieldSupplyApproveModel @Inject constructor( val yieldSupplyFeeUM = uiState.value.yieldSupplyFeeUM as? YieldSupplyFeeUM.Content ?: return uiState.update(YieldSupplyTransactionInProgressTransformer) + analyticsEventHandler.send(YieldSupplyAnalytics.ButtonGiveApprove( + token = cryptoCurrency.symbol, + blockchain = cryptoCurrency.network.name, + )) + modelScope.launch(dispatchers.default) { sendTransactionUseCase( txData = yieldSupplyFeeUM.transactionDataList.first(), 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 a6f111df3a..9e704f9967 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 @@ -97,6 +97,13 @@ internal class YieldSupplyStopEarningModel @Inject constructor( ) init { + val currency = params.cryptoCurrencyStatusFlow.value.currency + analytics.send( + YieldSupplyAnalytics.StopEarningScreen( + token = currency.symbol, + blockchain = currency.network.name, + ), + ) modelScope.launch { appCurrency = getSelectedAppCurrencyUseCase.invokeSync().getOrElse { AppCurrency.Default } subscribeOnCurrencyStatusUpdates() @@ -133,6 +140,10 @@ 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(), + )) yieldSupplyAlertFactory.getSendTransactionErrorState( error = error, popBack = params.callback::onBackClick,