Updated on 2026-08-14
This commit is contained in:
parent
73028360f4
commit
eaba6ee88d
21 changed files with 282 additions and 81 deletions
|
|
@ -65,13 +65,25 @@ internal class DefaultCurrenciesRepository(
|
|||
lazyMessage = { "Saved tokens empty. Can not perform add currencies action" },
|
||||
)
|
||||
|
||||
val filteredCurrencies = currencies.toMutableList()
|
||||
filteredCurrencies.filterNot { currency ->
|
||||
val blockchain = getBlockchain(networkId = currency.network.id)
|
||||
val networkId = blockchain.toNetworkId()
|
||||
val contractAddress = (currency as? CryptoCurrency.Token)?.contractAddress
|
||||
savedCurrencies.tokens.firstOrNull { token ->
|
||||
token.contractAddress == contractAddress &&
|
||||
token.networkId == networkId &&
|
||||
token.derivationPath == currency.network.derivationPath.value
|
||||
} != null
|
||||
}
|
||||
|
||||
val newCoins = createCoinsForNewTokens(
|
||||
userWalletId = userWalletId,
|
||||
newTokens = currencies.filterIsInstance<CryptoCurrency.Token>(),
|
||||
newTokens = filteredCurrencies.filterIsInstance<CryptoCurrency.Token>(),
|
||||
savedCurrencies = savedCurrencies.tokens,
|
||||
)
|
||||
|
||||
val newCurrencies = newCoins + currencies
|
||||
val newCurrencies = newCoins + filteredCurrencies
|
||||
|
||||
storeAndPushTokens(
|
||||
userWalletId = userWalletId,
|
||||
|
|
@ -276,7 +288,7 @@ internal class DefaultCurrenciesRepository(
|
|||
private suspend fun fetchUserMarketCoinsByIds(userWalletId: UserWalletId, userTokens: UserTokensResponse) {
|
||||
try {
|
||||
val networkIds = userTokens.tokens.joinToString(separator = ",") { it.networkId }
|
||||
val response = tangemTechApi.getCoins(networkIds)
|
||||
val response = tangemTechApi.getCoins(networkIds = networkIds)
|
||||
|
||||
userMarketCoinsStore.store(userWalletId, response)
|
||||
} catch (e: Throwable) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.tangem.data.tokens.repository
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.datasource.local.token.UserMarketCoinsStore
|
||||
import com.tangem.domain.common.extensions.toNetworkId
|
||||
import com.tangem.domain.tokens.models.CryptoCurrency
|
||||
import com.tangem.domain.tokens.repository.MarketCryptoCurrencyRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
|
@ -10,9 +12,11 @@ class DefaultMarketCryptoCurrencyRepository(
|
|||
) : MarketCryptoCurrencyRepository {
|
||||
|
||||
override suspend fun isExchangeable(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID): Boolean {
|
||||
val blockchain = Blockchain.fromId(cryptoCurrencyId.rawNetworkId)
|
||||
val apiNetworkId = blockchain.toNetworkId()
|
||||
return userMarketCoinsStore.getSyncOrNull(userWalletId)?.coins
|
||||
?.firstOrNull { it.id == cryptoCurrencyId.rawCurrencyId }
|
||||
?.networks
|
||||
?.firstOrNull { it.networkId == cryptoCurrencyId.rawNetworkId }?.exchangeable ?: false
|
||||
?.firstOrNull { it.networkId == apiNetworkId }?.exchangeable ?: false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue