Updated on 2026-08-14
This commit is contained in:
parent
54dd875aec
commit
96548d4ca4
6 changed files with 80 additions and 62 deletions
|
|
@ -22,6 +22,7 @@ import com.tangem.features.managetokens.entity.customtoken.CustomTokenFormValues
|
|||
import com.tangem.features.managetokens.entity.customtoken.SelectedDerivationPath
|
||||
import com.tangem.features.managetokens.entity.customtoken.SelectedNetwork
|
||||
import com.tangem.features.managetokens.ui.AddCustomTokenBottomSheet
|
||||
import com.tangem.features.managetokens.utils.ui.toContentModel
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
|
|
@ -34,15 +35,16 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
private val analyticsEventHandler: AnalyticsEventHandler,
|
||||
) : AddCustomTokenComponent, AppComponentContext by context {
|
||||
|
||||
private val initialConfiguration = AddCustomTokenConfig(
|
||||
userWalletId = params.userWalletId,
|
||||
step = AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
)
|
||||
|
||||
private val navigation = StackNavigation<AddCustomTokenConfig>()
|
||||
private val contentStack = childStack(
|
||||
key = "add_custom_token_content_stack",
|
||||
source = navigation,
|
||||
initialConfiguration = AddCustomTokenConfig(
|
||||
userWalletId = params.userWalletId,
|
||||
step = AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
popBack = ::dismiss,
|
||||
),
|
||||
initialConfiguration = initialConfiguration,
|
||||
handleBackButton = true,
|
||||
serializer = AddCustomTokenConfig.serializer(),
|
||||
childFactory = ::contentChild,
|
||||
|
|
@ -62,14 +64,14 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
TangemBottomSheetConfig(
|
||||
isShow = true,
|
||||
onDismissRequest = ::dismiss,
|
||||
content = contentStack.active.configuration,
|
||||
content = initialConfiguration.step.toContentModel(::popBack),
|
||||
)
|
||||
}
|
||||
val childStack by contentStack.subscribeAsState()
|
||||
|
||||
AddCustomTokenBottomSheet(
|
||||
config = config.copy(
|
||||
content = childStack.active.configuration,
|
||||
content = childStack.active.configuration.step.toContentModel(::popBack),
|
||||
),
|
||||
content = { modifier ->
|
||||
Children(
|
||||
|
|
@ -82,6 +84,17 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun popBack() {
|
||||
when (contentStack.value.active.configuration.step) {
|
||||
AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
AddCustomTokenConfig.Step.FORM,
|
||||
-> dismiss()
|
||||
AddCustomTokenConfig.Step.NETWORK_SELECTOR,
|
||||
AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR,
|
||||
-> navigation.pop()
|
||||
}
|
||||
}
|
||||
|
||||
private fun contentChild(
|
||||
config: AddCustomTokenConfig,
|
||||
componentContext: ComponentContext,
|
||||
|
|
@ -164,7 +177,6 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
val config = currentConfig.copy(
|
||||
step = AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR,
|
||||
formValues = formValues,
|
||||
popBack = navigation::pop,
|
||||
)
|
||||
navigation.push(config)
|
||||
}
|
||||
|
|
@ -175,7 +187,6 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
val config = currentConfig.copy(
|
||||
step = AddCustomTokenConfig.Step.NETWORK_SELECTOR,
|
||||
formValues = formValues,
|
||||
popBack = navigation::pop,
|
||||
)
|
||||
navigation.push(config)
|
||||
}
|
||||
|
|
@ -187,7 +198,6 @@ internal class DefaultAddCustomTokenComponent @AssistedInject constructor(
|
|||
step = AddCustomTokenConfig.Step.FORM,
|
||||
selectedNetwork = network ?: currentConfig.selectedNetwork,
|
||||
selectedDerivationPath = derivationPath ?: currentConfig.selectedDerivationPath,
|
||||
popBack = ::dismiss,
|
||||
)
|
||||
navigation.replaceAll(config)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ import com.tangem.features.managetokens.component.AddCustomTokenComponent
|
|||
import com.tangem.features.managetokens.component.CustomTokenSelectorComponent
|
||||
import com.tangem.features.managetokens.entity.customtoken.AddCustomTokenConfig
|
||||
import com.tangem.features.managetokens.ui.AddCustomTokenBottomSheet
|
||||
import com.tangem.features.managetokens.utils.ui.toContentModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
internal class PreviewAddCustomTokenComponent(
|
||||
initialState: AddCustomTokenConfig = AddCustomTokenConfig(
|
||||
userWalletId = UserWalletId(stringValue = "321"),
|
||||
step = AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
popBack = {},
|
||||
),
|
||||
) : AddCustomTokenComponent {
|
||||
|
||||
private val previewState: MutableStateFlow<AddCustomTokenConfig> = MutableStateFlow(initialState)
|
||||
private val previewConfig: MutableStateFlow<AddCustomTokenConfig> = MutableStateFlow(initialState)
|
||||
|
||||
override fun dismiss() {
|
||||
/* no-op */
|
||||
|
|
@ -27,21 +27,21 @@ internal class PreviewAddCustomTokenComponent(
|
|||
|
||||
@Composable
|
||||
override fun BottomSheet() {
|
||||
val state by previewState.collectAsStateWithLifecycle()
|
||||
val config = TangemBottomSheetConfig(
|
||||
val config by previewConfig.collectAsStateWithLifecycle()
|
||||
val bottomSheetConfig = TangemBottomSheetConfig(
|
||||
isShow = true,
|
||||
onDismissRequest = ::dismiss,
|
||||
content = state,
|
||||
content = config.step.toContentModel(::dismiss),
|
||||
)
|
||||
|
||||
AddCustomTokenBottomSheet(
|
||||
config = config,
|
||||
config = bottomSheetConfig,
|
||||
content = { modifier ->
|
||||
when (state.step) {
|
||||
when (config.step) {
|
||||
AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR -> {
|
||||
PreviewCustomTokenSelectorComponent(
|
||||
params = CustomTokenSelectorComponent.Params.NetworkSelector(
|
||||
userWalletId = state.userWalletId,
|
||||
userWalletId = config.userWalletId,
|
||||
selectedNetwork = null,
|
||||
onNetworkSelected = {},
|
||||
),
|
||||
|
|
@ -50,8 +50,8 @@ internal class PreviewAddCustomTokenComponent(
|
|||
AddCustomTokenConfig.Step.NETWORK_SELECTOR -> {
|
||||
PreviewCustomTokenSelectorComponent(
|
||||
params = CustomTokenSelectorComponent.Params.NetworkSelector(
|
||||
userWalletId = state.userWalletId,
|
||||
selectedNetwork = state.selectedNetwork,
|
||||
userWalletId = config.userWalletId,
|
||||
selectedNetwork = config.selectedNetwork,
|
||||
onNetworkSelected = {},
|
||||
),
|
||||
).Content(modifier)
|
||||
|
|
@ -59,9 +59,9 @@ internal class PreviewAddCustomTokenComponent(
|
|||
AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR -> {
|
||||
PreviewCustomTokenSelectorComponent(
|
||||
params = CustomTokenSelectorComponent.Params.DerivationPathSelector(
|
||||
userWalletId = state.userWalletId,
|
||||
selectedNetwork = state.selectedNetwork!!,
|
||||
selectedDerivationPath = state.selectedDerivationPath!!,
|
||||
userWalletId = config.userWalletId,
|
||||
selectedNetwork = config.selectedNetwork!!,
|
||||
selectedDerivationPath = config.selectedDerivationPath!!,
|
||||
onDerivationPathSelected = {},
|
||||
),
|
||||
).Content(modifier)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.features.managetokens.entity.customtoken
|
||||
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.serialization.Serializable
|
||||
|
|
@ -8,12 +7,11 @@ import kotlinx.serialization.Serializable
|
|||
@Serializable
|
||||
internal data class AddCustomTokenConfig(
|
||||
val step: Step,
|
||||
val popBack: () -> Unit,
|
||||
val userWalletId: UserWalletId,
|
||||
val selectedNetwork: SelectedNetwork? = null,
|
||||
val selectedDerivationPath: SelectedDerivationPath? = null,
|
||||
val formValues: CustomTokenFormValues = CustomTokenFormValues(),
|
||||
) : TangemBottomSheetConfigContent {
|
||||
) {
|
||||
|
||||
enum class Step {
|
||||
INITIAL_NETWORK_SELECTOR,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.features.managetokens.entity.customtoken
|
||||
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
|
||||
internal data class AddCustomTokenUM(
|
||||
val popBack: () -> Unit,
|
||||
val title: TextReference,
|
||||
val showBackButton: Boolean,
|
||||
) : TangemBottomSheetConfigContent
|
||||
|
|
@ -14,8 +14,6 @@ import com.tangem.core.ui.components.appbar.TangemTopAppBarHeight
|
|||
import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetTitle
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
|
|
@ -23,13 +21,13 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
import com.tangem.features.managetokens.component.AddCustomTokenComponent
|
||||
import com.tangem.features.managetokens.component.preview.PreviewAddCustomTokenComponent
|
||||
import com.tangem.features.managetokens.entity.customtoken.AddCustomTokenConfig
|
||||
import com.tangem.features.managetokens.entity.customtoken.AddCustomTokenUM
|
||||
import com.tangem.features.managetokens.entity.customtoken.SelectedDerivationPath
|
||||
import com.tangem.features.managetokens.entity.customtoken.SelectedNetwork
|
||||
import com.tangem.features.managetokens.impl.R
|
||||
|
||||
@Composable
|
||||
internal fun AddCustomTokenBottomSheet(config: TangemBottomSheetConfig, content: @Composable (Modifier) -> Unit) {
|
||||
TangemBottomSheet<AddCustomTokenConfig>(
|
||||
TangemBottomSheet<AddCustomTokenUM>(
|
||||
config = config,
|
||||
addBottomInsets = false,
|
||||
title = { model ->
|
||||
|
|
@ -47,35 +45,14 @@ internal fun AddCustomTokenBottomSheet(config: TangemBottomSheetConfig, content:
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun Title(model: AddCustomTokenConfig, modifier: Modifier = Modifier) {
|
||||
when (model.step) {
|
||||
AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
AddCustomTokenConfig.Step.FORM,
|
||||
-> {
|
||||
TangemBottomSheetTitle(
|
||||
modifier = modifier,
|
||||
title = resourceReference(R.string.add_custom_token_title),
|
||||
)
|
||||
}
|
||||
AddCustomTokenConfig.Step.NETWORK_SELECTOR -> {
|
||||
TangemTopAppBar(
|
||||
modifier = modifier,
|
||||
title = resourceReference(R.string.custom_token_network_selector_title),
|
||||
titleAlignment = Alignment.CenterHorizontally,
|
||||
startButton = TopAppBarButtonUM.Back(model.popBack),
|
||||
height = TangemTopAppBarHeight.BOTTOM_SHEET,
|
||||
)
|
||||
}
|
||||
AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR -> {
|
||||
TangemTopAppBar(
|
||||
modifier = modifier,
|
||||
title = resourceReference(R.string.custom_token_derivation_path),
|
||||
titleAlignment = Alignment.CenterHorizontally,
|
||||
startButton = TopAppBarButtonUM.Back(model.popBack),
|
||||
height = TangemTopAppBarHeight.BOTTOM_SHEET,
|
||||
)
|
||||
}
|
||||
}
|
||||
private fun Title(model: AddCustomTokenUM, modifier: Modifier = Modifier) {
|
||||
TangemTopAppBar(
|
||||
modifier = modifier,
|
||||
title = model.title,
|
||||
titleAlignment = Alignment.CenterHorizontally,
|
||||
startButton = TopAppBarButtonUM.Back(model.popBack).takeIf { model.showBackButton },
|
||||
height = TangemTopAppBarHeight.BOTTOM_SHEET,
|
||||
)
|
||||
}
|
||||
|
||||
// region Preview
|
||||
|
|
@ -98,7 +75,6 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
|
|||
initialState = AddCustomTokenConfig(
|
||||
userWalletId = UserWalletId(stringValue = "321"),
|
||||
step = AddCustomTokenConfig.Step.FORM,
|
||||
popBack = {},
|
||||
selectedNetwork = SelectedNetwork(
|
||||
id = Network.ID(value = "1"),
|
||||
name = "Ethereum",
|
||||
|
|
@ -111,7 +87,6 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
|
|||
initialState = AddCustomTokenConfig(
|
||||
userWalletId = UserWalletId(stringValue = "321"),
|
||||
step = AddCustomTokenConfig.Step.NETWORK_SELECTOR,
|
||||
popBack = {},
|
||||
selectedNetwork = SelectedNetwork(
|
||||
id = Network.ID(value = "0"),
|
||||
name = "Ethereum",
|
||||
|
|
@ -124,7 +99,6 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
|
|||
initialState = AddCustomTokenConfig(
|
||||
userWalletId = UserWalletId(stringValue = "321"),
|
||||
step = AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR,
|
||||
popBack = {},
|
||||
selectedDerivationPath = SelectedDerivationPath(
|
||||
id = Network.ID(value = "0"),
|
||||
value = Network.DerivationPath.None,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.tangem.features.managetokens.utils.ui
|
||||
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.features.managetokens.entity.customtoken.AddCustomTokenConfig
|
||||
import com.tangem.features.managetokens.entity.customtoken.AddCustomTokenUM
|
||||
import com.tangem.features.managetokens.impl.R
|
||||
|
||||
internal fun AddCustomTokenConfig.Step.toContentModel(popBack: () -> Unit): AddCustomTokenUM = when (this) {
|
||||
AddCustomTokenConfig.Step.INITIAL_NETWORK_SELECTOR,
|
||||
AddCustomTokenConfig.Step.FORM,
|
||||
-> AddCustomTokenUM(
|
||||
popBack = popBack,
|
||||
title = resourceReference(R.string.add_custom_token_title),
|
||||
showBackButton = false,
|
||||
)
|
||||
AddCustomTokenConfig.Step.NETWORK_SELECTOR -> AddCustomTokenUM(
|
||||
popBack = popBack,
|
||||
title = resourceReference(R.string.custom_token_network_selector_title),
|
||||
showBackButton = true,
|
||||
)
|
||||
AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR -> AddCustomTokenUM(
|
||||
popBack = popBack,
|
||||
title = resourceReference(R.string.custom_token_derivation_path),
|
||||
showBackButton = true,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue