chore: only show login dialog if nip-07 extension is not present
This commit is contained in:
@ -10,7 +10,6 @@ import { Icon } from "./icon";
|
|||||||
import Copy from "./copy";
|
import Copy from "./copy";
|
||||||
import { hexToBech32, openFile } from "utils";
|
import { hexToBech32, openFile } from "utils";
|
||||||
import { VoidApi } from "@void-cat/api";
|
import { VoidApi } from "@void-cat/api";
|
||||||
import { LoginType } from "login";
|
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
import { bech32 } from "@scure/base";
|
import { bech32 } from "@scure/base";
|
||||||
|
|
||||||
@ -27,23 +26,6 @@ export function LoginSignup({ close }: { close: () => void }) {
|
|||||||
const [avatar, setAvatar] = useState("");
|
const [avatar, setAvatar] = useState("");
|
||||||
const [key, setNewKey] = 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() {
|
function doLoginNsec() {
|
||||||
try {
|
try {
|
||||||
let nsec = prompt("Enter your nsec\nWARNING: THIS IS NOT RECOMMENDED. DO NOT IMPORT ANY KEYS YOU CARE ABOUT");
|
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 }) {
|
|||||||
<h2>
|
<h2>
|
||||||
<FormattedMessage defaultMessage="Login" />
|
<FormattedMessage defaultMessage="Login" />
|
||||||
</h2>
|
</h2>
|
||||||
{"nostr" in window && (
|
|
||||||
<AsyncButton type="button" className="btn btn-primary" onClick={doLogin}>
|
|
||||||
<FormattedMessage defaultMessage="Nostr Extension" />
|
|
||||||
</AsyncButton>
|
|
||||||
)}
|
|
||||||
<button type="button" className="btn btn-primary" onClick={createAccount}>
|
<button type="button" className="btn btn-primary" onClick={createAccount}>
|
||||||
<FormattedMessage defaultMessage="Create Account" />
|
<FormattedMessage defaultMessage="Create Account" />
|
||||||
</button>
|
</button>
|
||||||
|
@ -13,6 +13,8 @@ import { Menu, MenuItem } from "@szhsin/react-menu";
|
|||||||
import { hexToBech32 } from "@snort/shared";
|
import { hexToBech32 } from "@snort/shared";
|
||||||
import { Login } from "index";
|
import { Login } from "index";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
import { EventPublisher } from "@snort/system";
|
||||||
|
import { LoginType } from "login";
|
||||||
|
|
||||||
export function LayoutPage() {
|
export function LayoutPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -62,14 +64,26 @@ export function LayoutPage() {
|
|||||||
function loggedOut() {
|
function loggedOut() {
|
||||||
if (login) return;
|
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 (
|
return (
|
||||||
<Dialog.Root open={showLogin} onOpenChange={setShowLogin}>
|
<Dialog.Root open={showLogin} onOpenChange={setShowLogin}>
|
||||||
<Dialog.Trigger asChild>
|
<button type="button" className="btn btn-border" onClick={handleLogin}>
|
||||||
<button type="button" className="btn btn-border" onClick={() => setShowLogin(true)}>
|
<FormattedMessage defaultMessage="Login" />
|
||||||
<FormattedMessage defaultMessage="Login" />
|
<Icon name="login" />
|
||||||
<Icon name="login" />
|
</button>
|
||||||
</button>
|
|
||||||
</Dialog.Trigger>
|
|
||||||
<Dialog.Portal>
|
<Dialog.Portal>
|
||||||
<Dialog.Overlay className="dialog-overlay" />
|
<Dialog.Overlay className="dialog-overlay" />
|
||||||
<Dialog.Content className="dialog-content">
|
<Dialog.Content className="dialog-content">
|
||||||
|
Reference in New Issue
Block a user