Updated on 2026-08-14
This commit is contained in:
parent
b0ec0581dc
commit
3ace7ed2dc
1 changed files with 25 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.features.managetokens.utils.list
|
||||
|
||||
import androidx.compose.ui.util.fastForEachIndexed
|
||||
import androidx.compose.ui.util.fastMap
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.core.decompose.di.ComponentScoped
|
||||
|
|
@ -165,7 +167,7 @@ internal class ManageTokensListManager @Inject constructor(
|
|||
}
|
||||
|
||||
state.update { state ->
|
||||
val newBatches = batchListState.data
|
||||
val newBatches = distinctCurrencies(batchListState.data)
|
||||
val currentBatches = state.currencyBatches
|
||||
|
||||
// Distinct until changed
|
||||
|
|
@ -186,6 +188,28 @@ internal class ManageTokensListManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Add interception functionality to BatchFlow state and do this on domain
|
||||
// [REDACTED_JIRA]
|
||||
private fun distinctCurrencies(
|
||||
batches: List<Batch<Int, List<ManagedCryptoCurrency>>>,
|
||||
): List<Batch<Int, List<ManagedCryptoCurrency>>> {
|
||||
val allCurrenciesIds = mutableListOf<ManagedCryptoCurrency.ID>()
|
||||
|
||||
return batches.fastMap { batch ->
|
||||
val batchCurrencies = batch.data.toMutableList()
|
||||
|
||||
batch.data.fastForEachIndexed { index, currency ->
|
||||
if (currency.id in allCurrenciesIds) {
|
||||
batchCurrencies.removeAt(index)
|
||||
} else {
|
||||
allCurrenciesIds.add(currency.id)
|
||||
}
|
||||
}
|
||||
|
||||
batch.copy(data = batchCurrencies)
|
||||
}
|
||||
}
|
||||
|
||||
override fun addCurrency(batchKey: Int, currency: ManagedCryptoCurrency.Token, network: Network) {
|
||||
changedCurrenciesManager.addCurrency(currency, network)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue