diff --git a/app/Login.tsx b/app/Login.tsx index 8e37089..83aaa3b 100644 --- a/app/Login.tsx +++ b/app/Login.tsx @@ -7,12 +7,17 @@ import Button from "./Button"; import AccountButton from "./AccountButton"; import { KeysContext } from "./context/keys-provider.jsx"; +import PopupInput from "./PopupInput"; +import { generatePrivateKey, getPublicKey } from "nostr-tools"; +import { ImShuffle } from "react-icons/im"; +import { FaSignInAlt } from "react-icons/fa"; export default function Login() { // @ts-ignore const { keys, setKeys } = useContext(KeysContext); const [isOpen, setIsOpen] = useState(false); const [isLightningConnected, setIsLightningConnected] = useState(false); + const [hidePrivateKey, setHidePrivateKey] = useState(true); useEffect(() => { const shouldReconnect = localStorage.getItem("shouldReconnect"); @@ -28,7 +33,7 @@ export default function Login() { // @ts-ignore const publicKey = await nostr.getPublicKey(); // console.log("public key", publicKey); - setKeys({ privateKey: "", publicKey: publicKey }); + setKeys({ privateKey: "", publicKey }); } catch (e: any) { console.log(e.message); } @@ -39,7 +44,7 @@ export default function Login() { if (shouldReconnect === "true") { getConnected(shouldReconnect); } - }, []); + }, [setKeys]); const loginHandler = async () => { // @ts-ignore @@ -56,6 +61,12 @@ export default function Login() { setIsOpen(false); }; + const generateKeys = () => { + const privateKey = generatePrivateKey(); + const publicKey = getPublicKey(privateKey); + setKeys({ privateKey, publicKey }); + }; + const handleClick = async () => { setIsOpen(true); }; @@ -76,12 +87,48 @@ export default function Login() { )} +
+ setKeys({ ...keys, privateKey: e.target.value })} + password={keys.privateKey} + isPassword={hidePrivateKey} + toggleIsPassword={() => setHidePrivateKey((current) => !current)} + /> +
+ setKeys({ ...keys, publicKey: e.target.value })} + /> +
+ + +
+

OR

diff --git a/app/PopupInput.tsx b/app/PopupInput.tsx index 4991653..d595b74 100644 --- a/app/PopupInput.tsx +++ b/app/PopupInput.tsx @@ -1,4 +1,7 @@ import { DetailedHTMLProps, InputHTMLAttributes, useId } from "react"; +import { RxEyeClosed, RxEyeOpen } from "react-icons/rx"; +import Button from "./Button"; +import Truncate from "./Truncate"; interface PopupInputProps extends DetailedHTMLProps< @@ -9,6 +12,9 @@ interface PopupInputProps error?: string; value?: string; className?: string; + password?: string; + isPassword?: boolean; + toggleIsPassword?: () => void; } const PopupInput = ({ @@ -17,25 +23,42 @@ const PopupInput = ({ placeholder = "", value = "", className = "", + password = "", + isPassword, + toggleIsPassword, ...props }: PopupInputProps) => { const id = useId(); return ( -
+
{error &&

{error}

} {error ? null : ( - +
+ + {toggleIsPassword ? ( +
+ +
+ ) : null} +
)}
);