Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-16 18:00:50 +04:00
parent e14e82a284
commit 5ef69ea4b6
5 changed files with 70 additions and 43 deletions

View file

@ -22,8 +22,10 @@ dependencies {
implementation(projects.core.featuretoggles)
/* Project - Domain */
implementation(projects.domain.wallets.models)
implementation(projects.domain.manageTokens)
implementation(projects.domain.tokens)
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets.models)
/* AndroidX */
implementation(deps.androidx.activity.compose)

View file

@ -9,11 +9,14 @@ import androidx.compose.ui.util.fastForEachIndexed
import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
import com.tangem.core.ui.components.fields.entity.SearchBarUM
import com.tangem.core.ui.components.rows.model.ChainRowUM
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
import com.tangem.domain.tokens.model.Network
import com.tangem.features.managetokens.component.ManageTokensComponent
import com.tangem.features.managetokens.entity.*
import com.tangem.features.managetokens.entity.CurrencyItemUM
import com.tangem.features.managetokens.entity.CurrencyNetworkUM
import com.tangem.features.managetokens.entity.ManageTokensTopBarUM
import com.tangem.features.managetokens.entity.ManageTokensUM
import com.tangem.features.managetokens.impl.R
import com.tangem.features.managetokens.ui.ManageTokensScreen
import kotlinx.collections.immutable.mutate
@ -47,8 +50,10 @@ internal class PreviewManageTokensComponent : ManageTokensComponent {
onActiveChange = ::toggleSearchBar,
),
hasChanges = false,
isLoading = false,
onSaveClick = {},
isInitialBatchLoading = false,
isNextBatchLoading = true,
loadMore = { false },
saveChanges = {},
),
)
@ -58,7 +63,7 @@ internal class PreviewManageTokensComponent : ManageTokensComponent {
initItems()
} else {
items.filter { currency ->
currency.model.name.contains(query, ignoreCase = true)
currency.name.contains(query, ignoreCase = true)
}.toPersistentList()
}
@ -96,34 +101,28 @@ internal class PreviewManageTokensComponent : ManageTokensComponent {
}.toPersistentList()
private fun getCustomItem(index: Int) = CurrencyItemUM.Custom(
id = index.toString(),
model = ChainRowUM(
name = "Custom token $index",
type = "CT$index",
icon = CurrencyIconState.CustomTokenIcon(
tint = Color.White,
background = Color.Black,
topBadgeIconResId = R.drawable.img_eth_22,
isGrayscale = false,
showCustomBadge = true,
),
showCustom = true,
id = ManagedCryptoCurrency.ID(index.toString()),
name = "Custom token $index",
symbol = "CT$index",
icon = CurrencyIconState.CustomTokenIcon(
tint = Color.White,
background = Color.Black,
topBadgeIconResId = R.drawable.img_eth_22,
isGrayscale = false,
showCustomBadge = true,
),
onRemoveClick = {},
)
private fun getBasicItem(index: Int) = CurrencyItemUM.Basic(
id = index.toString(),
model = ChainRowUM(
name = "Currency $index",
type = "C$index",
icon = CurrencyIconState.CoinIcon(
url = null,
fallbackResId = R.drawable.img_btc_22,
isGrayscale = false,
showCustomBadge = false,
),
showCustom = false,
id = ManagedCryptoCurrency.ID(index.toString()),
name = "Currency $index",
symbol = "C$index",
icon = CurrencyIconState.CoinIcon(
url = null,
fallbackResId = R.drawable.img_btc_22,
isGrayscale = false,
showCustomBadge = false,
),
networks = if (index == 2) {
CurrencyItemUM.Basic.NetworksUM.Expanded(getCurrencyNetworks(index))

View file

@ -1,18 +1,23 @@
package com.tangem.features.managetokens.entity
import androidx.compose.runtime.Immutable
import com.tangem.core.ui.components.rows.model.ChainRowUM
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
import kotlinx.collections.immutable.ImmutableList
@Immutable
internal sealed class CurrencyItemUM {
abstract val id: String
abstract val model: ChainRowUM
abstract val id: ManagedCryptoCurrency.ID
abstract val name: String
abstract val symbol: String
abstract val icon: CurrencyIconState
data class Basic(
override val id: String,
override val model: ChainRowUM,
override val id: ManagedCryptoCurrency.ID,
override val name: String,
override val symbol: String,
override val icon: CurrencyIconState,
val networks: NetworksUM,
val onExpandClick: () -> Unit,
) : CurrencyItemUM() {
@ -29,8 +34,10 @@ internal sealed class CurrencyItemUM {
}
data class Custom(
override val id: String,
override val model: ChainRowUM,
override val id: ManagedCryptoCurrency.ID,
override val name: String,
override val symbol: String,
override val icon: CurrencyIconState,
val onRemoveClick: () -> Unit,
) : CurrencyItemUM()
}

View file

@ -8,26 +8,32 @@ import kotlinx.collections.immutable.ImmutableList
internal sealed class ManageTokensUM {
abstract val popBack: () -> Unit
abstract val isLoading: Boolean
abstract val isInitialBatchLoading: Boolean
abstract val isNextBatchLoading: Boolean
abstract val items: ImmutableList<CurrencyItemUM>
abstract val topBar: ManageTokensTopBarUM
abstract val search: SearchBarUM
abstract val loadMore: () -> Boolean
data class ReadContent(
override val popBack: () -> Unit,
override val isLoading: Boolean,
override val isInitialBatchLoading: Boolean,
override val isNextBatchLoading: Boolean,
override val items: ImmutableList<CurrencyItemUM>,
override val topBar: ManageTokensTopBarUM,
override val search: SearchBarUM,
override val loadMore: () -> Boolean,
) : ManageTokensUM()
data class ManageContent(
override val popBack: () -> Unit,
override val isLoading: Boolean,
override val isInitialBatchLoading: Boolean,
override val isNextBatchLoading: Boolean,
override val items: ImmutableList<CurrencyItemUM>,
override val topBar: ManageTokensTopBarUM,
override val search: SearchBarUM,
val onSaveClick: () -> Unit,
override val loadMore: () -> Boolean,
val saveChanges: () -> Unit,
val hasChanges: Boolean,
) : ManageTokensUM()
@ -35,10 +41,23 @@ internal sealed class ManageTokensUM {
search: SearchBarUM = this.search,
items: ImmutableList<CurrencyItemUM> = this.items,
hasChanges: Boolean = this is ManageContent && this.hasChanges,
isInitialBatchLoading: Boolean = this.isInitialBatchLoading,
isNextBatchLoading: Boolean = this.isNextBatchLoading,
): ManageTokensUM {
return when (this) {
is ManageContent -> copy(search = search, items = items, hasChanges = hasChanges)
is ReadContent -> copy(search = search, items = items)
is ManageContent -> copy(
search = search,
items = items,
hasChanges = hasChanges,
isInitialBatchLoading = isInitialBatchLoading,
isNextBatchLoading = isNextBatchLoading,
)
is ReadContent -> copy(
search = search,
items = items,
isInitialBatchLoading = isInitialBatchLoading,
isNextBatchLoading = isNextBatchLoading,
)
}
}
}

View file

@ -102,7 +102,7 @@ private fun NetworkItem(model: CurrencyNetworkUM, modifier: Modifier = Modifier)
icon = CurrencyIconState.CoinIcon(
url = null,
fallbackResId = model.iconResId,
isGrayscale = false,
isGrayscale = !model.isSelected,
showCustomBadge = false,
),
showCustom = false,