Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-02 16:24:48 +04:00
parent a285866cab
commit 79e262a069
5 changed files with 16 additions and 14 deletions

View file

@ -102,7 +102,7 @@ internal object WalletPreviewData {
url = null,
fallbackResId = R.drawable.img_polygon_22,
isGrayscale = false,
isCustom = false,
showCustomBadge = false,
)
private val tokenIconState
@ -112,6 +112,7 @@ internal object WalletPreviewData {
fallbackTint = TangemColorPalette.Black,
fallbackBackground = TangemColorPalette.Meadow,
isGrayscale = false,
showCustomBadge = false,
)
private val customTokenIconState

View file

@ -236,7 +236,7 @@ private class TokenConfigProvider : CollectionPreviewParameterProvider<TokenItem
),
),
WalletPreviewData.tokenItemVisibleState.copy(
iconState = WalletPreviewData.coinIconState.copy(isCustom = true),
iconState = WalletPreviewData.coinIconState.copy(showCustomBadge = true),
),
WalletPreviewData.tokenItemUnreachableState,
WalletPreviewData.tokenItemNoAddressState,

View file

@ -88,7 +88,7 @@ private fun BoxScope.ContentIconContainer(icon: TokenIconState, modifier: Modifi
)
}
if (icon.isCustom) {
if (icon.showCustomBadge) {
CustomBadge(modifier = Modifier.align(Alignment.BottomEnd))
}
}

View file

@ -124,7 +124,7 @@ internal sealed class TokenItemState {
sealed class IconState {
abstract val isGrayscale: Boolean
abstract val isCustom: Boolean
abstract val showCustomBadge: Boolean
abstract val networkBadgeIconResId: Int?
/**
@ -133,12 +133,13 @@ internal sealed class TokenItemState {
* @property url The URL where the coin icon can be fetched from. May be `null` if not found.
* @property fallbackResId The drawable resource ID to be used as a fallback if the URL is not available.
* @property isGrayscale Specifies whether to show the icon in grayscale.
* @property showCustomBadge Specifies whether to show the custom token badge.
*/
data class CoinIcon(
val url: String?,
@DrawableRes val fallbackResId: Int,
override val isGrayscale: Boolean,
override val isCustom: Boolean,
override val showCustomBadge: Boolean,
) : IconState() {
override val networkBadgeIconResId: Int? = null
@ -150,6 +151,7 @@ internal sealed class TokenItemState {
* @property url The URL where the token icon can be fetched from. May be `null` if not found.
* @property networkBadgeIconResId The drawable resource ID for the network badge.
* @property isGrayscale Specifies whether to show the icon in grayscale.
* @property showCustomBadge Specifies whether to show the custom token badge.
* @property fallbackTint The color to be used for tinting the fallback icon.
* @property fallbackBackground The background color to be used for the fallback icon.
*/
@ -157,12 +159,10 @@ internal sealed class TokenItemState {
val url: String?,
@DrawableRes override val networkBadgeIconResId: Int,
override val isGrayscale: Boolean,
override val showCustomBadge: Boolean,
val fallbackTint: Color,
val fallbackBackground: Color,
) : IconState() {
override val isCustom: Boolean = false
}
) : IconState()
/**
* Represents a custom token icon.
@ -179,18 +179,18 @@ internal sealed class TokenItemState {
override val isGrayscale: Boolean,
) : IconState() {
override val isCustom: Boolean = true
override val showCustomBadge: Boolean = true
}
object Loading : IconState() {
override val isGrayscale: Boolean = false
override val isCustom: Boolean = false
override val showCustomBadge: Boolean = false
override val networkBadgeIconResId: Int? = null
}
object Locked : IconState() {
override val isGrayscale: Boolean = false
override val isCustom: Boolean = false
override val showCustomBadge: Boolean = false
override val networkBadgeIconResId: Int? = null
}
}

View file

@ -25,7 +25,7 @@ internal class CryptoCurrencyToIconStateConverter : Converter<CryptoCurrencyStat
url = coin.iconUrl,
fallbackResId = coin.networkIconResId,
isGrayscale = coin.network.isTestnet || isUnreachable,
isCustom = coin.isCustom,
showCustomBadge = coin.isCustom,
)
}
@ -34,7 +34,7 @@ internal class CryptoCurrencyToIconStateConverter : Converter<CryptoCurrencyStat
val background = token.tryGetBackgroundForTokenIcon(isGrayscale)
val tint = getTintForTokenIcon(background)
return if (token.isCustom) {
return if (token.isCustom && token.iconUrl == null) {
TokenItemState.IconState.CustomTokenIcon(
tint = tint,
background = background,
@ -48,6 +48,7 @@ internal class CryptoCurrencyToIconStateConverter : Converter<CryptoCurrencyStat
isGrayscale = isGrayscale,
fallbackTint = tint,
fallbackBackground = background,
showCustomBadge = token.isCustom, // `true` for tokens with custom derivation
)
}
}