Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-29 12:51:19 +05:00
parent 187218cf03
commit c1302681a4
3 changed files with 23 additions and 10 deletions

View file

@ -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
}
}

View file

@ -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"

View file

@ -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 = {