From 7dc92a9beab7017ba27652b52062dd3369d84fb1 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 2 Feb 2022 14:24:01 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../features/tokens/redux/CurrencyListItem.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/tokens/redux/CurrencyListItem.kt b/app/src/main/java/com/tangem/tap/features/tokens/redux/CurrencyListItem.kt index f9749a8b8a..032f9d82ef 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/redux/CurrencyListItem.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/redux/CurrencyListItem.kt @@ -51,7 +51,7 @@ sealed class CurrencyListItem { fun List.removeTokensForBlockchain(blockchain: Blockchain): List { return filterNot { - it is CurrencyListItem.TokenListItem && it.token.blockchain == blockchain + it is CurrencyListItem.TokenListItem && it.isTheSameOrTestnetBlockchain(blockchain) } } @@ -59,18 +59,31 @@ fun List.addTokensForBlockchain( blockchain: Blockchain, fullCurrenciesList: List, ): List { val tokensToAdd = fullCurrenciesList.filter { - it is CurrencyListItem.TokenListItem && it.token.blockchain == blockchain + it is CurrencyListItem.TokenListItem && it.isTheSameOrTestnetBlockchain(blockchain) } val indexToInsert = indexOfFirst { - it is CurrencyListItem.TitleListItem && it.blockchain == blockchain + it is CurrencyListItem.TitleListItem && it.isTheSameOrTestnetBlockchain(blockchain) } + 1 return this.toMutableList().apply { addAll(indexToInsert, tokensToAdd) } } fun List.toggleHeaderContentShownValue(blockchain: Blockchain) { map { - if (it is CurrencyListItem.TitleListItem && it.blockchain == blockchain) { + if (it is CurrencyListItem.TitleListItem && it.isTheSameOrTestnetBlockchain(blockchain)) { it.isContentShown = !it.isContentShown } } +} + +// if you do not check the testNet blockchains, it will not collapse +private fun CurrencyListItem.isTheSameOrTestnetBlockchain(blockchain: Blockchain): Boolean { + return when (this) { + is CurrencyListItem.TitleListItem -> this.blockchain?.isTheSameOrTestnetBlockchain(blockchain) ?: false + is CurrencyListItem.BlockchainListItem -> this.blockchain.isTheSameOrTestnetBlockchain(blockchain) + is CurrencyListItem.TokenListItem -> this.token.blockchain.isTheSameOrTestnetBlockchain(blockchain) + } +} + +private fun Blockchain.isTheSameOrTestnetBlockchain(blockchain: Blockchain): Boolean { + return this == blockchain || this == blockchain.getTestnetVersion() } \ No newline at end of file