From 95c984d9e3edbf629c2f255f4725754ed6534d6a Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 29 Jul 2025 13:59:01 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../hotwallet/accesscode/Constants.kt | 3 -- .../confirm/ConfirmAccessCodeComponent.kt | 52 ------------------- .../confirm/entity/ConfirmAccessCodeUM.kt | 12 ----- .../accesscode/di/AccessCodeModule.kt | 26 ---------- .../accesscode/set/SetAccessCodeModel.kt | 45 ---------------- .../accesscode/set/entity/SetAccessCodeUM.kt | 12 ----- .../accesscode/set/ui/SetAccessCodeContent.kt | 46 ---------------- .../HotAccessCodeRequestModel.kt | 5 +- .../entry/AddExistingWalletModel.kt | 10 ++-- .../routing/AddExistingWalletChildFactory.kt | 20 +++---- .../AccessCodeComponent.kt} | 29 ++++++++--- .../AccessCodeModel.kt} | 28 ++++++---- .../hotwallet/setaccesscode/Constants.kt | 3 ++ .../setaccesscode/di/AccessCodeModule.kt | 20 +++++++ .../setaccesscode/entity/AccessCodeUM.kt | 12 +++++ .../ui/AccessCodeEnter.kt | 2 +- .../ui/AccessCodeLayout.kt} | 25 +++++---- .../stepper/impl/ui/HotWalletStepper.kt | 6 +-- 18 files changed, 107 insertions(+), 249 deletions(-) delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/Constants.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeComponent.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/entity/ConfirmAccessCodeUM.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/di/AccessCodeModule.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeModel.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/entity/SetAccessCodeUM.kt delete mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/ui/SetAccessCodeContent.kt rename features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/{accesscode/set/SetAccessCodeComponent.kt => setaccesscode/AccessCodeComponent.kt} (62%) rename features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/{accesscode/confirm/ConfirmAccessCodeModel.kt => setaccesscode/AccessCodeModel.kt} (53%) create mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/Constants.kt create mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/di/AccessCodeModule.kt create mode 100644 features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/entity/AccessCodeUM.kt rename features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/{accesscode => setaccesscode}/ui/AccessCodeEnter.kt (98%) rename features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/{accesscode/confirm/ui/ConfirmAccessCodeContent.kt => setaccesscode/ui/AccessCodeLayout.kt} (59%) diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/Constants.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/Constants.kt deleted file mode 100644 index ca5ecaa367..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/Constants.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.tangem.features.hotwallet.accesscode - -const val ACCESS_CODE_LENGTH = 6 \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeComponent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeComponent.kt deleted file mode 100644 index 849eb2cb57..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeComponent.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.confirm - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.tangem.core.decompose.context.AppComponentContext -import com.tangem.core.decompose.model.getOrCreateModel -import com.tangem.core.ui.decompose.ComposableContentComponent -import com.tangem.core.ui.security.DisableScreenshotsDisposableEffect -import com.tangem.features.hotwallet.accesscode.confirm.ui.SetAccessCodeConfirmContent -import dagger.assisted.Assisted -import dagger.assisted.AssistedFactory -import dagger.assisted.AssistedInject - -internal class ConfirmAccessCodeComponent @AssistedInject constructor( - @Assisted private val context: AppComponentContext, - @Assisted private val params: Params, -) : ComposableContentComponent, AppComponentContext by context { - - private val model: ConfirmAccessCodeModel = getOrCreateModel(params) - - @Composable - override fun Content(modifier: Modifier) { - val state by model.uiState.collectAsStateWithLifecycle() - - DisableScreenshotsDisposableEffect() - - SetAccessCodeConfirmContent( - accessCode = state.accessCode, - onAccessCodeChange = state.onAccessCodeChange, - accessCodeLength = state.accessCodeLength, - onConfirm = state.onConfirm, - buttonEnabled = state.buttonEnabled, - modifier = modifier, - ) - } - - interface ModelCallbacks { - fun onAccessCodeConfirmed() - } - - data class Params( - val accessCodeToConfirm: String, - val callbacks: ModelCallbacks, - ) - - @AssistedFactory - interface Factory { - fun create(context: AppComponentContext, params: Params): ConfirmAccessCodeComponent - } -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/entity/ConfirmAccessCodeUM.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/entity/ConfirmAccessCodeUM.kt deleted file mode 100644 index f2df925578..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/entity/ConfirmAccessCodeUM.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.confirm.entity - -import com.tangem.features.hotwallet.accesscode.ACCESS_CODE_LENGTH - -internal data class ConfirmAccessCodeUM( - val accessCode: String, - val onAccessCodeChange: (String) -> Unit, - val buttonEnabled: Boolean, - val onConfirm: () -> Unit, -) { - val accessCodeLength: Int = ACCESS_CODE_LENGTH -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/di/AccessCodeModule.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/di/AccessCodeModule.kt deleted file mode 100644 index 8c79d221da..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/di/AccessCodeModule.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.di - -import com.tangem.core.decompose.model.Model -import com.tangem.features.hotwallet.accesscode.confirm.ConfirmAccessCodeModel -import com.tangem.features.hotwallet.accesscode.set.SetAccessCodeModel -import dagger.Binds -import dagger.Module -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import dagger.multibindings.ClassKey -import dagger.multibindings.IntoMap - -@Module -@InstallIn(SingletonComponent::class) -internal interface AccessCodeModule { - - @Binds - @IntoMap - @ClassKey(SetAccessCodeModel::class) - fun bindSetAccessCodeModel(model: SetAccessCodeModel): Model - - @Binds - @IntoMap - @ClassKey(ConfirmAccessCodeModel::class) - fun bindConfirmAccessCodeModel(model: ConfirmAccessCodeModel): Model -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeModel.kt deleted file mode 100644 index 4f57d50886..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeModel.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.set - -import androidx.compose.runtime.Stable -import com.tangem.core.decompose.di.ModelScoped -import com.tangem.core.decompose.model.Model -import com.tangem.core.decompose.model.ParamsContainer -import com.tangem.features.hotwallet.accesscode.set.entity.SetAccessCodeUM -import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.update -import javax.inject.Inject - -@Stable -@ModelScoped -internal class SetAccessCodeModel @Inject constructor( - paramsContainer: ParamsContainer, - override val dispatchers: CoroutineDispatcherProvider, -) : Model() { - - private val params = paramsContainer.require() - - internal val uiState: StateFlow - field = MutableStateFlow(getInitialState()) - - private fun getInitialState() = SetAccessCodeUM( - accessCode = "", - onAccessCodeChange = ::onAccessCodeChange, - buttonEnabled = false, - onContinue = ::onContinue, - ) - - private fun onAccessCodeChange(value: String) { - uiState.update { - it.copy( - accessCode = value, - buttonEnabled = value.length == uiState.value.accessCodeLength, - ) - } - } - - private fun onContinue() { - params.callbacks.onAccessCodeSet(uiState.value.accessCode) - } -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/entity/SetAccessCodeUM.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/entity/SetAccessCodeUM.kt deleted file mode 100644 index 68fa89c2fe..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/entity/SetAccessCodeUM.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.set.entity - -import com.tangem.features.hotwallet.accesscode.ACCESS_CODE_LENGTH - -internal data class SetAccessCodeUM( - val accessCode: String, - val onAccessCodeChange: (String) -> Unit, - val buttonEnabled: Boolean, - val onContinue: () -> Unit, -) { - val accessCodeLength: Int = ACCESS_CODE_LENGTH -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/ui/SetAccessCodeContent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/ui/SetAccessCodeContent.kt deleted file mode 100644 index 0fcf53c2df..0000000000 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/ui/SetAccessCodeContent.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.tangem.features.hotwallet.accesscode.set.ui - -import androidx.compose.foundation.layout.* -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.extensions.stringResourceSafe -import com.tangem.features.hotwallet.accesscode.ui.AccessCodeEnter -import com.tangem.core.res.R - -@Composable -internal fun SetAccessCodeContent( - accessCode: String, - onAccessCodeChange: (String) -> Unit, - accessCodeLength: Int, - onContinue: () -> Unit, - buttonEnabled: Boolean, - modifier: Modifier = Modifier, -) { - Column( - modifier = modifier - .fillMaxSize() - .navigationBarsPadding(), - ) { - AccessCodeEnter( - modifier = Modifier - .padding(top = 16.dp) - .weight(1f), - accessCode = accessCode, - onAccessCodeChange = onAccessCodeChange, - accessCodeLength = accessCodeLength, - reEnterAccessCodeState = false, - ) - - PrimaryButton( - modifier = Modifier - .fillMaxWidth() - .padding(start = 16.dp, end = 16.dp, bottom = 16.dp) - .imePadding(), - text = stringResourceSafe(R.string.common_continue), - onClick = onContinue, - enabled = buttonEnabled, - ) - } -} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscoderequest/HotAccessCodeRequestModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscoderequest/HotAccessCodeRequestModel.kt index c34ec66391..05e2ef611b 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscoderequest/HotAccessCodeRequestModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscoderequest/HotAccessCodeRequestModel.kt @@ -3,6 +3,7 @@ package com.tangem.features.hotwallet.accesscoderequest import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model import com.tangem.domain.wallets.hot.HotWalletPasswordRequester +import com.tangem.features.hotwallet.setaccesscode.ACCESS_CODE_LENGTH import com.tangem.features.hotwallet.accesscoderequest.entity.HotAccessCodeRequestUM import com.tangem.hot.sdk.model.HotAuth import com.tangem.utils.coroutines.CoroutineDispatcherProvider @@ -82,8 +83,4 @@ internal class HotAccessCodeRequestModel @Inject constructor( it.copy(isShown = false) } } - - private companion object { - const val ACCESS_CODE_LENGTH = 6 - } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt index ad499a7aa4..1d192ffae5 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt @@ -14,8 +14,7 @@ import com.tangem.features.hotwallet.addexistingwallet.im.port.AddExistingWallet import com.tangem.features.hotwallet.addexistingwallet.entry.routing.AddExistingWalletRoute import com.tangem.features.hotwallet.addexistingwallet.start.AddExistingWalletStartComponent import com.tangem.features.hotwallet.manualbackup.completed.ManualBackupCompletedComponent -import com.tangem.features.hotwallet.accesscode.confirm.ConfirmAccessCodeComponent -import com.tangem.features.hotwallet.accesscode.set.SetAccessCodeComponent +import com.tangem.features.hotwallet.setaccesscode.AccessCodeComponent import com.tangem.features.hotwallet.setupfinished.MobileWalletSetupFinishedComponent import com.tangem.features.pushnotifications.api.PushNotificationsComponent import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION @@ -34,8 +33,7 @@ internal class AddExistingWalletModel @Inject constructor( val addExistingWalletImportModelCallbacks = AddExistingWalletImportModelCallbacks() val manualBackupCompletedComponentModelCallbacks = ManualBackupCompletedComponentModelCallbacks() val pushNotificationsComponentModelCallbacks = PushNotificationsComponentModelCallbacks() - val setAccessCodeModelCallbacks = SetAccessCodeModelCallbacks() - val confirmAccessCodeModelCallbacks = ConfirmAccessCodeModelCallbacks() + val accessCodeModelCallbacks = AccessCodeModelCallbacks() val mobileWalletSetupFinishedComponentModelCallbacks = MobileWalletSetupFinishedComponentModelCallbacks() val stackNavigation = StackNavigation() @@ -91,13 +89,11 @@ internal class AddExistingWalletModel @Inject constructor( } } - inner class SetAccessCodeModelCallbacks : SetAccessCodeComponent.ModelCallbacks { + inner class AccessCodeModelCallbacks : AccessCodeComponent.ModelCallbacks { override fun onAccessCodeSet(accessCode: String) { stackNavigation.push(AddExistingWalletRoute.ConfirmAccessCode(accessCode)) } - } - inner class ConfirmAccessCodeModelCallbacks : ConfirmAccessCodeComponent.ModelCallbacks { override fun onAccessCodeConfirmed() { navigateToPushNotificationsOrNext() } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt index 10bdd316a8..90ffa797d0 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt @@ -2,8 +2,7 @@ package com.tangem.features.hotwallet.addexistingwallet.entry.routing import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.ui.decompose.ComposableContentComponent -import com.tangem.features.hotwallet.accesscode.set.SetAccessCodeComponent -import com.tangem.features.hotwallet.accesscode.confirm.ConfirmAccessCodeComponent +import com.tangem.features.hotwallet.setaccesscode.AccessCodeComponent import com.tangem.features.hotwallet.addexistingwallet.entry.AddExistingWalletModel import com.tangem.features.hotwallet.addexistingwallet.start.AddExistingWalletStartComponent import com.tangem.features.hotwallet.addexistingwallet.im.port.AddExistingWalletImportComponent @@ -14,8 +13,7 @@ import javax.inject.Inject internal class AddExistingWalletChildFactory @Inject constructor( private val pushNotificationsComponent: PushNotificationsComponent.Factory, - private val setAccessCodeSetComponentFactory: SetAccessCodeComponent.Factory, - private val confirmAccessCodeComponentFactory: ConfirmAccessCodeComponent.Factory, + private val accessCodeComponentFactory: AccessCodeComponent.Factory, ) { fun createChild( @@ -42,17 +40,19 @@ internal class AddExistingWalletChildFactory @Inject constructor( callbacks = model.manualBackupCompletedComponentModelCallbacks, ), ) - is AddExistingWalletRoute.SetAccessCode -> setAccessCodeSetComponentFactory.create( + is AddExistingWalletRoute.SetAccessCode -> accessCodeComponentFactory.create( context = childContext, - params = SetAccessCodeComponent.Params( - callbacks = model.setAccessCodeModelCallbacks, + params = AccessCodeComponent.Params( + isConfirmMode = false, + callbacks = model.accessCodeModelCallbacks, ), ) - is AddExistingWalletRoute.ConfirmAccessCode -> confirmAccessCodeComponentFactory.create( + is AddExistingWalletRoute.ConfirmAccessCode -> accessCodeComponentFactory.create( context = childContext, - params = ConfirmAccessCodeComponent.Params( + params = AccessCodeComponent.Params( + isConfirmMode = true, accessCodeToConfirm = route.accessCode, - callbacks = model.confirmAccessCodeModelCallbacks, + callbacks = model.accessCodeModelCallbacks, ), ) is AddExistingWalletRoute.PushNotifications -> pushNotificationsComponent.create( diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeComponent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeComponent.kt similarity index 62% rename from features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeComponent.kt rename to features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeComponent.kt index c8a03346c0..4200b68d42 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/set/SetAccessCodeComponent.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeComponent.kt @@ -1,4 +1,4 @@ -package com.tangem.features.hotwallet.accesscode.set +package com.tangem.features.hotwallet.setaccesscode import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -8,17 +8,19 @@ import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.core.ui.security.DisableScreenshotsDisposableEffect -import com.tangem.features.hotwallet.accesscode.set.ui.SetAccessCodeContent +import com.tangem.core.ui.extensions.stringResourceSafe +import com.tangem.features.hotwallet.setaccesscode.ui.AccessCodeLayout +import com.tangem.core.res.R import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -internal class SetAccessCodeComponent @AssistedInject constructor( +internal class AccessCodeComponent @AssistedInject constructor( @Assisted private val context: AppComponentContext, @Assisted private val params: Params, ) : ComposableContentComponent, AppComponentContext by context { - private val model: SetAccessCodeModel = getOrCreateModel(params) + private val model: AccessCodeModel = getOrCreateModel(params) @Composable override fun Content(modifier: Modifier) { @@ -26,26 +28,37 @@ internal class SetAccessCodeComponent @AssistedInject constructor( DisableScreenshotsDisposableEffect() - SetAccessCodeContent( + AccessCodeLayout( + modifier = modifier, accessCode = state.accessCode, onAccessCodeChange = state.onAccessCodeChange, accessCodeLength = state.accessCodeLength, - onContinue = state.onContinue, + reEnterAccessCodeState = params.isConfirmMode, + buttonText = stringResourceSafe( + if (params.isConfirmMode) { + R.string.common_confirm + } else { + R.string.common_continue + }, + ), + onButtonClick = state.onButtonClick, buttonEnabled = state.buttonEnabled, - modifier = modifier, ) } interface ModelCallbacks { fun onAccessCodeSet(accessCode: String) + fun onAccessCodeConfirmed() } data class Params( + val isConfirmMode: Boolean, + val accessCodeToConfirm: String? = null, val callbacks: ModelCallbacks, ) @AssistedFactory interface Factory { - fun create(context: AppComponentContext, params: Params): SetAccessCodeComponent + fun create(context: AppComponentContext, params: Params): AccessCodeComponent } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeModel.kt similarity index 53% rename from features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeModel.kt rename to features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeModel.kt index 25a77bdbdc..d978ba32f6 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ConfirmAccessCodeModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/AccessCodeModel.kt @@ -1,10 +1,10 @@ -package com.tangem.features.hotwallet.accesscode.confirm +package com.tangem.features.hotwallet.setaccesscode import androidx.compose.runtime.Stable import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer -import com.tangem.features.hotwallet.accesscode.confirm.entity.ConfirmAccessCodeUM +import com.tangem.features.hotwallet.setaccesscode.entity.AccessCodeUM import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -13,33 +13,41 @@ import javax.inject.Inject @Stable @ModelScoped -internal class ConfirmAccessCodeModel @Inject constructor( +internal class AccessCodeModel @Inject constructor( paramsContainer: ParamsContainer, override val dispatchers: CoroutineDispatcherProvider, ) : Model() { - private val params = paramsContainer.require() + private val params = paramsContainer.require() - internal val uiState: StateFlow + internal val uiState: StateFlow field = MutableStateFlow(getInitialState()) - private fun getInitialState() = ConfirmAccessCodeUM( + private fun getInitialState() = AccessCodeUM( accessCode = "", onAccessCodeChange = ::onAccessCodeChange, buttonEnabled = false, - onConfirm = ::onConfirm, + onButtonClick = ::onButtonClick, ) private fun onAccessCodeChange(value: String) { uiState.update { it.copy( accessCode = value, - buttonEnabled = value == params.accessCodeToConfirm, + buttonEnabled = if (params.isConfirmMode) { + value == params.accessCodeToConfirm + } else { + value.length == uiState.value.accessCodeLength + }, ) } } - private fun onConfirm() { - params.callbacks.onAccessCodeConfirmed() + private fun onButtonClick() { + if (params.isConfirmMode) { + params.callbacks.onAccessCodeConfirmed() + } else { + params.callbacks.onAccessCodeSet(uiState.value.accessCode) + } } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/Constants.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/Constants.kt new file mode 100644 index 0000000000..8494ba6e8b --- /dev/null +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/Constants.kt @@ -0,0 +1,3 @@ +package com.tangem.features.hotwallet.setaccesscode + +const val ACCESS_CODE_LENGTH = 6 \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/di/AccessCodeModule.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/di/AccessCodeModule.kt new file mode 100644 index 0000000000..c6fb7f93cc --- /dev/null +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/di/AccessCodeModule.kt @@ -0,0 +1,20 @@ +package com.tangem.features.hotwallet.setaccesscode.di + +import com.tangem.core.decompose.model.Model +import com.tangem.features.hotwallet.setaccesscode.AccessCodeModel +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +@Module +@InstallIn(SingletonComponent::class) +internal interface AccessCodeModule { + + @Binds + @IntoMap + @ClassKey(AccessCodeModel::class) + fun bindAccessCodeModel(model: AccessCodeModel): Model +} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/entity/AccessCodeUM.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/entity/AccessCodeUM.kt new file mode 100644 index 0000000000..836a816175 --- /dev/null +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/entity/AccessCodeUM.kt @@ -0,0 +1,12 @@ +package com.tangem.features.hotwallet.setaccesscode.entity + +import com.tangem.features.hotwallet.setaccesscode.ACCESS_CODE_LENGTH + +internal data class AccessCodeUM( + val accessCode: String, + val onAccessCodeChange: (String) -> Unit, + val buttonEnabled: Boolean, + val onButtonClick: () -> Unit, +) { + val accessCodeLength: Int = ACCESS_CODE_LENGTH +} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCodeEnter.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeEnter.kt similarity index 98% rename from features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCodeEnter.kt rename to features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeEnter.kt index ba80fd0bb6..62e4388d9a 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCodeEnter.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeEnter.kt @@ -1,4 +1,4 @@ -package com.tangem.features.hotwallet.accesscode.ui +package com.tangem.features.hotwallet.setaccesscode.ui import android.content.res.Configuration import androidx.compose.foundation.background diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ui/ConfirmAccessCodeContent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeLayout.kt similarity index 59% rename from features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ui/ConfirmAccessCodeContent.kt rename to features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeLayout.kt index d85e2ea0d1..aee581c976 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/confirm/ui/ConfirmAccessCodeContent.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/setaccesscode/ui/AccessCodeLayout.kt @@ -1,20 +1,25 @@ -package com.tangem.features.hotwallet.accesscode.confirm.ui +package com.tangem.features.hotwallet.setaccesscode.ui -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.extensions.stringResourceSafe -import com.tangem.features.hotwallet.accesscode.ui.AccessCodeEnter -import com.tangem.core.res.R +@Suppress("LongParameterList") @Composable -internal fun SetAccessCodeConfirmContent( +internal fun AccessCodeLayout( accessCode: String, onAccessCodeChange: (String) -> Unit, accessCodeLength: Int, - onConfirm: () -> Unit, + reEnterAccessCodeState: Boolean, + buttonText: String, + onButtonClick: () -> Unit, buttonEnabled: Boolean, modifier: Modifier = Modifier, ) { @@ -30,7 +35,7 @@ internal fun SetAccessCodeConfirmContent( accessCode = accessCode, onAccessCodeChange = onAccessCodeChange, accessCodeLength = accessCodeLength, - reEnterAccessCodeState = true, + reEnterAccessCodeState = reEnterAccessCodeState, ) PrimaryButton( @@ -38,8 +43,8 @@ internal fun SetAccessCodeConfirmContent( .fillMaxWidth() .padding(start = 16.dp, end = 16.dp, bottom = 16.dp) .imePadding(), - text = stringResourceSafe(R.string.common_confirm), - onClick = onConfirm, + text = buttonText, + onClick = onButtonClick, enabled = buttonEnabled, ) } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/stepper/impl/ui/HotWalletStepper.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/stepper/impl/ui/HotWalletStepper.kt index f9af5a29b8..ea029d37be 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/stepper/impl/ui/HotWalletStepper.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/stepper/impl/ui/HotWalletStepper.kt @@ -43,18 +43,18 @@ internal fun HotWalletStepper( ) { TangemTopAppBar( startButton = if (state.showBackButton) { - TopAppBarButtonUM.Back { onBackClick() } + TopAppBarButtonUM.Back(onBackClick) } else { null }, endButton = when { state.showSkipButton -> TopAppBarButtonUM.Text( text = resourceReference(R.string.common_skip), - onClicked = { onSkipClick() }, + onClicked = onSkipClick, ) state.showFeedbackButton -> TopAppBarButtonUM.Icon( iconRes = R.drawable.ic_chat_24, - onClicked = { onFeedbackClick() }, + onClicked = onFeedbackClick, ) else -> null },