From 1f3f592cee1c200e0ff83e6501216088b0bc854b Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 12 Sep 2024 12:04:51 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../DefaultManageTokensRepository.kt | 9 +++++-- .../markets/DefaultMarketsTokenRepository.kt | 9 ++++--- .../QuotesUnsupportedCurrenciesIdAdapter.kt | 13 ++-------- features/markets/impl/build.gradle.kts | 1 + .../DefaultMarketsTokenDetailsComponent.kt | 13 +++++++--- .../block/impl/model/TokenMarketBlockModel.kt | 5 +++- .../WalletCurrencyActionsClickIntents.kt | 25 ++++++++++--------- .../blockchainsdk/compatibility/L2Networks.kt | 20 +++++++++++---- 8 files changed, 58 insertions(+), 37 deletions(-) diff --git a/data/manage-tokens/src/main/kotlin/com/tangem/data/managetokens/DefaultManageTokensRepository.kt b/data/manage-tokens/src/main/kotlin/com/tangem/data/managetokens/DefaultManageTokensRepository.kt index 6c0d025397..f1749f04d4 100644 --- a/data/manage-tokens/src/main/kotlin/com/tangem/data/managetokens/DefaultManageTokensRepository.kt +++ b/data/manage-tokens/src/main/kotlin/com/tangem/data/managetokens/DefaultManageTokensRepository.kt @@ -1,6 +1,7 @@ package com.tangem.data.managetokens import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchainsdk.compatibility.l2BlockchainsCoinIds import com.tangem.blockchainsdk.utils.isSupportedInApp import com.tangem.blockchainsdk.utils.toNetworkId import com.tangem.data.common.currency.getBlockchain @@ -86,6 +87,10 @@ internal class DefaultManageTokensRepository( } else { retryOnError(call = call) } + // filter l2 coins + val updatedCoinsResponse = coinsResponse.copy( + coins = coinsResponse.coins.filterNot { l2BlockchainsCoinIds.contains(it.id) }, + ) val tokensResponse = request.params.userWalletId?.let { getSavedUserTokensResponseSync(it) } val items = if (isFirstBatchFetching && @@ -94,13 +99,13 @@ internal class DefaultManageTokensRepository( request.params.searchText.isNullOrBlank() ) { managedCryptoCurrencyFactory.createWithCustomTokens( - coinsResponse = coinsResponse, + coinsResponse = updatedCoinsResponse, tokensResponse = tokensResponse, derivationStyleProvider = userWallet.scanResponse.derivationStyleProvider, ) } else { managedCryptoCurrencyFactory.create( - coinsResponse = coinsResponse, + coinsResponse = updatedCoinsResponse, tokensResponse = tokensResponse, derivationStyleProvider = userWallet?.scanResponse?.derivationStyleProvider, ) diff --git a/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt b/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt index 420a16f3e4..cd5b9ca9fc 100644 --- a/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt +++ b/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt @@ -2,6 +2,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.fromNetworkId import com.tangem.data.common.currency.CryptoCurrencyFactory import com.tangem.data.common.currency.getNetwork @@ -109,9 +110,10 @@ internal class DefaultMarketsTokenRepository( interval: PriceChangeInterval, tokenId: String, ): TokenChart { + val mappedTokenId = getTokenIdIfL2Network(tokenId) val response = marketsApi.getCoinChart( currency = fiatCurrencyCode, - coinId = tokenId, + coinId = mappedTokenId, interval = interval.toRequestParam(), ) @@ -123,13 +125,14 @@ internal class DefaultMarketsTokenRepository( interval: PriceChangeInterval, tokenId: String, ): TokenChart { + val mappedTokenId = getTokenIdIfL2Network(tokenId) val response = marketsApi.getCoinsListCharts( - coinIds = tokenId, + coinIds = mappedTokenId, currency = fiatCurrencyCode, interval = interval.toRequestParam(), ) - val chart = response.getOrThrow()[tokenId] ?: error("No chart preview data for token $tokenId") + val chart = response.getOrThrow()[mappedTokenId] ?: error("No chart preview data for token $mappedTokenId") return TokenChartConverter.convert(interval, chart) } diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesUnsupportedCurrenciesIdAdapter.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesUnsupportedCurrenciesIdAdapter.kt index 5ae6618a2c..66f0ea8b64 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesUnsupportedCurrenciesIdAdapter.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesUnsupportedCurrenciesIdAdapter.kt @@ -1,6 +1,7 @@ package com.tangem.data.tokens.utils import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchainsdk.compatibility.l2BlockchainsCoinIds import com.tangem.blockchainsdk.utils.toCoinId import com.tangem.datasource.api.tangemTech.models.QuotesResponse @@ -51,16 +52,6 @@ internal class QuotesUnsupportedCurrenciesIdAdapter { * Map that contains unsupported currencies and their replacement for request */ private val ethCoinId = Blockchain.Ethereum.toCoinId() - private val UNSUPPORTED_IDS_WITH_REPLACEMENTS = mapOf( - Blockchain.Optimism.toCoinId() to ethCoinId, - Blockchain.Arbitrum.toCoinId() to ethCoinId, - Blockchain.ZkSyncEra.toCoinId() to ethCoinId, - Blockchain.Manta.toCoinId() to ethCoinId, - Blockchain.PolygonZkEVM.toCoinId() to ethCoinId, - Blockchain.Aurora.toCoinId() to ethCoinId, - Blockchain.Base.toCoinId() to ethCoinId, - Blockchain.Blast.toCoinId() to ethCoinId, - Blockchain.Cyber.toCoinId() to ethCoinId, - ) + private val UNSUPPORTED_IDS_WITH_REPLACEMENTS = l2BlockchainsCoinIds.associateWith { ethCoinId } } } \ No newline at end of file diff --git a/features/markets/impl/build.gradle.kts b/features/markets/impl/build.gradle.kts index d356234b52..3ac39315a8 100644 --- a/features/markets/impl/build.gradle.kts +++ b/features/markets/impl/build.gradle.kts @@ -69,4 +69,5 @@ dependencies { /* Libs */ implementation(projects.libs.crypto) + implementation(projects.libs.blockchainSdk) } \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/details/impl/DefaultMarketsTokenDetailsComponent.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/details/impl/DefaultMarketsTokenDetailsComponent.kt index 22c2c2b970..d78eb7c19f 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/details/impl/DefaultMarketsTokenDetailsComponent.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/details/impl/DefaultMarketsTokenDetailsComponent.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp import androidx.lifecycle.compose.LifecycleStartEffect import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.blockchainsdk.compatibility.getTokenIdIfL2Network import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.context.child import com.tangem.core.decompose.model.getOrCreateModel @@ -31,12 +32,18 @@ internal class DefaultMarketsTokenDetailsComponent @AssistedInject constructor( portfolioComponentFactory: MarketsPortfolioComponent.Factory, ) : AppComponentContext by appComponentContext, MarketsTokenDetailsComponent { - private val model: MarketsTokenDetailsModel = getOrCreateModel(params) + // applying l2 compatibility + private val updatedParams = params.copy( + token = params.token.copy( + id = getTokenIdIfL2Network(params.token.id), + ), + ) + private val model: MarketsTokenDetailsModel = getOrCreateModel(updatedParams) - private val portfolioComponent: MarketsPortfolioComponent? = if (params.showPortfolio) { + private val portfolioComponent: MarketsPortfolioComponent? = if (updatedParams.showPortfolio) { portfolioComponentFactory.create( context = child("my_portfolio"), - params = MarketsPortfolioComponent.Params(params.token), + params = MarketsPortfolioComponent.Params(updatedParams.token), ) } else { null diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/token/block/impl/model/TokenMarketBlockModel.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/token/block/impl/model/TokenMarketBlockModel.kt index 71c71a4d5e..49adf98ff9 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/token/block/impl/model/TokenMarketBlockModel.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/token/block/impl/model/TokenMarketBlockModel.kt @@ -14,7 +14,10 @@ import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.markets.* +import com.tangem.domain.markets.GetCurrencyQuotesUseCase +import com.tangem.domain.markets.GetTokenPriceChartUseCase +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenMarketParams import com.tangem.features.markets.token.block.TokenMarketBlockComponent import com.tangem.features.markets.token.block.impl.ui.state.TokenMarketBlockUM import com.tangem.utils.coroutines.CoroutineDispatcherProvider diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt index 1a067b02f7..ebd530cb7c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt @@ -386,20 +386,21 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( viewModelScope.launch { val rawId = cryptoCurrencyStatus.currency.id.rawCurrencyId ?: return@launch + val tokenMarketParams = TokenMarketParams( + id = rawId, + name = cryptoCurrencyStatus.currency.name, + symbol = cryptoCurrencyStatus.currency.symbol, + tokenQuotes = TokenMarketParams.Quotes( + currentPrice = cryptoCurrencyStatus.value.fiatRate ?: BigDecimal.ZERO, + h24Percent = cryptoCurrencyStatus.value.priceChange, + weekPercent = null, + monthPercent = null, + ), + imageUrl = cryptoCurrencyStatus.currency.iconUrl, + ) appRouter.push( AppRoute.MarketsTokenDetails( - TokenMarketParams( - id = rawId, - name = cryptoCurrencyStatus.currency.name, - symbol = cryptoCurrencyStatus.currency.symbol, - tokenQuotes = TokenMarketParams.Quotes( - currentPrice = cryptoCurrencyStatus.value.fiatRate ?: BigDecimal.ZERO, - h24Percent = cryptoCurrencyStatus.value.priceChange, - weekPercent = null, - monthPercent = null, - ), - imageUrl = cryptoCurrencyStatus.currency.iconUrl, - ), + token = tokenMarketParams, appCurrency = getSelectedAppCurrencyUseCase.unwrap(), showPortfolio = true, ), diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/compatibility/L2Networks.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/compatibility/L2Networks.kt index b3572820d3..1248e3dedd 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/compatibility/L2Networks.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/compatibility/L2Networks.kt @@ -7,7 +7,7 @@ import com.tangem.datasource.api.markets.models.response.TokenMarketInfoResponse import com.tangem.datasource.api.tangemTech.models.CoinsResponse import com.tangem.datasource.api.tangemTech.models.UserTokensResponse -val l2NetworksList = listOf( +internal val l2BlockchainsList = listOf( Blockchain.Optimism, Blockchain.Arbitrum, Blockchain.ZkSyncEra, @@ -19,9 +19,13 @@ val l2NetworksList = listOf( Blockchain.Cyber, ) +val l2BlockchainsCoinIds = l2BlockchainsList.map { it.toCoinId() } + +val ETHEREUM_COIN_ID = Blockchain.Ethereum.toCoinId() + fun getL2CompatibilityTokenComparison(token: UserTokensResponse.Token, currencyId: String): Boolean { return if (currencyId == ETHEREUM_COIN_ID) { - l2NetworksList.map { it.toCoinId() }.contains(token.id) || currencyId == token.id + l2BlockchainsCoinIds.contains(token.id) || currencyId == token.id } else { token.id == currencyId } @@ -29,7 +33,7 @@ fun getL2CompatibilityTokenComparison(token: UserTokensResponse.Token, currencyI fun List.applyL2Compatibility(coinId: String): List { return if (coinId == ETHEREUM_COIN_ID) { - val l2Networks = l2NetworksList.map { + val l2Networks = l2BlockchainsList.map { CoinsResponse.Coin.Network( networkId = it.toNetworkId(), ) @@ -43,7 +47,7 @@ fun List.applyL2Compatibility(coinId: String): List< fun TokenMarketInfoResponse.applyL2Compatibility(coinId: String): TokenMarketInfoResponse { val networks = this.networks ?: return this return if (coinId == ETHEREUM_COIN_ID) { - val l2Networks = l2NetworksList.map { + val l2Networks = l2BlockchainsList.map { TokenMarketInfoResponse.Network( networkId = it.toNetworkId(), contractAddress = null, @@ -56,4 +60,10 @@ fun TokenMarketInfoResponse.applyL2Compatibility(coinId: String): TokenMarketInf } } -const val ETHEREUM_COIN_ID = "ethereum" \ No newline at end of file +fun getTokenIdIfL2Network(tokenId: String): String { + return if (l2BlockchainsCoinIds.contains(tokenId)) { + ETHEREUM_COIN_ID + } else { + tokenId + } +} \ No newline at end of file