Updated on 2026-08-14
This commit is contained in:
parent
bba40d0d7a
commit
49f14d1115
3 changed files with 11 additions and 35 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<String, Debouncer>()
|
||||
|
||||
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() {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue