Skip to content

Commit 4f02148

Browse files
Merge pull request #188 from logical-mechanism/fix-whitespaces-in-gui-wallet-creation
rust and ts should mirror functionality for white space removal
2 parents d20cade + 2d726e3 commit 4f02148

4 files changed

Lines changed: 77 additions & 8 deletions

File tree

seedelf-platform/seedelf-cli/src/setup.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ pub fn check_and_prepare_seedelf() -> Option<String> {
6464

6565
/// Prompt the user to enter a wallet name
6666
pub fn prompt_wallet_name() -> String {
67-
let mut wallet_name = String::new();
67+
let mut wallet_name: String = String::new();
6868
println!("{}", "\nEnter A Wallet Name:".bright_purple());
6969
io::stdout().flush().unwrap();
7070
io::stdin()
7171
.read_line(&mut wallet_name)
7272
.expect("Failed to read wallet name");
73-
let final_name: String = wallet_name.trim().to_string();
73+
let final_name: String = wallet_name
74+
.split_whitespace() // breaks on any whitespace sequence
75+
.collect::<Vec<_>>() // collect the pieces
76+
.join("_");
7477
if final_name.is_empty() {
7578
println!("{}", "Wallet Must Not Have Empty Name.".red());
7679
return prompt_wallet_name();

seedelf-platform/seedelf-cli/tests/setup_test.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,57 @@ fn test_good_password() {
2929
let pw: String = "i@G37xzM@qcgk3g".to_string();
3030
assert_eq!(password_complexity_check(pw), true)
3131
}
32+
33+
#[test]
34+
fn test_remove_white_spaces_no_spaces() {
35+
let name: String = "NoSpacesHere".to_string();
36+
let final_name = name
37+
.split_whitespace() // breaks on any whitespace sequence
38+
.collect::<Vec<_>>() // collect the pieces
39+
.join("_");
40+
assert_eq!(name, final_name)
41+
}
42+
43+
#[test]
44+
fn test_remove_white_spaces_single_spaces() {
45+
let name: String = "Single Space".to_string();
46+
let final_name: String = name
47+
.split_whitespace() // breaks on any whitespace sequence
48+
.collect::<Vec<_>>() // collect the pieces
49+
.join("_");
50+
let expected: String = "Single_Space".to_string();
51+
assert_eq!(expected, final_name)
52+
}
53+
54+
#[test]
55+
fn test_remove_white_spaces_multiple_spaces() {
56+
let name: String = "Multiple Space".to_string();
57+
let final_name: String = name
58+
.split_whitespace() // breaks on any whitespace sequence
59+
.collect::<Vec<_>>() // collect the pieces
60+
.join("_");
61+
let expected: String = "Multiple_Space".to_string();
62+
assert_eq!(expected, final_name)
63+
}
64+
65+
#[test]
66+
fn test_remove_white_spaces_tab() {
67+
let name: String = "Tab Space".to_string();
68+
let final_name: String = name
69+
.split_whitespace() // breaks on any whitespace sequence
70+
.collect::<Vec<_>>() // collect the pieces
71+
.join("_");
72+
let expected: String = "Tab_Space".to_string();
73+
assert_eq!(expected, final_name)
74+
}
75+
76+
#[test]
77+
fn test_remove_white_spaces_trailing() {
78+
let name: String = " Single Space ".to_string();
79+
let final_name: String = name
80+
.split_whitespace() // breaks on any whitespace sequence
81+
.collect::<Vec<_>>() // collect the pieces
82+
.join("_");
83+
let expected: String = "Single_Space".to_string();
84+
assert_eq!(expected, final_name)
85+
}

seedelf-platform/seedelf-gui/src/components/PasswordField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ interface PasswordFieldProps {
44
label: string;
55
value: string;
66
onChange: (v: string) => void;
7+
disabled?: boolean;
78
}
89

9-
export function PasswordField({ label, value, onChange }: PasswordFieldProps) {
10+
export function PasswordField({ label, value, onChange, disabled }: PasswordFieldProps) {
1011
const [show, setShow] = useState(false);
1112
return (
1213
<label className="flex flex-col gap-1 text-sm">
1314
{label}
1415
<div className="relative">
1516
<input
17+
disabled={disabled}
1618
type={show ? "text" : "password"}
1719
value={value}
1820
onChange={(e) => onChange(e.target.value)}
1921
className="w-full rounded border px-3 py-2 pr-10 focus:outline-none focus:ring"
2022
/>
2123
<button
2224
type="button"
25+
disabled={disabled}
2326
onClick={() => setShow((x) => !x)}
2427
className="absolute right-2 top-1/2 -translate-y-1/2 text-xs"
2528
>

seedelf-platform/seedelf-gui/src/pages/NewWallet.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ export function NewWalletPage() {
1212
const [confirm, setConfirm] = useState("");
1313
const [message, setMessage] = useState<string | null>(null);
1414
const [variant, setVariant] = useState<NotificationVariant>("error");
15+
const [submitting, setSubmitting] = useState(false);
1516

1617
const navigate = useNavigate();
1718

1819
const handleSubmit = async () => {
1920
// Simple custom rules – adjust as needed
2021
if (!name.trim()) return setMessage("Wallet name is required.");
22+
// spaces should be underscores
23+
const walletName: string = name.trim().replace(/\s+/g, "_");
2124

2225
const isStrong = await invoke<boolean>("check_password_complexity", {password: pw});
2326
if (!isStrong) return setMessage(`Passwords Must Contain The Following:
@@ -27,10 +30,14 @@ export function NewWalletPage() {
2730
Number: Requires At Least One Digit.
2831
Special Character: Requires At Least One Special Symbol.`);
2932
if (pw !== confirm) return setMessage("Passwords do not match.");
33+
34+
setSubmitting(true);
35+
let success = false;
3036
try {
31-
await invoke("create_new_wallet", { walletName: name, password: pw });
37+
await invoke("create_new_wallet", { walletName: walletName, password: pw });
3238
const walletExists = await invoke<WalletExistsResult>("check_if_wallet_exists");
3339
if (walletExists) {
40+
success = true;
3441
setMessage(`Wallet Was Created!`);
3542
setVariant('success');
3643
setTimeout(() => navigate("/wallet/"), 2718);
@@ -41,6 +48,8 @@ export function NewWalletPage() {
4148
}
4249
} catch (e: any) {
4350
setMessage(e as string);
51+
} finally {
52+
if (!success) setSubmitting(false);
4453
}
4554
};
4655

@@ -50,10 +59,10 @@ export function NewWalletPage() {
5059

5160
<ShowNotification message={message} setMessage={setMessage} variant={variant} />
5261

53-
<TextField label="Wallet name" value={name} onChange={(e) => setName(e.target.value)} />
62+
<TextField label="Wallet name" value={name} onChange={(e) => setName(e.target.value)} disabled={submitting}/>
5463

55-
<PasswordField label="Password" value={pw} onChange={setPw} />
56-
<PasswordField label="Confirm password" value={confirm} onChange={setConfirm} />
64+
<PasswordField label="Password" value={pw} onChange={setPw} disabled={submitting}/>
65+
<PasswordField label="Confirm password" value={confirm} onChange={setConfirm} disabled={submitting}/>
5766

5867
<div className="flex items-center justify-between">
5968
<button onClick={() => navigate("/")} className="rounded px-3 py-2 text-sm underline">
@@ -63,7 +72,7 @@ export function NewWalletPage() {
6372
<button
6473
onClick={handleSubmit}
6574
className="rounded bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
66-
disabled={!name || !pw || !confirm}
75+
disabled={submitting || !name || !pw || !confirm}
6776
>
6877
Create
6978
</button>

0 commit comments

Comments
 (0)