Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-23 18:13:17 +04:00
parent e59c7e5c5a
commit ed3b894c36
11 changed files with 41 additions and 24 deletions

View file

@ -68,6 +68,7 @@ internal class CryptoCurrenciesMocks(private val scanResponse: ScanResponse) {
isTestnet = false,
standardType = Network.StandardType.ERC20,
hasFiatFeeRate = true,
canHandleTokens = true,
),
name = "NEVER-MIND",
symbol = "NEVER-MIND",

View file

@ -23,6 +23,7 @@ fun getNetwork(networkId: Network.ID, derivationPath: Network.DerivationPath): N
currencySymbol = blockchain.currency,
standardType = getNetworkStandardType(blockchain),
hasFiatFeeRate = blockchain.feePaidCurrency() !is FeePaidCurrency.FeeResource,
canHandleTokens = blockchain.canHandleTokens(),
)
}
@ -45,6 +46,7 @@ fun getNetwork(
currencySymbol = blockchain.currency,
standardType = getNetworkStandardType(blockchain),
hasFiatFeeRate = blockchain.feePaidCurrency() !is FeePaidCurrency.FeeResource,
canHandleTokens = blockchain.canHandleTokens(),
)
}

View file

@ -29,6 +29,7 @@ data class Network(
val isTestnet: Boolean,
val standardType: StandardType,
val hasFiatFeeRate: Boolean,
val canHandleTokens: Boolean,
) {
init {

View file

@ -22,6 +22,7 @@ internal object MockNetworks {
currencySymbol = "ETH",
derivationPath = Network.DerivationPath.None,
hasFiatFeeRate = true,
canHandleTokens = true,
)
val network2 = Network(
@ -33,6 +34,7 @@ internal object MockNetworks {
currencySymbol = "ETH",
derivationPath = Network.DerivationPath.None,
hasFiatFeeRate = true,
canHandleTokens = true,
)
val network3 = Network(
@ -44,6 +46,7 @@ internal object MockNetworks {
currencySymbol = "ETH",
derivationPath = Network.DerivationPath.None,
hasFiatFeeRate = true,
canHandleTokens = true,
)
val networkStatus1 = NetworkStatus(

View file

@ -124,8 +124,9 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
userWalletId = config.userWalletId,
network = config.selectedNetwork ?: error("Network is not selected"),
derivationPath = config.selectedDerivationPath ?: SelectedDerivationPath(
id = config.selectedNetwork.id,
value = config.selectedNetwork.derivationPath,
name = resourceReference(R.string.custom_token_derivation_path_default),
networkName = resourceReference(R.string.custom_token_derivation_path_default),
),
formValues = config.formValues,
onSelectNetworkClick = ::showNetworkSelector,

View file

@ -49,7 +49,7 @@ internal class DefaultCustomTokenFormComponent @AssistedInject constructor(
tokenForm = getInitialTokenForm(),
derivationPath = ClickableFieldUM(
label = resourceReference(R.string.custom_token_derivation_path),
value = params.derivationPath.name,
value = params.derivationPath.networkName,
onClick = ::selectDerivationPath,
),
saveToken = {

View file

@ -29,13 +29,15 @@ internal class PreviewCustomTokenSelectorComponent(
when (params) {
is Params.DerivationPathSelector -> {
val d = SelectedDerivationPath(
value = "m/44'/0'/0'/0/$index",
name = stringReference(value = "Network $index"),
id = Network.ID(index.toString()),
value = Network.DerivationPath.Card("m/44'/0'/0'/0/$index"),
networkName = stringReference(value = "Network $index"),
)
DerivationPathUM(
value = "m/44'/0'/0'/0/$index",
blockchainName = d.name,
id = d.id.value,
value = d.value.value.orEmpty(),
networkName = d.networkName,
isSelected = d.value == params.selectedDerivationPath?.value,
onSelectedStateChange = { params.onDerivationPathSelected(d) },
)
@ -44,7 +46,8 @@ internal class PreviewCustomTokenSelectorComponent(
val n = SelectedNetwork(
id = Network.ID(index.toString()),
name = stringReference(value = "Network $index"),
derivationPath = "m/44'/0'/0'/0/$index",
derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/$index"),
canHandleTokens = false,
)
CurrencyNetworkUM(

View file

@ -28,11 +28,13 @@ internal data class AddCustomTokenConfig(
internal data class SelectedNetwork(
val id: Network.ID,
val name: TextReference,
val derivationPath: String,
val derivationPath: Network.DerivationPath,
val canHandleTokens: Boolean,
)
@Serializable
internal data class SelectedDerivationPath(
val value: String,
val name: TextReference,
val id: Network.ID,
val value: Network.DerivationPath,
val networkName: TextReference,
)

View file

@ -3,11 +3,9 @@ package com.tangem.features.managetokens.entity.item
import com.tangem.core.ui.extensions.TextReference
internal data class DerivationPathUM(
override val id: String,
val value: String,
val blockchainName: TextReference,
val networkName: TextReference,
override val isSelected: Boolean,
override val onSelectedStateChange: (Boolean) -> Unit,
) : SelectableItemUM {
override val id: String = value
}
) : SelectableItemUM

View file

@ -103,7 +103,8 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "1"),
name = stringReference("Ethereum"),
derivationPath = "m/44'/0'/0'/0/0",
derivationPath = Network.DerivationPath.None,
canHandleTokens = false,
),
),
),
@ -115,7 +116,8 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "0"),
name = stringReference("Ethereum"),
derivationPath = "m/44'/0'/0'/0/0",
derivationPath = Network.DerivationPath.None,
canHandleTokens = false,
),
),
),
@ -125,8 +127,9 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
step = AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR,
popBack = {},
selectedDerivationPath = SelectedDerivationPath(
value = "m/44'/0'/0'/0/0",
name = stringReference("Ethereum"),
id = Network.ID(value = "0"),
value = Network.DerivationPath.None,
networkName = stringReference("Ethereum"),
),
),
),

View file

@ -24,6 +24,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
import com.tangem.core.ui.components.rows.ChainRow
import com.tangem.core.ui.components.rows.model.ChainRowUM
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
@ -154,7 +155,7 @@ private fun NetworkItem(model: CurrencyNetworkUM, modifier: Modifier = Modifier)
icon = CurrencyIconState.CoinIcon(
url = null,
fallbackResId = model.iconResId,
isGrayscale = !model.isSelected,
isGrayscale = false,
showCustomBadge = false,
),
showCustom = false,
@ -205,7 +206,7 @@ private fun DerivationPathItem(model: DerivationPathUM, modifier: Modifier = Mod
contentAlignment = Alignment.CenterStart,
) {
Text(
text = "${model.value} ${if (model.isSelected) "- selected" else ""}",
text = "${model.networkName.resolveReference()}: ${model.value} ${if (model.isSelected) "<" else ""}",
color = TangemTheme.colors.text.primary1,
)
}
@ -235,7 +236,8 @@ private class CustomTokenNetworkSelectorComponentPreviewProvider :
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "0"),
name = stringReference(""),
derivationPath = "m/44'/0'/0'/0/0",
derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/0"),
canHandleTokens = false,
),
onNetworkSelected = {},
),
@ -244,8 +246,9 @@ private class CustomTokenNetworkSelectorComponentPreviewProvider :
params = CustomTokenSelectorComponent.Params.DerivationPathSelector(
userWalletId = UserWalletId(stringValue = "321"),
selectedDerivationPath = SelectedDerivationPath(
value = "m/44'/0'/0'/0/0",
name = stringReference(""),
id = Network.ID(value = "0"),
value = Network.DerivationPath.Card("m/44'/0'/0'/0/0"),
networkName = stringReference(""),
),
onDerivationPathSelected = {},
),