Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-17 19:20:51 +05:00
parent ed89b4bcd0
commit 533c036819
28 changed files with 334 additions and 162 deletions

View file

@ -20,6 +20,7 @@ import com.tangem.datasource.api.markets.TangemTechMarketsApi
import com.tangem.datasource.api.markets.models.response.TokenMarketExchangesResponse
import com.tangem.datasource.local.datastore.RuntimeStateStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.markets.*
import com.tangem.domain.markets.repositories.MarketsTokenRepository
import com.tangem.domain.models.account.DerivationIndex
@ -28,9 +29,8 @@ import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.pagination.*
import com.tangem.pagination.fetcher.LimitOffsetBatchFetcher
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import java.math.BigDecimal
import timber.log.Timber
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
@ -43,7 +43,6 @@ internal class DefaultMarketsTokenRepository(
private val analyticsEventHandler: AnalyticsEventHandler,
private val cacheRegistry: CacheRegistry,
private val tokenExchangesStore: RuntimeStateStore<List<TokenMarketExchangesResponse.Exchange>>,
private val maxApyStore: RuntimeStateStore<BigDecimal?>,
private val networkFactory: NetworkFactory,
excludedBlockchains: ExcludedBlockchains,
) : MarketsTokenRepository {
@ -95,8 +94,6 @@ internal class DefaultMarketsTokenRepository(
val tokenMarketListWithMaxApy = TokenMarketListConverter.convert(res)
maxApyStore.store(tokenMarketListWithMaxApy.maxApy)
return BatchFetchResult.Success(
data = tokenMarketListWithMaxApy.tokens,
last = last,
@ -294,8 +291,24 @@ internal class DefaultMarketsTokenRepository(
}
}
override suspend fun getMaxApy(): Flow<BigDecimal?> {
return maxApyStore.get()
override suspend fun showYieldModePromo(
appCurrency: AppCurrency,
interval: TokenMarketListConfig.Interval,
): Boolean = try {
val hasYieldSupplyTokens = marketsApi.getCoinsList(
currency = appCurrency.code,
interval = interval.toRequestParam(),
order = TokenMarketListConfig.Order.YieldSupply.toRequestParam(),
offset = 0,
limit = 40,
timestamp = null,
search = null,
).getOrThrow().tokens.isNotEmpty()
hasYieldSupplyTokens
} catch (error: Exception) {
Timber.e(error)
false
}
inline fun <T> catchListErrorAndSendEvent(block: () -> T): T {

View file

@ -16,6 +16,7 @@ internal fun TokenMarketListConfig.Order.toRequestParam(): String = when (this)
TokenMarketListConfig.Order.TopGainers -> "gainers"
TokenMarketListConfig.Order.TopLosers -> "losers"
TokenMarketListConfig.Order.Staking -> "staking"
TokenMarketListConfig.Order.YieldSupply -> "yield"
}
internal fun PriceChangeInterval.toRequestParam(): String = when (this) {

View file

@ -40,7 +40,7 @@ internal object TokenMarketListConverter : Converter<TokenMarketListResponse, To
monthChangePercent = token.priceChangePercentage?.day30?.movePointLeft(2),
),
tokenCharts = TokenMarket.Charts(h24 = null, week = null, month = null),
stakingRate = stakingRate,
yieldRate = stakingRate ?: token.maxYieldApy?.movePointLeft(2),
updateTimestamp = value.timestamp,
)
}

View file

@ -42,7 +42,6 @@ internal object MarketsDataModule {
cacheRegistry = cacheRegistry,
tokenExchangesStore = RuntimeStateStore(defaultValue = emptyList()),
excludedBlockchains = excludedBlockchains,
maxApyStore = RuntimeStateStore(defaultValue = null),
networkFactory = networkFactory,
)
}

View file

@ -90,16 +90,16 @@ internal class DefaultPromoRepository(
appPreferencesStore.store(PreferencesKeys.getShouldShowPromoKey(promoId = promoId.name), false)
}
override fun isMarketsStakingNotificationHideClicked(): Flow<Boolean> {
override fun isMarketsYieldSupplyNotificationHideClicked(): Flow<Boolean> {
return appPreferencesStore.get(
key = PreferencesKeys.MARKETS_STAKING_NOTIFICATION_HIDE_CLICKED_KEY,
key = PreferencesKeys.MARKETS_YIELD_SUPPLY_NOTIFICATION_HIDE_CLICKED_KEY,
default = false,
)
}
override suspend fun setMarketsStakingNotificationHideClicked() {
override suspend fun setMarketsYieldSupplyNotificationHideClicked() {
appPreferencesStore.store(
key = PreferencesKeys.MARKETS_STAKING_NOTIFICATION_HIDE_CLICKED_KEY,
key = PreferencesKeys.MARKETS_YIELD_SUPPLY_NOTIFICATION_HIDE_CLICKED_KEY,
value = true,
)
}