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.ManageTokensSource
|
||||||
import com.tangem.features.managetokens.component.analytics.CommonManageTokensAnalyticEvents
|
import com.tangem.features.managetokens.component.analytics.CommonManageTokensAnalyticEvents
|
||||||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM
|
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.ManageTokensTopBarUM
|
||||||
import com.tangem.features.managetokens.entity.managetokens.ManageTokensUM
|
import com.tangem.features.managetokens.entity.managetokens.ManageTokensUM
|
||||||
import com.tangem.features.managetokens.impl.R
|
import com.tangem.features.managetokens.impl.R
|
||||||
|
|
@ -42,7 +43,6 @@ import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.isNotEmpty
|
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
@ModelScoped
|
@ModelScoped
|
||||||
|
|
@ -95,7 +95,7 @@ internal class ChooseManagedTokensModel @Inject constructor(
|
||||||
observeSearchQueryChanges()
|
observeSearchQueryChanges()
|
||||||
|
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
manageTokensListManager.launchPagination()
|
manageTokensListManager.launchPagination(isCollapsed = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,8 +176,19 @@ internal class ChooseManagedTokensModel @Inject constructor(
|
||||||
uiState.update { state ->
|
uiState.update { state ->
|
||||||
state.copy(
|
state.copy(
|
||||||
readContent = state.readContent.copy(
|
readContent = state.readContent.copy(
|
||||||
items = items.filterNot {
|
items = items.filterNot { currency ->
|
||||||
it.id.value == params.initialCurrency.id.rawCurrencyId?.value
|
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(),
|
}.toPersistentList(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ internal class ManageTokensModel @Inject constructor(
|
||||||
observeSearchQueryChanges()
|
observeSearchQueryChanges()
|
||||||
|
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
manageTokensListManager.launchPagination()
|
manageTokensListManager.launchPagination(isCollapsed = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ internal class OnboardingManageTokensModel @Inject constructor(
|
||||||
observeSearchQueryChanges()
|
observeSearchQueryChanges()
|
||||||
|
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
manageTokensListManager.launchPagination()
|
manageTokensListManager.launchPagination(isCollapsed = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
val uiItems: Flow<ImmutableList<CurrencyItemUM>> = uiManager.items
|
val uiItems: Flow<ImmutableList<CurrencyItemUM>> = uiManager.items
|
||||||
|
|
||||||
suspend fun launchPagination() = coroutineScope {
|
suspend fun launchPagination(isCollapsed: Boolean) = coroutineScope {
|
||||||
val loadUserTokensFromRemote = when (mode) {
|
val loadUserTokensFromRemote = when (mode) {
|
||||||
is ManageTokensMode.Wallet -> source == ManageTokensSource.ONBOARDING
|
is ManageTokensMode.Wallet -> source == ManageTokensSource.ONBOARDING
|
||||||
is ManageTokensMode.Account,
|
is ManageTokensMode.Account,
|
||||||
|
|
@ -100,7 +100,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
|
|
||||||
batchFlow.state
|
batchFlow.state
|
||||||
.onEach { state -> updateState(state) }
|
.onEach { state -> updateState(state, isCollapsed) }
|
||||||
.flowOn(dispatchers.default)
|
.flowOn(dispatchers.default)
|
||||||
.launchIn(scope = this)
|
.launchIn(scope = this)
|
||||||
.saveIn(jobHolder)
|
.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.update { state ->
|
||||||
state.copy(
|
state.copy(
|
||||||
status = batchListState.status,
|
status = batchListState.status,
|
||||||
|
|
@ -186,7 +186,7 @@ internal class ManageTokensListManager @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
state.copy(
|
state.copy(
|
||||||
currencyBatches = newBatches,
|
currencyBatches = newBatches,
|
||||||
uiBatches = uiManager.createOrUpdateUiBatches(newBatches, canEditItems),
|
uiBatches = uiManager.createOrUpdateUiBatches(newBatches, canEditItems, isCollapsed),
|
||||||
canEditItems = canEditItems,
|
canEditItems = canEditItems,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ internal class ManageTokensUiManager(
|
||||||
fun createOrUpdateUiBatches(
|
fun createOrUpdateUiBatches(
|
||||||
newCurrencyBatches: List<Batch<Int, List<ManagedCryptoCurrency>>>,
|
newCurrencyBatches: List<Batch<Int, List<ManagedCryptoCurrency>>>,
|
||||||
canEditItems: Boolean,
|
canEditItems: Boolean,
|
||||||
|
isCollapsed: Boolean,
|
||||||
): List<Batch<Int, List<CurrencyItemUM>>> {
|
): List<Batch<Int, List<CurrencyItemUM>>> {
|
||||||
val currentUiBatches = state.value.uiBatches
|
val currentUiBatches = state.value.uiBatches
|
||||||
val batches = currentUiBatches.toMutableList()
|
val batches = currentUiBatches.toMutableList()
|
||||||
|
|
@ -54,6 +55,7 @@ internal class ManageTokensUiManager(
|
||||||
isEditable = canEditItems,
|
isEditable = canEditItems,
|
||||||
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
||||||
onTokenClick = actions::onTokenClick,
|
onTokenClick = actions::onTokenClick,
|
||||||
|
isCollapsed = isCollapsed,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -78,6 +80,7 @@ internal class ManageTokensUiManager(
|
||||||
isEditable = canEditItems,
|
isEditable = canEditItems,
|
||||||
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
onRemoveCustomCurrencyClick = ::removeCustomCurrency,
|
||||||
onTokenClick = actions::onTokenClick,
|
onTokenClick = actions::onTokenClick,
|
||||||
|
isCollapsed = isCollapsed,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
previousUiItem.update(item)
|
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
|
||||||
import com.tangem.features.managetokens.entity.item.CurrencyItemUM.Basic.NetworksUM
|
import com.tangem.features.managetokens.entity.item.CurrencyItemUM.Basic.NetworksUM
|
||||||
import com.tangem.features.managetokens.utils.ui.getIconRes
|
import com.tangem.features.managetokens.utils.ui.getIconRes
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
internal fun ManagedCryptoCurrency.toUiModel(
|
internal fun ManagedCryptoCurrency.toUiModel(
|
||||||
isEditable: Boolean,
|
isEditable: Boolean,
|
||||||
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
||||||
onRemoveCustomCurrencyClick: (ManagedCryptoCurrency.Custom) -> Unit,
|
onRemoveCustomCurrencyClick: (ManagedCryptoCurrency.Custom) -> Unit,
|
||||||
|
isCollapsed: Boolean,
|
||||||
): CurrencyItemUM = when (this) {
|
): CurrencyItemUM = when (this) {
|
||||||
is ManagedCryptoCurrency.Custom -> toUiModel(onRemoveCustomCurrencyClick)
|
is ManagedCryptoCurrency.Custom -> toUiModel(onRemoveCustomCurrencyClick)
|
||||||
is ManagedCryptoCurrency.Token -> toUiModel(isEditable, onTokenClick)
|
is ManagedCryptoCurrency.Token -> toUiModel(isEditable, onTokenClick, isCollapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ManagedCryptoCurrency.Custom.toUiModel(
|
private fun ManagedCryptoCurrency.Custom.toUiModel(
|
||||||
|
|
@ -54,6 +56,7 @@ private fun ManagedCryptoCurrency.Custom.toUiModel(
|
||||||
private fun ManagedCryptoCurrency.Token.toUiModel(
|
private fun ManagedCryptoCurrency.Token.toUiModel(
|
||||||
isEditable: Boolean,
|
isEditable: Boolean,
|
||||||
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
onTokenClick: (ManagedCryptoCurrency.Token) -> Unit,
|
||||||
|
isCollapsed: Boolean,
|
||||||
): CurrencyItemUM {
|
): CurrencyItemUM {
|
||||||
val background = TangemColorPalette.Black
|
val background = TangemColorPalette.Black
|
||||||
|
|
||||||
|
|
@ -69,7 +72,20 @@ private fun ManagedCryptoCurrency.Token.toUiModel(
|
||||||
fallbackTint = getTintForTokenIcon(background),
|
fallbackTint = getTintForTokenIcon(background),
|
||||||
fallbackBackground = 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 = {
|
onExpandClick = {
|
||||||
onTokenClick(this)
|
onTokenClick(this)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ internal fun Network.toCurrencyNetworkModel(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SourceNetwork.toCurrencyNetworkModel(
|
internal fun SourceNetwork.toCurrencyNetworkModel(
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
isEditable: Boolean,
|
isEditable: Boolean,
|
||||||
onSelectedStateChange: (SourceNetwork, Boolean) -> Unit,
|
onSelectedStateChange: (SourceNetwork, Boolean) -> Unit,
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4c0c522992e9ae84c42eeb45564a56b84fe337ef
|
Subproject commit c25ebad5af5776af0c06e52a2a2eb12b886f6cfd
|
||||||
Loading…
Add table
Add a link
Reference in a new issue