Skip to content

fix: accept newline-separated seed words in import (fixes #3128)#3188

Open
TeapoyY wants to merge 1 commit intotari-project:mainfrom
TeapoyY:fix/seed-word-import-newlines
Open

fix: accept newline-separated seed words in import (fixes #3128)#3188
TeapoyY wants to merge 1 commit intotari-project:mainfrom
TeapoyY:fix/seed-word-import-newlines

Conversation

@TeapoyY
Copy link
Copy Markdown

@TeapoyY TeapoyY commented Apr 10, 2026

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:

  • Accept multiple whitespace characters (spaces, newlines, tabs) between words: \s+ instead of \s
  • Allow leading and trailing whitespace: ^\s* and \s*$

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:

  • Space-separated: word1 word2 word3 ...
  • Newline-separated: word1\nword2\nword3...
  • Copy-pasted text with mixed whitespace
  • Text with leading/trailing whitespace

Root Cause

  1. The original regex \s only matched single whitespace characters. Multi-line input with newlines between words could cause the pattern to fail in edge cases.
  2. The split(' ') only split on space characters, not on newlines or tabs, so newline-separated input would produce an incorrect word array.

Acceptance Criteria (from issue)

  • Seed word import handles words entered one per line (newline-separated) in addition to space-separated
  • Seed word import works correctly when copy-pasting the full phrase
  • The confirmation tick becomes available once valid seed words are detected, regardless of whitespace format

Closes #3128

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+/)
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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+/));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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+/));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

seed wallet import problem

1 participant