diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index cbe836e1cd..fa5f16dbf1 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -10,6 +10,7 @@ import com.tangem.datasource.api.tangemTech.models.UserTokensResponse import com.tangem.datasource.local.token.UserMarketCoinsStore import com.tangem.datasource.local.token.UserTokensStore import com.tangem.datasource.local.userwallet.UserWalletsStore +import com.tangem.domain.common.extensions.toCoinId import com.tangem.domain.common.extensions.toNetworkId import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.core.error.DataError @@ -205,9 +206,17 @@ internal class DefaultCurrenciesRepository( val storedTokens = requireNotNull(userTokensStore.getSyncOrNull(userWallet.walletId)) { "Unable to find tokens response for user wallet with provided ID: $userWalletId" } + val blockchain = Blockchain.fromId(networkId.value) + val derivationPath = blockchain + .derivationPath(userWallet.scanResponse.derivationStyleProvider.getDerivationStyle()) + ?.rawPath - val storedCoin = storedTokens.tokens.find { it.networkId == Blockchain.fromId(networkId.value).toNetworkId() } - ?: error("Coin in this network $networkId not found") + val storedCoin = storedTokens.tokens + .find { + it.networkId == blockchain.toNetworkId() && + it.id == blockchain.toCoinId() && + it.derivationPath == derivationPath + } ?: error("Coin in this network $networkId not found") val coin = responseCurrenciesFactory.createCurrency(storedCoin, userWallet.scanResponse) @@ -341,8 +350,4 @@ internal class DefaultCurrenciesRepository( } private fun getTokensCacheKey(userWalletId: UserWalletId): String = "tokens_cache_key_${userWalletId.stringValue}" - - private companion object { - const val NOT_FOUND_HTTP_CODE = 404 - } } \ No newline at end of file diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt index d0f16e8762..27afcb1c84 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt @@ -6,6 +6,7 @@ import com.tangem.datasource.api.tangemTech.models.UserTokensResponse import com.tangem.domain.common.DerivationStyleProvider import com.tangem.domain.common.extensions.fromNetworkId import com.tangem.domain.common.extensions.toCoinId +import com.tangem.domain.common.extensions.toNetworkId import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.demo.DemoConfig import com.tangem.domain.models.scan.ScanResponse @@ -21,10 +22,17 @@ internal class ResponseCryptoCurrenciesFactory(private val demoConfig: DemoConfi scanResponse: ScanResponse, ): CryptoCurrency { val responseTokenId = currencyId.rawCurrencyId + val blockchain = Blockchain.fromId(currencyId.rawNetworkId) + val networkId = blockchain.toNetworkId() + val derivationPath = blockchain + .derivationPath(scanResponse.derivationStyleProvider.getDerivationStyle()) + ?.rawPath - val token = requireNotNull(response.tokens.firstOrNull { it.id == responseTokenId }) { - "Unable find a token with provided ID: $responseTokenId" - } + val token = requireNotNull( + value = response.tokens + .find { it.id == responseTokenId && it.networkId == networkId && it.derivationPath == derivationPath }, + lazyMessage = { "Unable find a token with provided TokenID($responseTokenId) and NetworkID($networkId)" }, + ) return requireNotNull(createCurrency(token, scanResponse)) { "Unable to create a currency with provided ID: $currencyId" diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 2e1ffc3c93..a8f37d0bf3 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -102,7 +102,7 @@ internal class TokenDetailsViewModel @Inject constructor( ifRight = { wallet = it }, ) viewModelScope.launch { - getCryptoCurrencyUseCase.invoke(userWalletId = wallet.walletId, id = screenArgument.currencyId) + getCryptoCurrencyUseCase(userWalletId = wallet.walletId, id = screenArgument.currencyId) .fold( ifLeft = { error("Can not get cryptoCurrency with given ID: screenArgument.currencyId. $it") }, ifRight = {