diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt index e976a7786a..2ab37242b0 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt @@ -82,7 +82,7 @@ data class Network( data class Custom(override val value: String) : DerivationPath() /** - * Represents a lack of derivation path. + * Represents a lack of derivation path, which means the wallet does not support the HD wallet feature. */ @Serializable data object None : DerivationPath() { diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewCustomTokenFormComponent.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewCustomTokenFormComponent.kt index 5d995e9b1c..237bf10084 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewCustomTokenFormComponent.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewCustomTokenFormComponent.kt @@ -18,7 +18,7 @@ import kotlinx.collections.immutable.toPersistentMap internal class PreviewCustomTokenFormComponent( networkName: ClickableFieldUM = PreviewCustomTokenFormComponent.networkName, - derivationPath: ClickableFieldUM = PreviewCustomTokenFormComponent.derivationPath, + derivationPath: ClickableFieldUM? = PreviewCustomTokenFormComponent.derivationPath, canAddToken: Boolean = false, tokenForm: CustomTokenFormUM.TokenFormUM? = PreviewCustomTokenFormComponent.tokenForm, notifications: PersistentList = PreviewCustomTokenFormComponent.notifications, diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt index cf0f8554a8..6f8206441a 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt @@ -10,7 +10,7 @@ import kotlinx.collections.immutable.persistentMapOf internal data class CustomTokenFormUM( val networkName: ClickableFieldUM, - val derivationPath: ClickableFieldUM, + val derivationPath: ClickableFieldUM?, val tokenForm: TokenFormUM?, val notifications: PersistentList = persistentListOf(), val canAddToken: Boolean = false, diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt index b5f4d3bfc1..1e4f48feec 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt @@ -37,7 +37,8 @@ import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject -@Suppress("LongParameterList") +// TODO: Divide to sub-components: [REDACTED_JIRA] +@Suppress("LongParameterList", "LargeClass") @ComponentScoped internal class CustomTokenFormModel @Inject constructor( override val dispatchers: CoroutineDispatcherProvider, @@ -83,19 +84,26 @@ internal class CustomTokenFormModel @Inject constructor( } else { null }, - derivationPath = ClickableFieldUM( - label = resourceReference(R.string.custom_token_derivation_path), - value = if (params.derivationPath == null || params.derivationPath.isDefault) { - resourceReference(R.string.custom_token_derivation_path_default) - } else { - stringReference(params.derivationPath.name) - }, - onClick = ::selectDerivationPath, - ), + derivationPath = getDerivationPathFormIfSupported(), saveToken = ::addCurrency, ) } + private fun getDerivationPathFormIfSupported(): ClickableFieldUM? { + // If network doesn't support derivation path, return null + if (params.network.derivationPath is Network.DerivationPath.None) return null + + return ClickableFieldUM( + label = resourceReference(R.string.custom_token_derivation_path), + value = if (params.derivationPath == null || params.derivationPath.isDefault) { + resourceReference(R.string.custom_token_derivation_path_default) + } else { + stringReference(params.derivationPath.name) + }, + onClick = ::selectDerivationPath, + ) + } + @OptIn(FlowPreview::class) private fun observeTokenFormUpdates() { state diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/CustomTokenFormContent.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/CustomTokenFormContent.kt index fca42a82dc..1b01e1e8bf 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/CustomTokenFormContent.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/CustomTokenFormContent.kt @@ -117,12 +117,13 @@ private fun FormContent(model: CustomTokenFormUM, modifier: Modifier = Modifier) val tokenForm = model.tokenForm if (tokenForm != null) { - TokenForm(tokenForm) + TokenForm(tokenForm = tokenForm) } - ClickableField( - model = model.derivationPath, - ) + val derivationPath = model.derivationPath + if (derivationPath != null) { + ClickableField(model = derivationPath) + } model.notifications.fastForEach { notification -> Notification( @@ -278,6 +279,13 @@ private class PreviewCustomTokenFormComponentProvider : PreviewCustomTokenFormComponent( tokenForm = null, ), + PreviewCustomTokenFormComponent( + derivationPath = null, + ), + PreviewCustomTokenFormComponent( + tokenForm = null, + derivationPath = null, + ), ) } // endregion Preview \ No newline at end of file