From 49f14d1115020ae080fae2860b76cf53725c6baf Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 11 Apr 2023 19:37:31 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/utils/coroutines/CoroutineExt.kt | 4 +- .../presentation/wallet2/model/UiActions.kt | 2 +- .../wallet2/viewmodel/SeedPhraseViewModel.kt | 40 +++++-------------- 3 files changed, 11 insertions(+), 35 deletions(-) diff --git a/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt b/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt index 42b911ad4d..872aeb1c64 100644 --- a/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt +++ b/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt @@ -23,9 +23,7 @@ suspend inline fun ifActive(crossinline block: suspend () -> Unit) = coroutineSc } } -class Debouncer( - val name: String = "Default", -) { +class Debouncer { private var debounceJob: Job? = null diff --git a/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/model/UiActions.kt b/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/model/UiActions.kt index db5573c0fa..168cbaca76 100644 --- a/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/model/UiActions.kt +++ b/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/model/UiActions.kt @@ -43,8 +43,8 @@ data class ImportSeedPhraseUiAction( ) data class TextFieldUiAction( - val onFocusChanged: (Boolean) -> Unit, val onTextFieldChanged: (TextFieldValue) -> Unit, + val onFocusChanged: (Boolean) -> Unit = {}, ) enum class SeedPhraseField { diff --git a/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/viewmodel/SeedPhraseViewModel.kt b/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/viewmodel/SeedPhraseViewModel.kt index eabb91923b..14c5167dd3 100644 --- a/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/viewmodel/SeedPhraseViewModel.kt +++ b/features/onboarding/src/main/java/com/tangem/feature/onboarding/presentation/wallet2/viewmodel/SeedPhraseViewModel.kt @@ -37,9 +37,6 @@ class SeedPhraseViewModel @Inject constructor( private val dispatchers: CoroutineDispatcherProvider, ) : ViewModel() { - var aboutSeedPhraseUriProvider: AboutSeedPhraseOpener? = null - var chatLauncher: ChatSupportOpener? = null - private var uiBuilder = StateBuilder(createUiActions()) var uiState: OnboardingSeedPhraseState by mutableStateOf(uiBuilder.init()) @@ -50,6 +47,12 @@ class SeedPhraseViewModel @Inject constructor( private val textFieldsDebouncers = mutableMapOf() + override fun onCleared() { + textFieldsDebouncers.forEach { entry -> entry.value.release() } + textFieldsDebouncers.clear() + super.onCleared() + } + private fun createUiActions(): UiActions = UiActions( introActions = IntroUiAction( buttonCreateWalletClick = ::buttonCreateWalletClick, @@ -67,15 +70,12 @@ class SeedPhraseViewModel @Inject constructor( buttonCreateWalletClick = ::buttonCreateWalletWithSeedPhraseClick, secondTextFieldAction = TextFieldUiAction( onTextFieldChanged = { value -> onTextFieldChanged(SeedPhraseField.Second, value) }, - onFocusChanged = { isFocused -> onFocusChanged(SeedPhraseField.Second, isFocused) }, ), seventhTextFieldAction = TextFieldUiAction( onTextFieldChanged = { value -> onTextFieldChanged(SeedPhraseField.Seventh, value) }, - onFocusChanged = { isFocused -> onFocusChanged(SeedPhraseField.Seventh, isFocused) }, ), eleventhTextFieldAction = TextFieldUiAction( onTextFieldChanged = { value -> onTextFieldChanged(SeedPhraseField.Eleventh, value) }, - onFocusChanged = { isFocused -> onFocusChanged(SeedPhraseField.Eleventh, isFocused) }, ), ), importSeedPhraseActions = ImportSeedPhraseUiAction( @@ -89,21 +89,7 @@ class SeedPhraseViewModel @Inject constructor( menuChatClick = ::menuChatClick, ) - override fun onCleared() { - textFieldsDebouncers.forEach { entry -> entry.value.release() } - textFieldsDebouncers.clear() - super.onCleared() - } - // region CheckSeedPhrase - private fun onFocusChanged(field: SeedPhraseField, isFocused: Boolean) { - when (field) { - SeedPhraseField.Second -> {} - SeedPhraseField.Seventh -> {} - SeedPhraseField.Eleventh -> {} - } - } - private fun onTextFieldChanged(field: SeedPhraseField, textFieldValue: TextFieldValue) { viewModelScope.launchSingle { updateUi { uiBuilder.checkSeedPhrase.updateTextField(uiState, field, textFieldValue) } @@ -147,7 +133,7 @@ class SeedPhraseViewModel @Inject constructor( } private fun buttonReadMoreAboutSeedPhraseClick() { - aboutSeedPhraseUriProvider?.open() + // TODO: open the about info through a router } private fun buttonGenerateSeedPhraseClick() { @@ -179,7 +165,7 @@ class SeedPhraseViewModel @Inject constructor( } private fun menuChatClick() { - chatLauncher?.open() + // TODO: open the support chat through a router } // endregion ButtonClickHandlers @@ -196,7 +182,7 @@ class SeedPhraseViewModel @Inject constructor( } private fun createOrGetDebouncer(name: String): Debouncer { - return textFieldsDebouncers[name] ?: Debouncer(name).apply { textFieldsDebouncers[name] = this } + return textFieldsDebouncers[name] ?: Debouncer().apply { textFieldsDebouncers[name] = this } } private fun SeedPhraseField.getState(uiState: OnboardingSeedPhraseState): TextFieldState = when (this) { @@ -217,12 +203,4 @@ class SeedPhraseViewModel @Inject constructor( return withContext(dispatchers.single, block) } // endregion Utils -} - -interface AboutSeedPhraseOpener { - fun open() {} -} - -interface ChatSupportOpener { - fun open() {} } \ No newline at end of file