wip: convert tauri sql to prisma
This commit is contained in:
@@ -2,13 +2,20 @@ import BaseLayout from '@layouts/base';
|
||||
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { createAccount } from '@utils/storage';
|
||||
|
||||
import { ArrowLeftIcon, EyeClosedIcon, EyeOpenIcon } from '@radix-ui/react-icons';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import { generatePrivateKey, getEventHash, getPublicKey, nip19, signEvent } from 'nostr-tools';
|
||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useContext, useMemo, useState } from 'react';
|
||||
import {
|
||||
JSXElementConstructor,
|
||||
ReactElement,
|
||||
ReactFragment,
|
||||
ReactPortal,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Config, names, uniqueNamesGenerator } from 'unique-names-generator';
|
||||
|
||||
const config: Config = {
|
||||
@@ -39,23 +46,11 @@ export default function Page() {
|
||||
display_name: name,
|
||||
name: name,
|
||||
username: name.toLowerCase(),
|
||||
picture: 'https://void.cat/d/KmypFh2fBdYCEvyJrPiN89',
|
||||
picture: 'https://void.cat/d/KmypFh2fBdYCEvyJrPiN89.webp',
|
||||
}),
|
||||
[name]
|
||||
);
|
||||
|
||||
// build profile
|
||||
const data = useMemo(
|
||||
() => ({
|
||||
pubkey: pubKey,
|
||||
privkey: privKey,
|
||||
npub: npub,
|
||||
nsec: nsec,
|
||||
metadata: metadata,
|
||||
}),
|
||||
[metadata, npub, nsec, privKey, pubKey]
|
||||
);
|
||||
|
||||
// toggle privatek key
|
||||
const showPrivateKey = () => {
|
||||
if (type === 'password') {
|
||||
@@ -66,7 +61,8 @@ export default function Page() {
|
||||
};
|
||||
|
||||
// create account and broadcast to all relays
|
||||
const submit = () => {
|
||||
const submit = useCallback(async () => {
|
||||
const { createAccount } = await import('@utils/bindings');
|
||||
setLoading(true);
|
||||
|
||||
// build event
|
||||
@@ -81,16 +77,16 @@ export default function Page() {
|
||||
event.sig = signEvent(event, privKey);
|
||||
|
||||
// insert to database then broadcast
|
||||
createAccount(data)
|
||||
.then(() => {
|
||||
createAccount({ pubkey: pubKey, privkey: privKey, metadata: JSON.stringify(metadata) })
|
||||
.then((res) => {
|
||||
pool.publish(event, relays);
|
||||
router.push({
|
||||
pathname: '/onboarding/create/step-2',
|
||||
query: { id: pubKey, privkey: privKey },
|
||||
query: { id: res.id, privkey: res.privkey },
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
}, [pool, pubKey, privKey, metadata, relays, router]);
|
||||
|
||||
return (
|
||||
<div className="grid h-full w-full grid-rows-5">
|
||||
|
||||
@@ -3,7 +3,7 @@ import BaseLayout from '@layouts/base';
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
import { UserBase } from '@components/user/base';
|
||||
|
||||
import { createFollows } from '@utils/storage';
|
||||
import { followsTag } from '@utils/transform';
|
||||
|
||||
import { CheckCircledIcon } from '@radix-ui/react-icons';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ReactElement,
|
||||
ReactFragment,
|
||||
ReactPortal,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
@@ -76,18 +77,9 @@ export default function Page() {
|
||||
setFollows(arr);
|
||||
};
|
||||
|
||||
// build event tags
|
||||
const tags = () => {
|
||||
const arr = [];
|
||||
// push item to tags
|
||||
follows.forEach((item) => {
|
||||
arr.push(['p', item]);
|
||||
});
|
||||
return arr;
|
||||
};
|
||||
|
||||
// save follows to database then broadcast
|
||||
const submit = () => {
|
||||
const submit = useCallback(async () => {
|
||||
const { createFollow } = await import('@utils/bindings');
|
||||
setLoading(true);
|
||||
|
||||
// build event
|
||||
@@ -96,21 +88,18 @@ export default function Page() {
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
kind: 3,
|
||||
pubkey: id,
|
||||
tags: tags(),
|
||||
tags: followsTag(follows),
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privkey);
|
||||
|
||||
createFollows(follows, id, 0)
|
||||
.then((res) => {
|
||||
if (res === 'ok') {
|
||||
// publish to relays
|
||||
pool.publish(event, relays);
|
||||
router.replace('/');
|
||||
}
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
follows.forEach((item) => {
|
||||
createFollow({ pubkey: item, kind: 0, metadata: JSON.stringify({}), account_id: id });
|
||||
});
|
||||
|
||||
pool.publish(event, relays);
|
||||
router.replace('/');
|
||||
}, [follows, id, pool, privkey, relays, router]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
|
||||
Reference in New Issue
Block a user