clean up
This commit is contained in:
@@ -8,16 +8,7 @@ import { useLocalStorage, writeStorage } from '@rehooks/local-storage';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import { generatePrivateKey, getEventHash, getPublicKey, nip19, signEvent } from 'nostr-tools';
|
||||
import {
|
||||
JSXElementConstructor,
|
||||
ReactElement,
|
||||
ReactFragment,
|
||||
ReactPortal,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useContext, useMemo, useState } from 'react';
|
||||
import { Config, names, uniqueNamesGenerator } from 'unique-names-generator';
|
||||
|
||||
const config: Config = {
|
||||
@@ -42,6 +33,7 @@ export default function Page() {
|
||||
const npub = nip19.npubEncode(pubKey);
|
||||
const nsec = nip19.nsecEncode(privKey);
|
||||
|
||||
// toggle privatek key
|
||||
const showPrivateKey = () => {
|
||||
if (type === 'password') {
|
||||
setType('text');
|
||||
@@ -49,7 +41,6 @@ export default function Page() {
|
||||
setType('password');
|
||||
}
|
||||
};
|
||||
|
||||
// auto-generated profile
|
||||
const data = useMemo(
|
||||
() => ({
|
||||
@@ -61,16 +52,16 @@ export default function Page() {
|
||||
}),
|
||||
[name]
|
||||
);
|
||||
|
||||
const insertDB = useCallback(async () => {
|
||||
// insert to database
|
||||
const insertDB = async () => {
|
||||
await db.execute(
|
||||
`INSERT INTO accounts (id, privkey, npub, nsec, metadata) VALUES ("${pubKey}", "${privKey}", "${npub}", "${nsec}", '${JSON.stringify(
|
||||
data
|
||||
)}')`
|
||||
);
|
||||
}, [data, db, npub, nsec, privKey, pubKey]);
|
||||
|
||||
const createAccount = async () => {
|
||||
};
|
||||
// build event and broadcast to all relays
|
||||
const createAccount = () => {
|
||||
setLoading(true);
|
||||
|
||||
// build event
|
||||
@@ -83,7 +74,7 @@ export default function Page() {
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privKey);
|
||||
|
||||
// insert to database then broadcast
|
||||
insertDB()
|
||||
.then(() => {
|
||||
// publish to relays
|
||||
|
||||
@@ -78,7 +78,6 @@ export default function Page() {
|
||||
const arr = follows.includes(pubkey) ? follows.filter((i) => i !== pubkey) : [...follows, pubkey];
|
||||
setFollows(arr);
|
||||
};
|
||||
|
||||
// insert follow to database
|
||||
const insertDB = async () => {
|
||||
// self follow
|
||||
@@ -92,7 +91,6 @@ export default function Page() {
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
// build event tags
|
||||
const createTags = () => {
|
||||
const tags = [];
|
||||
@@ -103,7 +101,6 @@ export default function Page() {
|
||||
|
||||
return tags;
|
||||
};
|
||||
|
||||
// commit and publish to relays
|
||||
const createFollows = () => {
|
||||
setLoading(true);
|
||||
|
||||
@@ -45,7 +45,6 @@ export default function Page() {
|
||||
},
|
||||
[db, privkey, pubkey]
|
||||
);
|
||||
|
||||
// save follows to database
|
||||
const insertFollows = useCallback(
|
||||
async (follows) => {
|
||||
@@ -60,13 +59,13 @@ export default function Page() {
|
||||
},
|
||||
[db, pubkey]
|
||||
);
|
||||
|
||||
// submit then redirect to home
|
||||
const submit = () => {
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
relayPool.subscribe(
|
||||
const unsubscribe = relayPool.subscribe(
|
||||
[
|
||||
{
|
||||
authors: [pubkey],
|
||||
@@ -89,6 +88,10 @@ export default function Page() {
|
||||
console.log(events, relayURL);
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [insertAccount, insertFollows, pubkey, relayPool, relays]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user