Skip to content

Commit 9c6aff5

Browse files
committed
a bit of cleanup
1 parent 38b7e60 commit 9c6aff5

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

src/components/Form/FormPasswordGenerator.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ import type {
1414
control,
1515
field,
1616
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
17-
const [password, createPassword] = useState<string>("");
18-
19-
const generate = () => {
20-
let generatedPass = "VHl1OTVpY7TAly0jGF0X2A==";
21-
return generatedPass
22-
}
23-
2417
return (
2518
<Controller
2619
name={field.name}

src/components/PageComponents/Channel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
8181
label: "pre-Shared Key",
8282
description: "256, 128, or 8 bit PSKs allowed",
8383
properties: {
84-
// act
84+
passwordValue: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
85+
devicePSKBitCount: channel?.settings?.psk.length
8586
},
8687
},
8788
{

src/components/UI/Generator.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,15 @@ export interface GeneratorProps
5050
extends React.BaseHTMLAttributes<HTMLElement>,
5151
VariantProps<typeof generatorVariants>
5252
{
53+
devicePSKBitCount?: number;
5354
passwordValue?: string;
5455
textValue?: string;
5556
}
5657

5758
const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
58-
({ passwordValue, textValue, className, variant, size, ...props }, ref) => {
59-
const [pass, setPass] = useState<string>("");
60-
const [bitCount, setBits] = useState<string>("bit256");
61-
62-
const generate = () => {
63-
let generated = "thisisapass";
64-
if (bitCount == "bit8") {
65-
generated = btoa(cryptoRandomString({length: 1, type: 'alphanumeric'}));
66-
}
67-
if (bitCount == "bit128") {
68-
generated = btoa(cryptoRandomString({length: 16, type: 'alphanumeric'}));
69-
}
70-
if (bitCount == "bit256") {
71-
generated = btoa(cryptoRandomString({length: 32, type: 'alphanumeric'}));
72-
}
73-
return generated;
74-
};
59+
({ devicePSKBitCount, passwordValue, textValue, className, variant, size, ...props }, ref) => {
60+
const [pass, setPass] = useState<string>(passwordValue ?? "");
61+
const [bitCount, setBits] = useState<string>(devicePSKBitCount?.toString() ?? "");
7562

7663
return (
7764
<>
@@ -87,9 +74,9 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
8774
<SelectValue />
8875
</SelectTrigger>
8976
<SelectContent>
90-
<SelectItem key="bit256" value="bit256">256 bit</SelectItem>
91-
<SelectItem key="bit128" value="bit128">128 bit</SelectItem>
92-
<SelectItem key="bit8" value="bit8">8 bit</SelectItem>
77+
<SelectItem key="bit256" value="32">256 bit</SelectItem>
78+
<SelectItem key="bit128" value="16">128 bit</SelectItem>
79+
<SelectItem key="bit8" value="1">8 bit</SelectItem>
9380
</SelectContent>
9481
</Select>
9582
<Button
@@ -98,7 +85,7 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
9885
ref={ref}
9986
{...props}
10087
onClick={() => {
101-
setPass(generate());
88+
setPass(btoa(cryptoRandomString({length: Number.parseInt(bitCount), type: 'alphanumeric'})));
10289
}}
10390
>
10491
{textValue}

0 commit comments

Comments
 (0)