From 9c6aff534a83f223c5ea96a87f823506f721ba1c Mon Sep 17 00:00:00 2001 From: Hunter Thornsberry Date: Sun, 28 Jul 2024 16:43:41 -0400 Subject: [PATCH] a bit of cleanup --- src/components/Form/FormPasswordGenerator.tsx | 7 ----- src/components/PageComponents/Channel.tsx | 3 +- src/components/UI/Generator.tsx | 29 +++++-------------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/components/Form/FormPasswordGenerator.tsx b/src/components/Form/FormPasswordGenerator.tsx index eb30dc1a..a53e7d96 100644 --- a/src/components/Form/FormPasswordGenerator.tsx +++ b/src/components/Form/FormPasswordGenerator.tsx @@ -14,13 +14,6 @@ import type { control, field, }: GenericFormElementProps>) { - const [password, createPassword] = useState(""); - - const generate = () => { - let generatedPass = "VHl1OTVpY7TAly0jGF0X2A=="; - return generatedPass - } - return ( { label: "pre-Shared Key", description: "256, 128, or 8 bit PSKs allowed", properties: { - // act + passwordValue: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)), + devicePSKBitCount: channel?.settings?.psk.length }, }, { diff --git a/src/components/UI/Generator.tsx b/src/components/UI/Generator.tsx index 857ec51d..ae42ed3f 100644 --- a/src/components/UI/Generator.tsx +++ b/src/components/UI/Generator.tsx @@ -50,28 +50,15 @@ export interface GeneratorProps extends React.BaseHTMLAttributes, VariantProps { + devicePSKBitCount?: number; passwordValue?: string; textValue?: string; } const Generator = React.forwardRef( - ({ passwordValue, textValue, className, variant, size, ...props }, ref) => { - const [pass, setPass] = useState(""); - const [bitCount, setBits] = useState("bit256"); - - const generate = () => { - let generated = "thisisapass"; - if (bitCount == "bit8") { - generated = btoa(cryptoRandomString({length: 1, type: 'alphanumeric'})); - } - if (bitCount == "bit128") { - generated = btoa(cryptoRandomString({length: 16, type: 'alphanumeric'})); - } - if (bitCount == "bit256") { - generated = btoa(cryptoRandomString({length: 32, type: 'alphanumeric'})); - } - return generated; - }; + ({ devicePSKBitCount, passwordValue, textValue, className, variant, size, ...props }, ref) => { + const [pass, setPass] = useState(passwordValue ?? ""); + const [bitCount, setBits] = useState(devicePSKBitCount?.toString() ?? ""); return ( <> @@ -87,9 +74,9 @@ const Generator = React.forwardRef( - 256 bit - 128 bit - 8 bit + 256 bit + 128 bit + 8 bit