Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-26 13:17:34 +04:00
parent 207da4af08
commit 7aef4046c3
31 changed files with 238 additions and 91 deletions

View file

@ -16,6 +16,7 @@ dependencies {
implementation(projects.core.pagination)
implementation(projects.core.analytics)
implementation(projects.core.analytics.models)
implementation(projects.core.configToggles)
implementation(projects.domain.legacy)
implementation(projects.domain.markets)

View file

@ -3,6 +3,7 @@ package com.tangem.data.markets
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.compatibility.applyL2Compatibility
import com.tangem.blockchainsdk.compatibility.getTokenIdIfL2Network
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.data.common.cache.CacheRegistry
@ -37,10 +38,14 @@ internal class DefaultMarketsTokenRepository(
private val userWalletsStore: UserWalletsStore,
private val dispatcherProvider: CoroutineDispatcherProvider,
private val analyticsEventHandler: AnalyticsEventHandler,
private val excludedBlockchains: ExcludedBlockchains,
private val cacheRegistry: CacheRegistry,
private val tokenExchangesStore: RuntimeStateStore<List<TokenMarketExchangesResponse.Exchange>>,
) : MarketsTokenRepository {
private val tokenMarketInfoConverter: TokenMarketInfoConverter = TokenMarketInfoConverter(excludedBlockchains)
private val cryptoCurrencyFactory = CryptoCurrencyFactory(excludedBlockchains)
private fun createTokenMarketsFetcher(firstBatchSize: Int, nextBatchSize: Int) = LimitOffsetBatchFetcher(
prefetchDistance = firstBatchSize,
batchSize = nextBatchSize,
@ -204,7 +209,7 @@ internal class DefaultMarketsTokenRepository(
}
val resultResponse = result.applyL2Compatibility(tokenId)
return@withContext TokenMarketInfoConverter.convert(resultResponse)
return@withContext tokenMarketInfoConverter.convert(resultResponse)
}
override suspend fun getTokenQuotes(fiatCurrencyCode: String, tokenId: String, tokenSymbol: String) =
@ -234,7 +239,7 @@ internal class DefaultMarketsTokenRepository(
val blockchain = Blockchain.fromNetworkId(network.networkId) ?: error("Unknown network [${network.networkId}]")
return if (network.contractAddress == null) {
CryptoCurrencyFactory().createCoin(
cryptoCurrencyFactory.createCoin(
blockchain = blockchain,
extraDerivationPath = null,
scanResponse = userWallet.scanResponse,
@ -244,9 +249,10 @@ internal class DefaultMarketsTokenRepository(
blockchain = blockchain,
extraDerivationPath = null,
scanResponse = userWallet.scanResponse,
excludedBlockchains = excludedBlockchains,
) ?: return null
CryptoCurrencyFactory().createToken(
cryptoCurrencyFactory.createToken(
network = currencyNetwork,
rawId = token.id,
name = token.name,

View file

@ -2,8 +2,8 @@ package com.tangem.data.markets.converters
import android.net.Uri
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.blockchainsdk.utils.isSupportedInApp
import com.tangem.datasource.api.markets.models.response.TokenMarketInfoResponse
import com.tangem.domain.markets.BuildConfig
import com.tangem.domain.markets.TokenMarketInfo
@ -11,10 +11,9 @@ import com.tangem.domain.markets.TokenQuotes
import com.tangem.utils.converter.Converter
import java.math.BigDecimal
internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, TokenMarketInfo> {
private const val PROD_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api/security_provider/"
private const val DEV_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api.dev/security_provider/"
internal class TokenMarketInfoConverter(
private val excludedBlockchains: ExcludedBlockchains,
) : Converter<TokenMarketInfoResponse, TokenMarketInfo> {
override fun convert(value: TokenMarketInfoResponse): TokenMarketInfo {
return with(value) {
@ -68,7 +67,8 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
decimalCount = network.decimalCount,
)
}
blockchain != null && blockchain.isSupportedInApp() && blockchain.canHandleTokens() -> {
blockchain != null && blockchain !in excludedBlockchains &&
blockchain.canHandleTokens() -> {
TokenMarketInfo.Network(
networkId = network.networkId,
exchangeable = network.exchangeable,
@ -193,4 +193,10 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
PROD_IMAGE_HOST
}
}
private companion object {
const val PROD_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api/security_provider/"
const val DEV_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api.dev/security_provider/"
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.data.markets.di
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.data.common.cache.CacheRegistry
import com.tangem.data.markets.DefaultMarketsTokenRepository
@ -28,6 +29,7 @@ internal object MarketsDataModule {
dispatchers: CoroutineDispatcherProvider,
analyticsEventHandler: AnalyticsEventHandler,
cacheRegistry: CacheRegistry,
excludedBlockchains: ExcludedBlockchains,
): MarketsTokenRepository {
return DefaultMarketsTokenRepository(
marketsApi = marketsApi,
@ -37,6 +39,7 @@ internal object MarketsDataModule {
analyticsEventHandler = analyticsEventHandler,
cacheRegistry = cacheRegistry,
tokenExchangesStore = RuntimeStateStore(defaultValue = emptyList()),
excludedBlockchains = excludedBlockchains,
)
}
}