Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-14 13:39:12 +03:00
parent 131ef0ae71
commit 0ec583301e
4 changed files with 14 additions and 10 deletions

View file

@ -4,6 +4,7 @@ import com.tangem.common.core.TangemSdkError
import com.tangem.crypto.bip39.Mnemonic
import com.tangem.crypto.bip39.MnemonicErrorResult
import com.tangem.feature.onboarding.data.MnemonicRepository
import com.tangem.feature.onboarding.presentation.wallet2.model.SeedPhraseField
import com.tangem.utils.extensions.isNotWhitespace
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -36,8 +37,8 @@ internal class DefaultSeedPhraseInteractor constructor(
}
}
override suspend fun isWordMatch(word: String): Boolean {
return repository.getWordsDictionary().contains(word)
override suspend fun isWordMatch(mnemonicComponents: List<String>?, field: SeedPhraseField, word: String): Boolean {
return mnemonicComponents?.get(field.index) == word
}
override suspend fun validateMnemonicString(text: String): Result<List<String>> {

View file

@ -1,6 +1,7 @@
package com.tangem.feature.onboarding.domain
import com.tangem.crypto.bip39.Mnemonic
import com.tangem.feature.onboarding.presentation.wallet2.model.SeedPhraseField
import kotlinx.collections.immutable.ImmutableList
/**
@ -9,7 +10,7 @@ import kotlinx.collections.immutable.ImmutableList
interface SeedPhraseInteractor {
suspend fun generateMnemonic(): Result<Mnemonic>
suspend fun getMnemonicComponents(): Result<List<String>>
suspend fun isWordMatch(word: String): Boolean
suspend fun isWordMatch(mnemonicComponents: List<String>?, field: SeedPhraseField, word: String): Boolean
suspend fun validateMnemonicString(text: String): Result<List<String>>
suspend fun getSuggestions(text: String, hasSelection: Boolean, cursorPosition: Int): ImmutableList<String>
suspend fun insertSuggestionWord(text: String, suggestion: String, cursorPosition: Int): InsertSuggestionResult

View file

@ -50,8 +50,8 @@ data class TextFieldUiAction(
enum class SeedPhraseField {
Second,
Seventh,
Eleventh,
enum class SeedPhraseField(val index: Int) {
Second(index = 1),
Seventh(index = 6),
Eleventh(index = 10),
}

View file

@ -161,12 +161,15 @@ class SeedPhraseViewModel @Inject constructor(
val fieldState = field.getState(uiState)
if (fieldState.textFieldValue.text.isEmpty()) {
updateUi { uiBuilder.checkSeedPhrase.updateTextFieldError(uiState, field, hasError = false) }
updateUi {
val mediate = uiBuilder.checkSeedPhrase.updateTextFieldError(uiState, field, hasError = false)
uiBuilder.checkSeedPhrase.updateCreateWalletButton(mediate, enabled = false)
}
return@launchSingle
}
createOrGetDebouncer(field.name).debounce(viewModelScope, context = dispatchers.io) {
val hasError = !interactor.isWordMatch(textFieldValue.text)
val hasError = !interactor.isWordMatch(generatedMnemonicComponents, field, textFieldValue.text)
if (fieldState.isError != hasError) {
updateUi { uiBuilder.checkSeedPhrase.updateTextFieldError(uiState, field, hasError) }
}
@ -278,7 +281,6 @@ class SeedPhraseViewModel @Inject constructor(
is CompletionResult.Success -> {
isFinished = true
}
is CompletionResult.Failure -> {
// errors shows on the TangemSdk bottom sheet dialog
}