fix: accept newline-separated seed words in import (fixes #3128)#3188
Open
TeapoyY wants to merge 1 commit intotari-project:mainfrom
Open
fix: accept newline-separated seed words in import (fixes #3128)#3188TeapoyY wants to merge 1 commit intotari-project:mainfrom
TeapoyY wants to merge 1 commit intotari-project:mainfrom
Conversation
Fixes tari-project#3128 Two changes: 1. Edit.tsx: Updated SEEDWORD_REGEX to accept multiple whitespace chars between words and allow leading/trailing whitespace. Old: /^(([a-zA-Z]+)\s){23}([a-zA-Z]+)\$/ New: /^\s*(([a-zA-Z]+)\s+){23}([a-zA-Z]+)\s*\$/ 2. SeedWords.tsx: Changed handleApply to split by any whitespace, not just spaces. This correctly handles newline-separated, space-separated, and mixed input formats. Old: data.seedWords.split(' ') New: data.seedWords.trim().split(/\s+/)
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of seed word input by allowing multiple whitespace characters and trimming leading or trailing spaces in both the processing logic and the validation regex. A review comment suggests further normalizing the input to lowercase to prevent issues with case-sensitive wordlists.
| const handleApply = (data: { seedWords: string }) => { | ||
| setNewSeedWords(data.seedWords.split(' ')); | ||
| // Split by any whitespace (spaces, newlines, tabs) to support multiple input formats | ||
| setNewSeedWords(data.seedWords.trim().split(/\s+/)); |
Contributor
There was a problem hiding this comment.
It is a good practice to normalize seed words to lowercase before processing them. This prevents potential issues with the backend if it expects a strict lowercase wordlist (like BIP-39) and handles cases where users might have accidental capitalization from mobile keyboards or copy-pasting.
Suggested change
| setNewSeedWords(data.seedWords.trim().split(/\s+/)); | |
| setNewSeedWords(data.seedWords.trim().toLowerCase().split(/\s+/)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed the seed word import to accept both newline-separated and space-separated input formats.
Changes
1. src/components/wallet/seedwords/components/Edit.tsx
Updated the SEEDWORD_REGEX to:
Before: /^(([a-zA-Z]+)\s){23}([a-zA-Z]+)$/
After: /^\s*(([a-zA-Z]+)\s+){23}([a-zA-Z]+)\s*$/
2. src/components/wallet/seedwords/SeedWords.tsx
Changed handleApply to split by any whitespace instead of just spaces:
Before: data.seedWords.split(' ')
After: data.seedWords.trim().split(/\s+/)
This correctly handles:
Root Cause
Acceptance Criteria (from issue)
Closes #3128