Updated on 2026-08-14
This commit is contained in:
parent
642bcca31f
commit
81a16c8bb1
46 changed files with 610 additions and 615 deletions
|
|
@ -3,49 +3,50 @@ package com.tangem.feature.wallet.presentation.wallet.utils
|
|||
import androidx.annotation.DrawableRes
|
||||
import com.tangem.core.ui.components.marketprice.PriceChangeConfig
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.tokens.model.TokenStatus
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.utils.converter.Converter
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class TokenStatusToTokenItemConverter(
|
||||
internal class CryptoCurrencyStatusToTokenItemConverter(
|
||||
private val isWalletContentHidden: Boolean,
|
||||
private val fiatCurrencyCode: String,
|
||||
private val fiatCurrencySymbol: String,
|
||||
) : Converter<TokenStatus, TokenItemState> {
|
||||
) : Converter<CryptoCurrencyStatus, TokenItemState> {
|
||||
|
||||
private val TokenStatus.networkIconResId: Int?
|
||||
private val CryptoCurrencyStatus.networkIconResId: Int?
|
||||
@DrawableRes get() {
|
||||
// TODO: [REDACTED_JIRA]
|
||||
return if (isCoin) null else R.drawable.img_eth_22
|
||||
return if (currency is CryptoCurrency.Token) null else R.drawable.img_eth_22
|
||||
}
|
||||
|
||||
private val TokenStatus.tokenIconResId: Int
|
||||
private val CryptoCurrencyStatus.tokenIconResId: Int
|
||||
@DrawableRes get() {
|
||||
// TODO: [REDACTED_JIRA]
|
||||
return R.drawable.img_eth_22
|
||||
}
|
||||
|
||||
override fun convert(value: TokenStatus): TokenItemState {
|
||||
override fun convert(value: CryptoCurrencyStatus): TokenItemState {
|
||||
return when (value.value) {
|
||||
is TokenStatus.Loading -> TokenItemState.Loading
|
||||
is TokenStatus.Loaded,
|
||||
is TokenStatus.Custom,
|
||||
is CryptoCurrencyStatus.Loading -> TokenItemState.Loading
|
||||
is CryptoCurrencyStatus.Loaded,
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
-> value.mapToTokenItemState()
|
||||
// TODO: Add other token item states, currently not designed
|
||||
is TokenStatus.MissedDerivation,
|
||||
is TokenStatus.NoAccount,
|
||||
is TokenStatus.Unreachable,
|
||||
is CryptoCurrencyStatus.MissedDerivation,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
-> value.mapToUnreachableTokenItemState()
|
||||
}
|
||||
}
|
||||
|
||||
private fun TokenStatus.mapToTokenItemState(): TokenItemState.Content {
|
||||
private fun CryptoCurrencyStatus.mapToTokenItemState(): TokenItemState.Content {
|
||||
return TokenItemState.Content(
|
||||
id = this.id.value,
|
||||
name = this.name,
|
||||
tokenIconUrl = this.iconUrl,
|
||||
id = currency.id.value,
|
||||
name = currency.name,
|
||||
tokenIconUrl = currency.iconUrl,
|
||||
tokenIconResId = this.tokenIconResId,
|
||||
networkIconResId = this.networkIconResId,
|
||||
amount = getFormattedAmount(),
|
||||
|
|
@ -61,27 +62,27 @@ internal class TokenStatusToTokenItemConverter(
|
|||
)
|
||||
}
|
||||
|
||||
private fun TokenStatus.getFormattedAmount(): String {
|
||||
private fun CryptoCurrencyStatus.getFormattedAmount(): String {
|
||||
val amount = value.amount ?: return UNKNOWN_AMOUNT_SIGN
|
||||
|
||||
return BigDecimalFormatter.formatCryptoAmount(amount, symbol, decimals)
|
||||
return BigDecimalFormatter.formatCryptoAmount(amount, currency.symbol, currency.decimals)
|
||||
}
|
||||
|
||||
private fun TokenStatus.getFormattedFiatAmount(): String {
|
||||
private fun CryptoCurrencyStatus.getFormattedFiatAmount(): String {
|
||||
val fiatAmount = value.fiatAmount ?: return UNKNOWN_AMOUNT_SIGN
|
||||
|
||||
return BigDecimalFormatter.formatFiatAmount(fiatAmount, fiatCurrencyCode, fiatCurrencySymbol)
|
||||
}
|
||||
|
||||
private fun TokenStatus.mapToUnreachableTokenItemState() = TokenItemState.Unreachable(
|
||||
id = this.id.value,
|
||||
name = this.name,
|
||||
tokenIconUrl = this.iconUrl,
|
||||
private fun CryptoCurrencyStatus.mapToUnreachableTokenItemState() = TokenItemState.Unreachable(
|
||||
id = currency.id.value,
|
||||
name = currency.name,
|
||||
tokenIconUrl = currency.iconUrl,
|
||||
tokenIconResId = this.tokenIconResId,
|
||||
networkIconResId = this.networkIconResId,
|
||||
)
|
||||
|
||||
private fun TokenStatus.getPriceChangeConfig(): PriceChangeConfig {
|
||||
private fun CryptoCurrencyStatus.getPriceChangeConfig(): PriceChangeConfig {
|
||||
val priceChange = value.priceChange
|
||||
?: return PriceChangeConfig(UNKNOWN_AMOUNT_SIGN, PriceChangeConfig.Type.DOWN)
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.utils
|
||||
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.model.TokenStatus
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState.TokensListItemState
|
||||
import com.tangem.feature.wallet.presentation.wallet.utils.LoadingItemsProvider.getLoadingMultiCurrencyTokens
|
||||
|
|
@ -19,7 +19,7 @@ internal class TokenListToContentItemsConverter(
|
|||
private val clickCallbacks: WalletClickCallbacks,
|
||||
) : Converter<TokenList, WalletTokensListState> {
|
||||
|
||||
private val tokenStatusConverter = TokenStatusToTokenItemConverter(
|
||||
private val tokenStatusConverter = CryptoCurrencyStatusToTokenItemConverter(
|
||||
isWalletContentHidden = isWalletContentHidden,
|
||||
fiatCurrencyCode = fiatCurrencyCode,
|
||||
fiatCurrencySymbol = fiatCurrencySymbol,
|
||||
|
|
@ -47,7 +47,7 @@ internal class TokenListToContentItemsConverter(
|
|||
}
|
||||
|
||||
private fun TokenList.Ungrouped.mapToMultiCurrencyItems(): PersistentList<TokensListItemState> {
|
||||
return tokens.fold(initial = persistentListOf()) { acc, token ->
|
||||
return currencies.fold(initial = persistentListOf()) { acc, token ->
|
||||
acc.mutate { it.addToken(token) }
|
||||
}
|
||||
}
|
||||
|
|
@ -55,14 +55,14 @@ internal class TokenListToContentItemsConverter(
|
|||
private fun MutableList<TokensListItemState>.addGroup(group: NetworkGroup): List<TokensListItemState> {
|
||||
this.add(TokensListItemState.NetworkGroupTitle(group.network.name))
|
||||
|
||||
group.tokens.forEach { token ->
|
||||
group.currencies.forEach { token ->
|
||||
this.addToken(token)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
private fun MutableList<TokensListItemState>.addToken(token: TokenStatus): List<TokensListItemState> {
|
||||
private fun MutableList<TokensListItemState>.addToken(token: CryptoCurrencyStatus): List<TokensListItemState> {
|
||||
val tokenItemState = tokenStatusConverter.convert(token)
|
||||
|
||||
this.add(TokensListItemState.Token(tokenItemState))
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels
|
|||
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.domain.common.CardTypesResolver
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.model.TokenStatus
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.WalletNotification
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder
|
||||
|
|
@ -123,12 +123,12 @@ internal class WalletNotificationsListFactory(
|
|||
|
||||
private fun TokenList.hasMissedDerivations(): Boolean {
|
||||
val statuses = when (this) {
|
||||
is TokenList.GroupedByNetwork -> groups.flatMap(NetworkGroup::tokens).map(TokenStatus::value)
|
||||
is TokenList.Ungrouped -> tokens.map(TokenStatus::value)
|
||||
is TokenList.GroupedByNetwork -> groups.flatMap(NetworkGroup::currencies).map(CryptoCurrencyStatus::value)
|
||||
is TokenList.Ungrouped -> currencies.map(CryptoCurrencyStatus::value)
|
||||
TokenList.NotInitialized -> emptyList()
|
||||
}
|
||||
|
||||
return statuses.any { it is TokenStatus.MissedDerivation }
|
||||
return statuses.any { it is CryptoCurrencyStatus.MissedDerivation }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue