Updated on 2026-08-14
This commit is contained in:
parent
7af83c6998
commit
b9b612c1b8
3 changed files with 28 additions and 25 deletions
|
|
@ -68,17 +68,17 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
.mapValues { SwapAmount(it.value.value, it.value.decimals) }
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val rates = repository.getRates(appCurrency.code, tokensInWallet.map { it.id })
|
||||
cache.cacheLoadedTokens(loadedTokens)
|
||||
cache.cacheBalances(tokensBalance)
|
||||
cache.cacheInWalletTokens(tokensInWallet)
|
||||
cache.cacheLoadedTokens(loadedTokens.map { TokenWithBalance(it) })
|
||||
cache.cacheInWalletTokens(getTokensWithBalance(tokensInWallet, tokensBalance, rates, appCurrency))
|
||||
return TokensDataState(
|
||||
preselectTokens = PreselectTokens(
|
||||
fromToken = initialCurrency,
|
||||
toToken = selectToToken(initialCurrency, tokensInWallet, loadedTokens),
|
||||
),
|
||||
foundTokensState = FoundTokensState(
|
||||
tokensInWallet = getTokensWithBalance(tokensInWallet, tokensBalance, rates, appCurrency),
|
||||
loadedTokens = loadedTokens.map { TokenWithBalance(it) },
|
||||
tokensInWallet = cache.getInWalletTokens(),
|
||||
loadedTokens = cache.getLoadedTokens(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -87,28 +87,29 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
val searchQueryLowerCase = searchQuery.lowercase()
|
||||
val tokensInWallet = cache.getInWalletTokens()
|
||||
.filter {
|
||||
it.name.lowercase().contains(searchQueryLowerCase) ||
|
||||
it.symbol.lowercase().contains(searchQueryLowerCase)
|
||||
it.token.name.lowercase().contains(searchQueryLowerCase) ||
|
||||
it.token.symbol.lowercase().contains(searchQueryLowerCase)
|
||||
}
|
||||
val loadedTokens = cache.getLoadedTokens()
|
||||
.filter {
|
||||
it.name.lowercase().contains(searchQueryLowerCase) ||
|
||||
it.symbol.lowercase().contains(searchQueryLowerCase)
|
||||
it.token.name.lowercase().contains(searchQueryLowerCase) ||
|
||||
it.token.symbol.lowercase().contains(searchQueryLowerCase)
|
||||
}
|
||||
val tokensBalance = userWalletManager.getCurrentWalletTokensBalance(networkId, emptyList())
|
||||
.mapValues { SwapAmount(it.value.value, it.value.decimals) }
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val rates = repository.getRates(appCurrency.code, tokensInWallet.map { it.id })
|
||||
// val tokensBalance = userWalletManager.getCurrentWalletTokensBalance(networkId, emptyList())
|
||||
// .mapValues { SwapAmount(it.value.value, it.value.decimals) }
|
||||
// val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
// val rates = repository.getRates(appCurrency.code, tokensInWallet.map { it.id })
|
||||
return FoundTokensState(
|
||||
tokensInWallet = getTokensWithBalance(tokensInWallet, tokensBalance, rates, appCurrency),
|
||||
loadedTokens = loadedTokens.map { TokenWithBalance(it) },
|
||||
tokensInWallet = tokensInWallet, // getTokensWithBalance(tokensInWallet, tokensBalance, rates, appCurrency),
|
||||
loadedTokens = loadedTokens, // loadedTokens.map { TokenWithBalance(it) },
|
||||
)
|
||||
}
|
||||
|
||||
override fun findTokenById(id: String): Currency? {
|
||||
val tokensInWallet = cache.getInWalletTokens()
|
||||
val loadedTokens = cache.getLoadedTokens()
|
||||
return tokensInWallet.firstOrNull { it.id == id } ?: loadedTokens.firstOrNull { it.id == id }
|
||||
return tokensInWallet.firstOrNull { it.token.id == id }?.token
|
||||
?: loadedTokens.firstOrNull { it.token.id == id }?.token
|
||||
}
|
||||
|
||||
override suspend fun givePermissionToSwap(
|
||||
|
|
|
|||
|
|
@ -2,18 +2,19 @@ package com.tangem.feature.swap.domain.cache
|
|||
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.Currency
|
||||
import com.tangem.feature.swap.domain.models.ui.TokenWithBalance
|
||||
import java.math.BigDecimal
|
||||
|
||||
interface SwapDataCache {
|
||||
|
||||
fun cacheAvailableToSwapTokens(networkId: String, tokens: List<Currency>)
|
||||
fun cacheInWalletTokens(tokens: List<Currency>)
|
||||
fun cacheLoadedTokens(tokens: List<Currency>)
|
||||
fun cacheInWalletTokens(tokens: List<TokenWithBalance>)
|
||||
fun cacheLoadedTokens(tokens: List<TokenWithBalance>)
|
||||
fun cacheBalances(balances: Map<String, SwapAmount>)
|
||||
fun cacheLastFeeForNetwork(fee: BigDecimal, networkId: String)
|
||||
fun getAvailableTokens(networkId: String): List<Currency>
|
||||
fun getInWalletTokens(): List<Currency>
|
||||
fun getLoadedTokens(): List<Currency>
|
||||
fun getInWalletTokens(): List<TokenWithBalance>
|
||||
fun getLoadedTokens(): List<TokenWithBalance>
|
||||
fun getBalanceForToken(symbol: String): SwapAmount?
|
||||
fun getLastFeeForNetwork(networkId: String): BigDecimal?
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.swap.domain.cache
|
|||
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.Currency
|
||||
import com.tangem.feature.swap.domain.models.ui.TokenWithBalance
|
||||
import java.math.BigDecimal
|
||||
|
||||
class SwapDataCacheImpl : SwapDataCache {
|
||||
|
|
@ -9,28 +10,28 @@ class SwapDataCacheImpl : SwapDataCache {
|
|||
private val availableTokensForNetwork: MutableMap<String, List<Currency>> = mutableMapOf()
|
||||
private val feesForNetworks: MutableMap<String, BigDecimal> = mutableMapOf()
|
||||
private val tokensBalances: MutableMap<String, SwapAmount> = mutableMapOf()
|
||||
private val lastInWalletTokens = mutableListOf<Currency>()
|
||||
private val lastLoadedTokens = mutableListOf<Currency>()
|
||||
private val lastInWalletTokens = mutableListOf<TokenWithBalance>()
|
||||
private val lastLoadedTokens = mutableListOf<TokenWithBalance>()
|
||||
|
||||
override fun cacheLastFeeForNetwork(fee: BigDecimal, networkId: String) {
|
||||
feesForNetworks[networkId] = fee
|
||||
}
|
||||
|
||||
override fun cacheInWalletTokens(tokens: List<Currency>) {
|
||||
override fun cacheInWalletTokens(tokens: List<TokenWithBalance>) {
|
||||
lastInWalletTokens.clear()
|
||||
lastInWalletTokens.addAll(tokens)
|
||||
}
|
||||
|
||||
override fun cacheLoadedTokens(tokens: List<Currency>) {
|
||||
override fun cacheLoadedTokens(tokens: List<TokenWithBalance>) {
|
||||
lastLoadedTokens.clear()
|
||||
lastLoadedTokens.addAll(tokens)
|
||||
}
|
||||
|
||||
override fun getInWalletTokens(): List<Currency> {
|
||||
override fun getInWalletTokens(): List<TokenWithBalance> {
|
||||
return lastInWalletTokens
|
||||
}
|
||||
|
||||
override fun getLoadedTokens(): List<Currency> {
|
||||
override fun getLoadedTokens(): List<TokenWithBalance> {
|
||||
return lastLoadedTokens
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue