fix: nsec login
This commit is contained in:
@ -14,7 +14,7 @@ import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
|
|||||||
import { EventPublisher, PrivateKeySigner, UserMetadata } from "@snort/system";
|
import { EventPublisher, PrivateKeySigner, UserMetadata } from "@snort/system";
|
||||||
import { schnorr } from "@noble/curves/secp256k1";
|
import { schnorr } from "@noble/curves/secp256k1";
|
||||||
import { bytesToHex } from "@noble/curves/abstract/utils";
|
import { bytesToHex } from "@noble/curves/abstract/utils";
|
||||||
import { LNURL, bech32ToHex, getPublicKey, hexToBech32 } from "@snort/shared";
|
import { LNURL, bech32ToHex, getPublicKey, hexToBech32, isHex } from "@snort/shared";
|
||||||
import { SnortContext } from "@snort/system-react";
|
import { SnortContext } from "@snort/system-react";
|
||||||
|
|
||||||
import { Login, LoginType } from "@/login";
|
import { Login, LoginType } from "@/login";
|
||||||
@ -45,7 +45,6 @@ export function LoginSignup({ close }: { close: () => void }) {
|
|||||||
const [key, setNewKey] = useState("");
|
const [key, setNewKey] = useState("");
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const hasNostrExtension = "nostr" in window && window.nostr;
|
const hasNostrExtension = "nostr" in window && window.nostr;
|
||||||
const signer = key ? new PrivateKeySigner(key) : undefined;
|
|
||||||
|
|
||||||
function doLoginNsec() {
|
function doLoginNsec() {
|
||||||
try {
|
try {
|
||||||
@ -134,6 +133,20 @@ export function LoginSignup({ close }: { close: () => void }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function imageUploadSection() {
|
||||||
|
const signer = key && key.length === 64 && isHex(key) ? new PrivateKeySigner(key) : undefined;
|
||||||
|
if (!signer) return;
|
||||||
|
return (
|
||||||
|
<FileUploader
|
||||||
|
publisher={new EventPublisher(signer, signer.getPubKey())}
|
||||||
|
onResult={e => setAvatar(e ?? "")}
|
||||||
|
onError={e => setError(e.toString())}
|
||||||
|
className="absolute flex items-center justify-center w-full h-full hover:opacity-30 opacity-0 transition bg-black cursor-pointer">
|
||||||
|
<Icon name="camera-plus" />
|
||||||
|
</FileUploader>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case Stage.Login: {
|
case Stage.Login: {
|
||||||
return (
|
return (
|
||||||
@ -222,15 +235,7 @@ export function LoginSignup({ close }: { close: () => void }) {
|
|||||||
</h2>
|
</h2>
|
||||||
<div className="relative mx-auto w-[100px] h-[100px] rounded-full overflow-hidden bg-layer-3">
|
<div className="relative mx-auto w-[100px] h-[100px] rounded-full overflow-hidden bg-layer-3">
|
||||||
{avatar && <img className="absolute object-fit w-full h-full" src={avatar} />}
|
{avatar && <img className="absolute object-fit w-full h-full" src={avatar} />}
|
||||||
{signer && (
|
{imageUploadSection()}
|
||||||
<FileUploader
|
|
||||||
publisher={new EventPublisher(signer, signer.getPubKey())}
|
|
||||||
onResult={e => setAvatar(e ?? "")}
|
|
||||||
onError={e => setError(e.toString())}
|
|
||||||
className="absolute flex items-center justify-center w-full h-full hover:opacity-30 opacity-0 transition bg-black cursor-pointer">
|
|
||||||
<Icon name="camera-plus" />
|
|
||||||
</FileUploader>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
Reference in New Issue
Block a user