diff --git a/features/onboarding/src/main/java/com/tangem/feature/onboarding/domain/DefaultSeedPhraseInteractor.kt b/features/onboarding/src/main/java/com/tangem/feature/onboarding/domain/DefaultSeedPhraseInteractor.kt index 1056aa7996..2860aa5b8a 100644 --- a/features/onboarding/src/main/java/com/tangem/feature/onboarding/domain/DefaultSeedPhraseInteractor.kt +++ b/features/onboarding/src/main/java/com/tangem/feature/onboarding/domain/DefaultSeedPhraseInteractor.kt @@ -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.utils.extensions.isNotWhitespace /** [REDACTED_AUTHOR] @@ -13,6 +14,7 @@ internal class DefaultSeedPhraseInteractor constructor( ) : SeedPhraseInteractor { private var currentMnemonic: Mnemonic? = null + private val partWordFinder: PartWordFinder = PartWordFinder() override suspend fun generateMnemonic(): Result { return runCatching { @@ -61,8 +63,15 @@ internal class DefaultSeedPhraseInteractor constructor( hasSelection: Boolean, cursorPosition: Int, ): List { - // TODO: todo - return emptyList() + if (text.isEmpty() || cursorPosition == 0 || hasSelection) return emptyList() + val word = partWordFinder.getLeadPartOfWord(text, cursorPosition) + ?: return emptyList() + + val suggestions = repository.getWordsDictionary() + .filter { it.startsWith(word, ignoreCase = false) && it != word } + .toList() + + return suggestions } override suspend fun insertSuggestionWord( @@ -70,8 +79,23 @@ internal class DefaultSeedPhraseInteractor constructor( suggestion: String, cursorPosition: Int, ): InsertSuggestionResult { - // TODO: todo - return InsertSuggestionResult("", 0) + val textPartLead = text.substring(0, cursorPosition) + val textPartLast = text.substring(cursorPosition, text.length) + val wordPartLast = partWordFinder.getLastPartOfWord(text, suggestion, cursorPosition) + + val textBuilder = StringBuilder() + .append(textPartLead) + .append(wordPartLast) + + if (textPartLast.isEmpty() || textPartLast[0].isNotWhitespace()) { + textBuilder.append(SeedPhraseInteractor.MNEMONIC_DELIMITER) + } + textBuilder.append(textPartLast) + + val textWithSuggestion = textBuilder.toString() + val newCursorPosition = cursorPosition + wordPartLast.length + SeedPhraseInteractor.MNEMONIC_DELIMITER.length + + return InsertSuggestionResult(textWithSuggestion, newCursorPosition) } }