Updated on 2026-08-14
This commit is contained in:
parent
173ea35019
commit
feb4cf76c9
3 changed files with 137 additions and 103 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.common.extensions
|
|||
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.common.extensions.remove
|
||||
import com.tangem.wallet.R
|
||||
|
||||
@DrawableRes
|
||||
|
|
@ -57,4 +58,7 @@ fun Blockchain.getNetworkName(): String {
|
|||
Blockchain.Binance, Blockchain.BinanceTestnet -> "BEP2"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Blockchain.fullNameWithoutTestnet
|
||||
get() = this.fullName.remove(" Testnet")
|
||||
|
|
@ -15,12 +15,15 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.SubcomposeAsyncImage
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.tap.common.extensions.fullNameWithoutTestnet
|
||||
import com.tangem.tap.common.extensions.getGreyedOutIconRes
|
||||
import com.tangem.tap.common.extensions.getNetworkName
|
||||
import com.tangem.tap.common.extensions.getRoundIconRes
|
||||
|
|
@ -90,17 +93,13 @@ fun NetworkItem(
|
|||
.align(Alignment.CenterVertically)
|
||||
) {
|
||||
Text(
|
||||
text = blockchain.fullName.uppercase(),
|
||||
fontSize = 13.sp,
|
||||
text = prepareNetworkNameSpannableText(
|
||||
blockchain = blockchain,
|
||||
contractAddress = contract.address
|
||||
),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (added) Color.Black else Color(0xFF848488),
|
||||
)
|
||||
Spacer(modifier = Modifier.size(3.dp))
|
||||
Text(
|
||||
text = if (contract.address == null) "MAIN" else blockchain.getNetworkName().uppercase(),
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = if (contract.address != null) Color(0xFF8E8E93) else Color(0xFF1ACE80),
|
||||
color = if (added) Color.Black else Color(0xFF848488),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -136,4 +135,33 @@ fun NetworkItem(
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun prepareNetworkNameSpannableText(
|
||||
blockchain: Blockchain,
|
||||
contractAddress: String?
|
||||
): AnnotatedString {
|
||||
|
||||
val blockchainName = blockchain.fullNameWithoutTestnet.uppercase()
|
||||
val additionalText =
|
||||
if (contractAddress == null) "MAIN" else blockchain.getNetworkName().uppercase()
|
||||
|
||||
val text = "$blockchainName $additionalText"
|
||||
|
||||
val startOfAdditionalText =
|
||||
if (additionalText.isNotBlank()) text.indexOf(additionalText) else text.length
|
||||
|
||||
val spanStyles = listOf(
|
||||
AnnotatedString.Range(
|
||||
SpanStyle(
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = if (contractAddress != null) Color(0xFF8E8E93) else Color(0xFF1ACE80)
|
||||
),
|
||||
start = startOfAdditionalText,
|
||||
end = text.length
|
||||
)
|
||||
)
|
||||
return AnnotatedString(text = text, spanStyles = spanStyles)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue