Updated on 2026-08-14
This commit is contained in:
parent
364f4e51b7
commit
360f2ec453
5 changed files with 33 additions and 17 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue