Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-25 15:18:35 +07:00
commit efa6863777
3 changed files with 57 additions and 7 deletions

View file

@ -48,7 +48,8 @@ internal class TokenListAnalyticsSender @Inject constructor(
if (screenLifecycleProvider.isBackgroundState.value) return
if (displayedUiState == null || displayedUiState.pullToRefreshConfig.isRefreshing) return
if (totalFiatBalance is TotalFiatBalance.Loading) {
val isFlickering = totalFiatBalance is TotalFiatBalance.Loaded && totalFiatBalance.source == StatusSource.CACHE
if (totalFiatBalance is TotalFiatBalance.Loading || isFlickering) {
startLoadingTraceIfNeeded(userWallet.walletId, flattenCurrencies)
return
}
@ -57,12 +58,10 @@ internal class TokenListAnalyticsSender @Inject constructor(
stopLoadingTraceIfNeeded(userWallet.walletId, totalFiatBalance)
}
val currenciesStatuses = flattenCurrencies
sendBalanceLoadedEventIfNeeded(totalFiatBalance, currenciesStatuses)
sendToppedUpEventIfNeeded(userWallet, totalFiatBalance, currenciesStatuses)
sendUnreachableNetworksEventIfNeeded(currenciesStatuses)
sendTokenBalancesIfNeeded(currenciesStatuses)
sendBalanceLoadedEventIfNeeded(totalFiatBalance, flattenCurrencies)
sendToppedUpEventIfNeeded(userWallet, totalFiatBalance, flattenCurrencies)
sendUnreachableNetworksEventIfNeeded(flattenCurrencies)
sendTokenBalancesIfNeeded(flattenCurrencies)
}
private suspend fun startLoadingTraceIfNeeded(

View file

@ -17,6 +17,7 @@ import dagger.assisted.AssistedInject
internal class MultiWalletContentLoaderV2 @AssistedInject constructor(
@Assisted private val userWallet: UserWallet,
private val accountListSubscriberFactory: AccountListSubscriber.Factory,
private val tokenListAnalyticsSubscriberFactory: TokenListAnalyticsSubscriber.Factory,
private val walletNFTListSubscriberV2Factory: WalletNFTListSubscriberV2.Factory,
private val stateController: WalletStateController,
private val clickIntents: WalletClickIntents,
@ -31,6 +32,7 @@ internal class MultiWalletContentLoaderV2 @AssistedInject constructor(
override fun create(): List<WalletSubscriber> = listOfNotNull(
accountListSubscriberFactory.create(userWallet = userWallet),
tokenListAnalyticsSubscriberFactory.create(userWallet = userWallet),
walletNFTListSubscriberV2Factory.create(userWallet = userWallet),
checkWalletWithFundsSubscriberFactory.create(userWallet = userWallet),
MultiWalletWarningsSubscriber(

View file

@ -0,0 +1,49 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.onEach
/**
* Subscriber that monitors account list changes and sends token list analytics
* when the total fiat balance changes.
*
[REDACTED_AUTHOR]
*/
internal class TokenListAnalyticsSubscriber @AssistedInject constructor(
@Assisted override val userWallet: UserWallet,
override val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val stateHolder: WalletStateController,
private val tokenListAnalyticsSender: TokenListAnalyticsSender,
) : BasicWalletSubscriber() {
override fun create(coroutineScope: CoroutineScope): Flow<*> = getAccountStatusListFlow()
.distinctUntilChanged { old, new -> old.totalFiatBalance == new.totalFiatBalance }
.onEach(::sendTokenListAnalytics)
private suspend fun sendTokenListAnalytics(accountStatusList: AccountStatusList) {
val displayedState = stateHolder.getWalletStateIfSelected(userWallet.walletId)
val flattenCurrencies = accountStatusList.flattenCurrencies()
tokenListAnalyticsSender.send(
displayedUiState = displayedState,
userWallet = userWallet,
flattenCurrencies = flattenCurrencies,
totalFiatBalance = accountStatusList.totalFiatBalance,
)
}
@AssistedFactory
interface Factory {
fun create(userWallet: UserWallet): TokenListAnalyticsSubscriber
}
}