Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-13 15:52:18 +04:00
commit b2c38d791e
5 changed files with 33 additions and 17 deletions

View file

@ -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() {

View file

@ -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<CustomTokenFormUM.NotificationUM> = PreviewCustomTokenFormComponent.notifications,

View file

@ -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<NotificationUM> = persistentListOf(),
val canAddToken: Boolean = false,

View file

@ -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

View file

@ -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