From 3b0345a845febe1b71b6b4949f8a0a991720e723 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 29 Aug 2023 22:04:11 +0700 Subject: [PATCH] chore: only show login dialog if nip-07 extension is not present --- src/element/login-signup.tsx | 23 ----------------------- src/pages/layout.tsx | 26 ++++++++++++++++++++------ 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/element/login-signup.tsx b/src/element/login-signup.tsx index 1878044..d5bd93b 100644 --- a/src/element/login-signup.tsx +++ b/src/element/login-signup.tsx @@ -10,7 +10,6 @@ import { Icon } from "./icon"; import Copy from "./copy"; import { hexToBech32, openFile } from "utils"; import { VoidApi } from "@void-cat/api"; -import { LoginType } from "login"; import { FormattedMessage } from "react-intl"; import { bech32 } from "@scure/base"; @@ -27,23 +26,6 @@ export function LoginSignup({ close }: { close: () => void }) { const [avatar, setAvatar] = useState(""); const [key, setNewKey] = useState(""); - async function doLogin() { - try { - const pub = await EventPublisher.nip7(); - if (pub) { - Login.loginWithPubkey(pub.pubKey, LoginType.Nip7); - close(); - } - } catch (e) { - console.error(e); - if (e instanceof Error) { - setError(e.message); - } else { - setError(e as string); - } - } - } - function doLoginNsec() { try { let nsec = prompt("Enter your nsec\nWARNING: THIS IS NOT RECOMMENDED. DO NOT IMPORT ANY KEYS YOU CARE ABOUT"); @@ -118,11 +100,6 @@ export function LoginSignup({ close }: { close: () => void }) {

- {"nostr" in window && ( - - - - )} diff --git a/src/pages/layout.tsx b/src/pages/layout.tsx index 933db53..4bffe4d 100644 --- a/src/pages/layout.tsx +++ b/src/pages/layout.tsx @@ -13,6 +13,8 @@ import { Menu, MenuItem } from "@szhsin/react-menu"; import { hexToBech32 } from "@snort/shared"; import { Login } from "index"; import { FormattedMessage } from "react-intl"; +import { EventPublisher } from "@snort/system"; +import { LoginType } from "login"; export function LayoutPage() { const navigate = useNavigate(); @@ -62,14 +64,26 @@ export function LayoutPage() { function loggedOut() { if (login) return; + async function handleLogin() { + try { + const pub = await EventPublisher.nip7(); + if (pub) { + Login.loginWithPubkey(pub.pubKey, LoginType.Nip7); + return; + } + } + catch(e) { + console.error(e); + } + setShowLogin(true); + } + return ( - - - +