From 3ace7ed2dc07d2396f80036542970287a759a622 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 9 Dec 2024 15:38:09 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../utils/list/ManageTokensListManager.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/list/ManageTokensListManager.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/list/ManageTokensListManager.kt index 414fd1161a..d3a52095a7 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/list/ManageTokensListManager.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/list/ManageTokensListManager.kt @@ -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>>, + ): List>> { + val allCurrenciesIds = mutableListOf() + + 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)