Updated on 2026-08-14
This commit is contained in:
parent
ab4ed3efc6
commit
80e0e5988e
4 changed files with 133 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
package com.tangem.features.managetokens.component
|
||||
|
||||
import com.tangem.core.decompose.factory.ComponentFactory
|
||||
import com.tangem.core.ui.decompose.ComposableDialogComponent
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
internal interface CustomTokenDerivationInputComponent : ComposableDialogComponent {
|
||||
|
||||
data class Params(
|
||||
val userWalletId: UserWalletId,
|
||||
val onConfirm: (String) -> Unit,
|
||||
val onDismiss: () -> Unit,
|
||||
)
|
||||
|
||||
interface Factory : ComponentFactory<Params, CustomTokenDerivationInputComponent>
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.tangem.features.managetokens.component.preview
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.features.managetokens.component.CustomTokenDerivationInputComponent
|
||||
import com.tangem.features.managetokens.entity.customtoken.CustomDerivationInputUM
|
||||
import com.tangem.features.managetokens.ui.dialog.CustomDerivationInputDialog
|
||||
|
||||
internal class PreviewCustomTokenDerivationInputComponent(
|
||||
private val value: String = "",
|
||||
private val error: String? = null,
|
||||
) : CustomTokenDerivationInputComponent {
|
||||
|
||||
override fun dismiss() {
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun Dialog() {
|
||||
val model = CustomDerivationInputUM(
|
||||
value = TextFieldValue(value),
|
||||
error = error?.let(::stringReference),
|
||||
updateValue = {},
|
||||
isConfirmEnabled = false,
|
||||
onConfirm = {},
|
||||
)
|
||||
|
||||
CustomDerivationInputDialog(
|
||||
model = model,
|
||||
onDismiss = ::dismiss,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.tangem.features.managetokens.entity.customtoken
|
||||
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
|
||||
internal data class CustomDerivationInputUM(
|
||||
val value: TextFieldValue,
|
||||
val error: TextReference? = null,
|
||||
val updateValue: (value: TextFieldValue) -> Unit,
|
||||
val isConfirmEnabled: Boolean,
|
||||
val onConfirm: () -> Unit,
|
||||
)
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.tangem.features.managetokens.ui.dialog
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import com.tangem.core.ui.components.AdditionalTextInputDialogUM
|
||||
import com.tangem.core.ui.components.DialogButtonUM
|
||||
import com.tangem.core.ui.components.TextInputDialog
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.features.managetokens.component.CustomTokenDerivationInputComponent
|
||||
import com.tangem.features.managetokens.component.preview.PreviewCustomTokenDerivationInputComponent
|
||||
import com.tangem.features.managetokens.entity.customtoken.CustomDerivationInputUM
|
||||
import com.tangem.features.managetokens.impl.R
|
||||
|
||||
@Composable
|
||||
internal fun CustomDerivationInputDialog(model: CustomDerivationInputUM, onDismiss: () -> Unit) {
|
||||
val value by rememberUpdatedState(newValue = model.value)
|
||||
|
||||
TextInputDialog(
|
||||
title = stringResource(id = R.string.custom_token_custom_derivation_title),
|
||||
fieldValue = value,
|
||||
confirmButton = DialogButtonUM(
|
||||
title = stringResource(id = R.string.common_ok),
|
||||
enabled = model.isConfirmEnabled,
|
||||
onClick = model.onConfirm,
|
||||
),
|
||||
dismissButton = DialogButtonUM(
|
||||
title = stringResource(id = R.string.common_cancel),
|
||||
onClick = onDismiss,
|
||||
),
|
||||
onDismissDialog = onDismiss,
|
||||
onValueChange = model.updateValue,
|
||||
textFieldParams = AdditionalTextInputDialogUM(
|
||||
label = model.error?.resolveReference() ?: stringResource(id = R.string.custom_token_derivation_path),
|
||||
isError = model.error != null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// region Preview
|
||||
@Composable
|
||||
@Preview(showBackground = true, widthDp = 360)
|
||||
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
private fun Preview_CustomDerivationInputDialog(
|
||||
@PreviewParameter(ComponentPreviewProvider::class) component: CustomTokenDerivationInputComponent,
|
||||
) {
|
||||
TangemThemePreview {
|
||||
component.Dialog()
|
||||
}
|
||||
}
|
||||
|
||||
private class ComponentPreviewProvider : PreviewParameterProvider<CustomTokenDerivationInputComponent> {
|
||||
override val values: Sequence<CustomTokenDerivationInputComponent>
|
||||
get() = sequenceOf(
|
||||
PreviewCustomTokenDerivationInputComponent(),
|
||||
PreviewCustomTokenDerivationInputComponent(
|
||||
value = "m/44'/60'/0'/0/0",
|
||||
),
|
||||
PreviewCustomTokenDerivationInputComponent(
|
||||
value = "m/44'/60'/0'/0/0",
|
||||
error = "Invalid derivation path",
|
||||
),
|
||||
)
|
||||
}
|
||||
// endregion Preview
|
||||
Loading…
Add table
Add a link
Reference in a new issue