Updated on 2026-08-14
This commit is contained in:
parent
8c3972bc43
commit
05d2286ed7
9 changed files with 87 additions and 9 deletions
|
|
@ -167,6 +167,7 @@ internal object WalletPreviewData {
|
|||
iconState = tokenIconState,
|
||||
titleState = TokenItemState.TitleState.Content(text = "Polygon"),
|
||||
cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = "3 172,14 $"),
|
||||
isBalanceHidden = false,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@ internal fun TokenItem(
|
|||
.tokenClickable(state = state)
|
||||
.background(color = TangemTheme.colors.background.primary),
|
||||
) {
|
||||
val isBalanceHidden = (state as? TokenItemState.Content)?.isBalanceHidden ?: false
|
||||
val isBalanceHidden = (state as? TokenItemState.Content)?.isBalanceHidden
|
||||
?: (state as? TokenItemState.Draggable)?.isBalanceHidden
|
||||
?: false
|
||||
|
||||
TokenIcon(state = state.iconState, modifier = Modifier.layoutId(layoutId = LayoutId.ICON))
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ internal sealed class TokenItemState {
|
|||
override val iconState: IconState,
|
||||
override val titleState: TitleState,
|
||||
override val cryptoAmountState: CryptoAmountState,
|
||||
val isBalanceHidden: Boolean,
|
||||
) : TokenItemState() {
|
||||
override val fiatAmountState: FiatAmountState? = null
|
||||
override val priceChangeState: PriceChangeState? = null
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeToken
|
|||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.InProgressStateConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.TokenListToStateConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.error.TokenListHiddenStateConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.error.TokenListErrorConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.error.TokenListSortingErrorConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.items.CryptoCurrencyToDraggableItemConverter
|
||||
|
|
@ -24,12 +25,14 @@ internal class OrganizeTokensStateHolder(
|
|||
private val intents: OrganizeTokensIntents,
|
||||
private val dragAndDropIntents: DragAndDropIntents,
|
||||
private val appCurrencyProvider: Provider<AppCurrency>,
|
||||
private val isBalanceHiddenProvider: Provider<Boolean>,
|
||||
private val listStateProvider: Provider<OrganizeTokensListState>,
|
||||
) {
|
||||
|
||||
private val stateFlowInternal: MutableStateFlow<OrganizeTokensState> = MutableStateFlow(getInitialState())
|
||||
|
||||
private val tokenListConverter by lazy {
|
||||
val tokensConverter = CryptoCurrencyToDraggableItemConverter(appCurrencyProvider)
|
||||
val tokensConverter = CryptoCurrencyToDraggableItemConverter(appCurrencyProvider, isBalanceHiddenProvider)
|
||||
val itemsConverter = TokenListToListStateConverter(
|
||||
tokensConverter = tokensConverter,
|
||||
groupsConverter = NetworkGroupToDraggableItemsConverter(tokensConverter),
|
||||
|
|
@ -38,9 +41,8 @@ internal class OrganizeTokensStateHolder(
|
|||
TokenListToStateConverter(Provider(stateFlowInternal::value), itemsConverter)
|
||||
}
|
||||
|
||||
private val inProgressStateConverter by lazy {
|
||||
InProgressStateConverter()
|
||||
}
|
||||
private val inProgressStateConverter by lazy { InProgressStateConverter() }
|
||||
private val tokenListHiddenStateConverter by lazy { TokenListHiddenStateConverter(listStateProvider) }
|
||||
|
||||
private val tokenListErrorConverter by lazy {
|
||||
TokenListErrorConverter(Provider(stateFlowInternal::value), inProgressStateConverter)
|
||||
|
|
@ -80,6 +82,10 @@ internal class OrganizeTokensStateHolder(
|
|||
updateState { copy(header = header.copy(isSortedByBalance = false)) }
|
||||
}
|
||||
|
||||
fun updateHiddenState(isBalanceHidden: Boolean) {
|
||||
updateState { copy(itemsState = tokenListHiddenStateConverter.convert(isBalanceHidden)) }
|
||||
}
|
||||
|
||||
fun updateStateWithError(error: TokenListError) {
|
||||
updateState { tokenListErrorConverter.convert(error) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler
|
|||
import com.tangem.core.analytics.models.AnalyticsParam
|
||||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.balancehiding.IsBalanceHiddenUseCase
|
||||
import com.tangem.domain.balancehiding.ListenToFlipsUseCase
|
||||
import com.tangem.domain.tokens.ApplyTokenListSortingUseCase
|
||||
import com.tangem.domain.tokens.GetTokenListUseCase
|
||||
import com.tangem.domain.tokens.ToggleTokenListGroupingUseCase
|
||||
|
|
@ -36,6 +38,8 @@ internal class OrganizeTokensViewModel @Inject constructor(
|
|||
private val toggleTokenListSortingUseCase: ToggleTokenListSortingUseCase,
|
||||
private val applyTokenListSortingUseCase: ApplyTokenListSortingUseCase,
|
||||
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
|
||||
private val isBalanceHiddenUseCase: IsBalanceHiddenUseCase,
|
||||
private val listenToFlipsUseCase: ListenToFlipsUseCase,
|
||||
private val analyticsEventsHandler: AnalyticsEventHandler,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
savedStateHandle: SavedStateHandle,
|
||||
|
|
@ -45,6 +49,8 @@ internal class OrganizeTokensViewModel @Inject constructor(
|
|||
|
||||
private val selectedAppCurrencyFlow = createSelectedAppCurrencyFlow()
|
||||
|
||||
private var isBalanceHidden = true
|
||||
|
||||
private val dragAndDropAdapter = DragAndDropAdapter(
|
||||
listStateProvider = Provider { uiState.value.itemsState },
|
||||
)
|
||||
|
|
@ -53,6 +59,8 @@ internal class OrganizeTokensViewModel @Inject constructor(
|
|||
intents = this,
|
||||
dragAndDropIntents = dragAndDropAdapter,
|
||||
appCurrencyProvider = Provider(selectedAppCurrencyFlow::value),
|
||||
isBalanceHiddenProvider = Provider { isBalanceHidden },
|
||||
listStateProvider = Provider { uiState.value.itemsState },
|
||||
)
|
||||
|
||||
private val userWalletId: UserWalletId by lazy {
|
||||
|
|
@ -68,6 +76,20 @@ internal class OrganizeTokensViewModel @Inject constructor(
|
|||
override fun onCreate(owner: LifecycleOwner) {
|
||||
analyticsEventsHandler.send(PortfolioOrganizeTokensAnalyticsEvent.ScreenOpened)
|
||||
|
||||
isBalanceHiddenUseCase()
|
||||
.flowWithLifecycle(owner.lifecycle)
|
||||
.onEach { hidden ->
|
||||
isBalanceHidden = hidden
|
||||
stateHolder.updateHiddenState(isBalanceHidden)
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
viewModelScope.launch {
|
||||
listenToFlipsUseCase()
|
||||
.flowWithLifecycle(owner.lifecycle)
|
||||
.collect()
|
||||
}
|
||||
|
||||
bootstrapTokenList()
|
||||
bootstrapDragAndDropUpdates()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,12 @@ internal sealed class OrganizeTokensListState {
|
|||
object Empty : OrganizeTokensListState() {
|
||||
override val items: PersistentList<DraggableItem> = persistentListOf()
|
||||
}
|
||||
|
||||
fun copySealed(items: PersistentList<DraggableItem> = this.items): OrganizeTokensListState {
|
||||
return when (this) {
|
||||
is GroupedByNetwork -> copy(items = items)
|
||||
is Ungrouped -> copy(items = items)
|
||||
is Empty -> Empty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.error
|
||||
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.utils.converter.Converter
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
internal class TokenListHiddenStateConverter(
|
||||
private val currentStateProvider: Provider<OrganizeTokensListState>,
|
||||
) : Converter<Boolean, OrganizeTokensListState> {
|
||||
|
||||
override fun convert(input: Boolean): OrganizeTokensListState {
|
||||
val currentState = currentStateProvider()
|
||||
val isBalanceHidden = input
|
||||
|
||||
return currentState.copySealed(
|
||||
currentState.items.map { draggableItem ->
|
||||
if (draggableItem is DraggableItem.Token) {
|
||||
draggableItem.copy(
|
||||
tokenItemState = draggableItem.tokenItemState.copy(
|
||||
isBalanceHidden = isBalanceHidden,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
draggableItem
|
||||
}
|
||||
}.toPersistentList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,26 +13,29 @@ import com.tangem.utils.converter.Converter
|
|||
|
||||
internal class CryptoCurrencyToDraggableItemConverter(
|
||||
private val appCurrencyProvider: Provider<AppCurrency>,
|
||||
private val isBalanceHiddenProvider: Provider<Boolean>,
|
||||
) : Converter<CryptoCurrencyStatus, DraggableItem.Token> {
|
||||
|
||||
private val iconStateConverter = CryptoCurrencyToIconStateConverter()
|
||||
|
||||
override fun convert(value: CryptoCurrencyStatus): DraggableItem.Token {
|
||||
return createDraggableToken(value, appCurrencyProvider())
|
||||
return createDraggableToken(value, appCurrencyProvider(), isBalanceHiddenProvider())
|
||||
}
|
||||
|
||||
override fun convertList(input: Collection<CryptoCurrencyStatus>): List<DraggableItem.Token> {
|
||||
val appCurrency = appCurrencyProvider()
|
||||
val isBalanceHidden = isBalanceHiddenProvider()
|
||||
|
||||
return input.map { createDraggableToken(it, appCurrency) }
|
||||
return input.map { createDraggableToken(it, appCurrency, isBalanceHidden) }
|
||||
}
|
||||
|
||||
private fun createDraggableToken(
|
||||
currencyStatus: CryptoCurrencyStatus,
|
||||
appCurrency: AppCurrency,
|
||||
isBalanceHidden: Boolean,
|
||||
): DraggableItem.Token {
|
||||
return DraggableItem.Token(
|
||||
tokenItemState = createTokenItemState(currencyStatus, appCurrency),
|
||||
tokenItemState = createTokenItemState(currencyStatus, appCurrency, isBalanceHidden),
|
||||
groupId = getGroupHeaderId(currencyStatus.currency.network),
|
||||
)
|
||||
}
|
||||
|
|
@ -40,6 +43,7 @@ internal class CryptoCurrencyToDraggableItemConverter(
|
|||
private fun createTokenItemState(
|
||||
currencyStatus: CryptoCurrencyStatus,
|
||||
appCurrency: AppCurrency,
|
||||
isBalanceHidden: Boolean,
|
||||
): TokenItemState.Draggable {
|
||||
val currency = currencyStatus.currency
|
||||
|
||||
|
|
@ -52,6 +56,8 @@ internal class CryptoCurrencyToDraggableItemConverter(
|
|||
} else {
|
||||
TokenItemState.CryptoAmountState.Content(text = getFormattedFiatAmount(currencyStatus, appCurrency))
|
||||
},
|
||||
isBalanceHidden = isBalanceHidden,
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
|
|||
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
|
||||
import androidx.compose.ui.unit.*
|
||||
import androidx.constraintlayout.compose.*
|
||||
import com.tangem.common.Strings
|
||||
import com.tangem.core.ui.components.FontSizeRange
|
||||
import com.tangem.core.ui.components.RectangleShimmer
|
||||
import com.tangem.core.ui.components.ResizableText
|
||||
|
|
@ -296,7 +297,7 @@ private fun Balance(state: WalletCardState, modifier: Modifier = Modifier) {
|
|||
style = TangemTheme.typography.h2,
|
||||
)
|
||||
}
|
||||
is WalletCardState.HiddenContent -> NonContentBalanceText(text = WalletCardState.HIDDEN_BALANCE_TEXT)
|
||||
is WalletCardState.HiddenContent -> NonContentBalanceText(TextReference.Str(Strings.STARS))
|
||||
is WalletCardState.Error -> NonContentBalanceText(text = WalletCardState.EMPTY_BALANCE_TEXT)
|
||||
is WalletCardState.Loading -> {
|
||||
RectangleShimmer(modifier = Modifier.nonContentBalanceSize(TangemTheme.dimens))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue