Skip to content

Update word check #5232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import one.mixin.android.tip.Tip
import one.mixin.android.ui.home.web3.swap.KeyboardAwareBox
import one.mixin.android.ui.wallet.WalletViewModel
import one.mixin.android.util.getMixinErrorStringByCode
import org.bitcoinj.crypto.MnemonicCode

@Composable
fun MnemonicPhraseInput(
Expand Down Expand Up @@ -283,6 +284,12 @@ fun MnemonicPhraseInput(
)
}
} else {
val text = inputs[index]
val textColor = if (index != focusIndex && text.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(text).not()) {
Copy link
Preview

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word list lookup MnemonicCode.INSTANCE.wordList.contains(text) is being called multiple times for the same text during composition. Consider caching the validation result or extracting it to avoid redundant lookups.

Suggested change
val textColor = if (index != focusIndex && text.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(text).not()) {
val isWordInList = remember(text) { MnemonicCode.INSTANCE.wordList.contains(text) }
val textColor = if (index != focusIndex && text.isNotEmpty() && !isWordInList) {

Copilot uses AI. Check for mistakes.

MixinAppTheme.colors.tipError
} else {
MixinAppTheme.colors.textMinor
}
BasicTextField(
modifier = Modifier.onFocusChanged { focusState ->
focusIndex = if (focusState.isFocused) {
Expand All @@ -300,7 +307,7 @@ fun MnemonicPhraseInput(
singleLine = true,
cursorBrush = SolidColor(MixinAppTheme.colors.accent),
textStyle = LocalTextStyle.current.copy(
color = MixinAppTheme.colors.textMinor,
color = textColor,
fontSize = 13.sp,
fontWeight = W500
),
Expand Down Expand Up @@ -398,7 +405,7 @@ fun MnemonicPhraseInput(
Row {
Text(
"${index + 1}",
color = MixinAppTheme.colors.textPrimary,
color = textColor,
fontSize = 13.sp,
)
Spacer(Modifier.width(8.dp))
Expand Down Expand Up @@ -557,7 +564,6 @@ fun MnemonicPhraseInput(
)
Spacer(modifier = Modifier.height(8.dp))
}

if (errorInfo.isNotBlank()) {
Spacer(modifier = Modifier.height(8.dp))
Text(
Expand All @@ -566,14 +572,22 @@ fun MnemonicPhraseInput(
color = MixinAppTheme.colors.tipError,
)
Spacer(modifier = Modifier.height(8.dp))
} else if (inputs.any { it.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(it).not() }) {
Copy link
Preview

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation logic iterates through all inputs and performs word list lookups on each composition. This could be expensive with many input fields. Consider memoizing this validation or moving it to a computed property.

Suggested change
} else if (inputs.any { it.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(it).not() }) {
} else if (hasInvalidInput) {

Copilot uses AI. Check for mistakes.

Spacer(modifier = Modifier.height(8.dp))
Text(
modifier = Modifier.align(Alignment.Start),
text = context.getString(R.string.invalid_mnemonic_phrase), fontSize = 14.sp,
color = MixinAppTheme.colors.tipError,
)
Spacer(modifier = Modifier.height(8.dp))
}
Spacer(modifier = Modifier.height(if (legacy) 20.dp else 8.dp))
Spacer(modifier = Modifier.weight(1f))
Button(
modifier = Modifier
.fillMaxWidth()
.height(48.dp),
enabled = state == MnemonicState.Display || inputs.all { it.isNotEmpty() },
enabled = state == MnemonicState.Display || (inputs.all { it.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(it) }),
onClick = {
val words = inputs.map { it.trim() }
validate?.invoke(words)?.let {
Expand Down Expand Up @@ -634,7 +648,7 @@ fun MnemonicPhraseInput(
},
colors =
ButtonDefaults.outlinedButtonColors(
backgroundColor = if (state == MnemonicState.Display || inputs.all { it.isNotEmpty() }) {
backgroundColor = if (state == MnemonicState.Display || (inputs.all { it.isNotEmpty() && MnemonicCode.INSTANCE.wordList.contains(it) })) {
MixinAppTheme.colors.accent
} else {
MixinAppTheme.colors.backgroundGray
Expand Down