From 42cb399a12a76dbdb56b2aff40c702a62cd8612a Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 14 Nov 2023 12:35:45 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../DefaultMarketCryptoCurrencyRepository.kt | 8 +++++++- .../com/tangem/domain/tokens/model/CryptoCurrency.kt | 2 ++ .../tangem/feature/swap/domain/SwapInteractorImpl.kt | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt index 441f3f97d2..2211aa96cd 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt @@ -17,6 +17,12 @@ class DefaultMarketCryptoCurrencyRepository( return userMarketCoinsStore.getSyncOrNull(userWalletId)?.coins ?.firstOrNull { it.id == cryptoCurrencyId.rawCurrencyId } ?.networks - ?.firstOrNull { it.networkId == apiNetworkId }?.exchangeable ?: false + ?.firstOrNull { + if (it.contractAddress != null) { + it.networkId == apiNetworkId && it.contractAddress == cryptoCurrencyId.contractAddress + } else { + it.networkId == apiNetworkId + } + }?.exchangeable ?: false } } \ No newline at end of file diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt index e360bda6e4..87015b1305 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt @@ -94,6 +94,8 @@ sealed class CryptoCurrency : Parcelable { /** Represents a raw cryptocurrency ID. If it is a custom token, the value will be `null`. */ val rawCurrencyId: String? get() = (suffix as? Suffix.RawID)?.rawId + val contractAddress: String? get() = (suffix as? Suffix.RawID)?.contractAddress + /** Represents a raw cryptocurrency's network ID. */ val rawNetworkId: String get() = when (body) { diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index d76a2d777e..4e6dcfa4cf 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -23,6 +23,7 @@ import timber.log.Timber import java.math.BigDecimal import java.math.RoundingMode import javax.inject.Inject +import com.tangem.lib.crypto.models.Currency as LibCurrency @Suppress("LargeClass", "LongParameterList") internal class SwapInteractorImpl @Inject constructor( @@ -70,7 +71,14 @@ internal class SwapInteractorImpl @Inject constructor( isExcludeCustom = true, ) .map { token -> - allLoadedTokens.firstOrNull { it.symbol == token.symbol }?.let { + val contractAddress = (token as? LibCurrency.NonNativeToken)?.contractAddress + allLoadedTokens.firstOrNull { + if (it is Currency.NonNativeToken) { + it.symbol == token.symbol && it.contractAddress == contractAddress + } else { + it.symbol == token.symbol + } + }?.let { loadedOnWalletsMap.add(it.symbol) it } ?: swapCurrencyConverter.convertBack(token)