Updated on 2026-08-14
This commit is contained in:
commit
86be6b105e
8 changed files with 44 additions and 14 deletions
|
|
@ -26,6 +26,7 @@ import com.tangem.features.managetokens.component.ManageTokensMode
|
|||
import com.tangem.features.managetokens.component.ManageTokensSource
|
||||
import com.tangem.features.managetokens.component.analytics.CommonManageTokensAnalyticEvents
|
||||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM
|
||||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM.Basic
|
||||
import com.tangem.features.managetokens.entity.managetokens.ManageTokensTopBarUM
|
||||
import com.tangem.features.managetokens.entity.managetokens.ManageTokensUM
|
||||
import com.tangem.features.managetokens.impl.R
|
||||
|
|
@ -42,7 +43,6 @@ import kotlinx.coroutines.flow.*
|
|||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.isNotEmpty
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@ModelScoped
|
||||
|
|
@ -95,7 +95,7 @@ internal class ChooseManagedTokensModel @Inject constructor(
|
|||
observeSearchQueryChanges()
|
||||
|
||||
modelScope.launch {
|
||||
manageTokensListManager.launchPagination()
|
||||
manageTokensListManager.launchPagination(isCollapsed = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -176,8 +176,19 @@ internal class ChooseManagedTokensModel @Inject constructor(
|
|||
uiState.update { state ->
|
||||
state.copy(
|
||||
readContent = state.readContent.copy(
|
||||
items = items.filterNot {
|
||||
it.id.value == params.initialCurrency.id.rawCurrencyId?.value
|
||||
items = items.filterNot { currency ->
|
||||
val availableNetworks = (currency as? Basic)?.networks as? Basic.NetworksUM.Expanded
|
||||
|
||||
// Check whether currency is initial token
|
||||
val isToken = currency.id.value == params.initialCurrency.id.rawCurrencyId?.value
|
||||
|
||||
// Ensure that initial token network is filtered out and network list is empty
|
||||
val isEmptyNetworks = availableNetworks?.networks?.filterNot { network ->
|
||||
network.id == params.initialCurrency.network.id.rawId.value
|
||||
}.isNullOrEmpty()
|
||||
|
||||
// Filter out currency from display
|
||||
isToken && isEmptyNetworks
|
||||
}.toPersistentList(),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ internal class ManageTokensModel @Inject constructor(
|
|||
observeSearchQueryChanges()
|
||||
|
||||
modelScope.launch {
|
||||
manageTokensListManager.launchPagination()
|
||||
manageTokensListManager.launchPagination(isCollapsed = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ internal class OnboardingManageTokensModel @Inject constructor(
|
|||
observeSearchQueryChanges()
|
||||
|
||||
modelScope.launch {
|
||||
manageTokensListManager.launchPagination()
|
||||
manageTokensListManager.launchPagination(isCollapsed = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
|||
.distinctUntilChanged()
|
||||
val uiItems: Flow<ImmutableList<CurrencyItemUM>> = uiManager.items
|
||||
|
||||
suspend fun launchPagination() = coroutineScope {
|
||||
suspend fun launchPagination(isCollapsed: Boolean) = coroutineScope {
|
||||
val loadUserTokensFromRemote = when (mode) {
|
||||
is ManageTokensMode.Wallet -> source == ManageTokensSource.ONBOARDING
|
||||
is ManageTokensMode.Account,
|
||||
|
|
@ -100,7 +100,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
|||
)
|
||||
|
||||
batchFlow.state
|
||||
.onEach { state -> updateState(state) }
|
||||
.onEach { state -> updateState(state, isCollapsed) }
|
||||
.flowOn(dispatchers.default)
|
||||
.launchIn(scope = this)
|
||||
.saveIn(jobHolder)
|
||||
|
|
@ -137,7 +137,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun updateState(batchListState: BatchListState<Int, List<ManagedCryptoCurrency>>) {
|
||||
private fun updateState(batchListState: BatchListState<Int, List<ManagedCryptoCurrency>>, isCollapsed: Boolean) {
|
||||
state.update { state ->
|
||||
state.copy(
|
||||
status = batchListState.status,
|
||||
|
|
@ -186,7 +186,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
|||
}
|
||||
state.copy(
|
||||
currencyBatches = newBatches,
|
||||
uiBatches = uiManager.createOrUpdateUiBatches(newBatches, canEditItems),
|
||||
uiBatches = uiManager.createOrUpdateUiBatches(newBatches, canEditItems, isCollapsed),
|
||||
canEditItems = canEditItems,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ internal class ManageTokensUiManager(
|
|||
fun createOrUpdateUiBatches(
|
||||
newCurrencyBatches: List<Batch<Int, List<ManagedCryptoCurrency>>>,
|
||||
canEditItems: Boolean,
|
||||
isCollapsed: Boolean,
|
||||
): List<Batch<Int, List<CurrencyItemUM>>> {
|
||||
val currentUiBatches = state.value.uiBatches
|
||||
val batches = currentUiBatches.toMutableList()
|
||||
|
|
@ -54,6 +55,7 @@ internal class ManageTokensUiManager(
|
|||
isEditable = canEditItems,
|
||||
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
||||
onTokenClick = actions::onTokenClick,
|
||||
isCollapsed = isCollapsed,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
@ -78,6 +80,7 @@ internal class ManageTokensUiManager(
|
|||
isEditable = canEditItems,
|
||||
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
||||
onTokenClick = actions::onTokenClick,
|
||||
isCollapsed = isCollapsed,
|
||||
)
|
||||
} else {
|
||||
previousUiItem.update(item)
|
||||
|
|
|
|||
|
|
@ -8,14 +8,16 @@ import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
|
|||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM
|
||||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM.Basic.NetworksUM
|
||||
import com.tangem.features.managetokens.utils.ui.getIconRes
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
internal fun ManagedCryptoCurrency.toUiModel(
|
||||
isEditable: Boolean,
|
||||
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
||||
onRemoveCustomCurrencyClick: (ManagedCryptoCurrency.Custom) -> Unit,
|
||||
isCollapsed: Boolean,
|
||||
): CurrencyItemUM = when (this) {
|
||||
is ManagedCryptoCurrency.Custom -> toUiModel(onRemoveCustomCurrencyClick)
|
||||
is ManagedCryptoCurrency.Token -> toUiModel(isEditable, onTokenClick)
|
||||
is ManagedCryptoCurrency.Token -> toUiModel(isEditable, onTokenClick, isCollapsed)
|
||||
}
|
||||
|
||||
private fun ManagedCryptoCurrency.Custom.toUiModel(
|
||||
|
|
@ -54,6 +56,7 @@ private fun ManagedCryptoCurrency.Custom.toUiModel(
|
|||
private fun ManagedCryptoCurrency.Token.toUiModel(
|
||||
isEditable: Boolean,
|
||||
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
||||
isCollapsed: Boolean,
|
||||
): CurrencyItemUM {
|
||||
val background = TangemColorPalette.Black
|
||||
|
||||
|
|
@ -69,7 +72,20 @@ private fun ManagedCryptoCurrency.Token.toUiModel(
|
|||
fallbackTint = getTintForTokenIcon(background),
|
||||
fallbackBackground = background,
|
||||
),
|
||||
networks = NetworksUM.Collapsed,
|
||||
networks = if (isCollapsed) {
|
||||
NetworksUM.Collapsed
|
||||
} else {
|
||||
NetworksUM.Expanded(
|
||||
availableNetworks.map {
|
||||
it.toCurrencyNetworkModel(
|
||||
isSelected = it.network in addedIn,
|
||||
isEditable = false,
|
||||
onSelectedStateChange = { _, _ -> },
|
||||
onLongTap = { _ -> },
|
||||
)
|
||||
}.toImmutableList(),
|
||||
)
|
||||
},
|
||||
onExpandClick = {
|
||||
onTokenClick(this)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ internal fun Network.toCurrencyNetworkModel(
|
|||
)
|
||||
}
|
||||
|
||||
private fun SourceNetwork.toCurrencyNetworkModel(
|
||||
internal fun SourceNetwork.toCurrencyNetworkModel(
|
||||
isSelected: Boolean,
|
||||
isEditable: Boolean,
|
||||
onSelectedStateChange: (SourceNetwork, Boolean) -> Unit,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 4c0c522992e9ae84c42eeb45564a56b84fe337ef
|
||||
Subproject commit c25ebad5af5776af0c06e52a2a2eb12b886f6cfd
|
||||
Loading…
Add table
Add a link
Reference in a new issue