mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-18 11:13:30 +00:00
updated import private key process
This commit is contained in:
parent
a603bf9ec1
commit
c0889456a3
@ -53,7 +53,7 @@ export default function Page() {
|
|||||||
|
|
||||||
const pubKey = getPublicKey(privKey);
|
const pubKey = getPublicKey(privKey);
|
||||||
const npub = nip19.npubEncode(pubKey);
|
const npub = nip19.npubEncode(pubKey);
|
||||||
const nsec = nip19.nsecEncode(pubKey);
|
const nsec = nip19.nsecEncode(privKey);
|
||||||
|
|
||||||
// auto-generated profile
|
// auto-generated profile
|
||||||
const data = {
|
const data = {
|
||||||
@ -96,7 +96,7 @@ export default function Page() {
|
|||||||
pubkey: pubKey,
|
pubkey: pubKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
// redirect to following newsfeed
|
// redirect to pre-follow
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
router.push('/onboarding/following');
|
router.push('/onboarding/following');
|
||||||
|
108
src/pages/onboarding/fetch-profile.tsx
Normal file
108
src/pages/onboarding/fetch-profile.tsx
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import BaseLayout from '@layouts/baseLayout';
|
||||||
|
import OnboardingLayout from '@layouts/onboardingLayout';
|
||||||
|
|
||||||
|
import { motion } from 'framer-motion';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { useNostrEvents } from 'nostr-react';
|
||||||
|
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||||
|
import {
|
||||||
|
JSXElementConstructor,
|
||||||
|
ReactElement,
|
||||||
|
ReactFragment,
|
||||||
|
ReactPortal,
|
||||||
|
useCallback,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import Database from 'tauri-plugin-sql-api';
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
const [account, setAccount] = useState(null);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const { privkey }: any = router.query;
|
||||||
|
|
||||||
|
const pubkey = getPublicKey(privkey);
|
||||||
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
const nsec = nip19.nsecEncode(privkey);
|
||||||
|
|
||||||
|
const { onEvent } = useNostrEvents({
|
||||||
|
filter: {
|
||||||
|
authors: [pubkey],
|
||||||
|
kinds: [0],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
onEvent((rawMetadata) => {
|
||||||
|
try {
|
||||||
|
const metadata: any = JSON.parse(rawMetadata.content);
|
||||||
|
setAccount(metadata);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err, rawMetadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const insertAccount = useCallback(async () => {
|
||||||
|
// save account to database
|
||||||
|
const db = await Database.load('sqlite:lume.db');
|
||||||
|
await db.execute(
|
||||||
|
`INSERT INTO accounts (privkey, pubkey, npub, nsec, metadata) VALUES ("${privkey}", "${pubkey}", "${npub}", "${nsec}", '${JSON.stringify(
|
||||||
|
account
|
||||||
|
)}')`
|
||||||
|
);
|
||||||
|
await db.close();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
router.push('/feed/following');
|
||||||
|
}, 500);
|
||||||
|
}, [account, npub, nsec, privkey, pubkey, router]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full flex-col justify-between px-8">
|
||||||
|
<div>{/* spacer */}</div>
|
||||||
|
<motion.div layoutId="form">
|
||||||
|
<div className="mb-8 flex flex-col gap-3">
|
||||||
|
<motion.h1
|
||||||
|
layoutId="title"
|
||||||
|
className="bg-gradient-to-br from-zinc-200 to-zinc-400 bg-clip-text text-3xl font-medium text-transparent">
|
||||||
|
Getting your old profile
|
||||||
|
</motion.h1>
|
||||||
|
<motion.h2 layoutId="subtitle" className="w-3/4 text-zinc-400">
|
||||||
|
As long as you have private key, you alway can recover your profile as well as follows
|
||||||
|
list when you move to new nostr client
|
||||||
|
</motion.h2>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<p>#TODO: show profile</p>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div layoutId="action" className="pb-5">
|
||||||
|
<div className="flex h-10 items-center">
|
||||||
|
<div className="relative shrink-0 before:pointer-events-none before:absolute before:-inset-1 before:rounded-[11px] before:border before:border-blue-500 before:opacity-0 before:ring-2 before:ring-blue-500/20 before:transition after:pointer-events-none after:absolute after:inset-px after:rounded-[7px] after:shadow-highlight after:shadow-white/5 after:transition focus-within:before:opacity-100 focus-within:after:shadow-blue-500/100 dark:focus-within:after:shadow-blue-500/20">
|
||||||
|
<button
|
||||||
|
onClick={() => insertAccount()}
|
||||||
|
className="transform rounded-lg border border-white/10 bg-[radial-gradient(ellipse_at_bottom_right,_var(--tw-gradient-stops))] from-gray-300 via-fuchsia-600 to-orange-600 px-3.5 py-2 font-medium shadow-input shadow-black/5 active:translate-y-1 disabled:cursor-not-allowed disabled:opacity-50 dark:shadow-black/10">
|
||||||
|
<span className="drop-shadow-lg">Finish →</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Page.getLayout = function getLayout(
|
||||||
|
page:
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| ReactElement<unknown, string | JSXElementConstructor<unknown>>
|
||||||
|
| ReactFragment
|
||||||
|
| ReactPortal
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<BaseLayout>
|
||||||
|
<OnboardingLayout>{page}</OnboardingLayout>
|
||||||
|
</BaseLayout>
|
||||||
|
);
|
||||||
|
};
|
@ -7,7 +7,6 @@ import { useRouter } from 'next/router';
|
|||||||
import { getPublicKey, nip19 } from 'nostr-tools';
|
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal } from 'react';
|
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal } from 'react';
|
||||||
import { Resolver, useForm } from 'react-hook-form';
|
import { Resolver, useForm } from 'react-hook-form';
|
||||||
import Database from 'tauri-plugin-sql-api';
|
|
||||||
|
|
||||||
type FormValues = {
|
type FormValues = {
|
||||||
key: string;
|
key: string;
|
||||||
@ -44,15 +43,10 @@ export default function Page() {
|
|||||||
try {
|
try {
|
||||||
const pubKey = getPublicKey(privKey);
|
const pubKey = getPublicKey(privKey);
|
||||||
if (pubKey) {
|
if (pubKey) {
|
||||||
const npub = nip19.npubEncode(pubKey);
|
router.push({
|
||||||
const db = await Database.load('sqlite:lume.db');
|
pathname: '/onboarding/fetch-profile',
|
||||||
|
query: { privkey: privKey },
|
||||||
await db.execute(
|
});
|
||||||
`INSERT INTO accounts (privkey, pubkey, npub) VALUES ("${privKey}", "${pubKey}", "${npub}")`
|
|
||||||
);
|
|
||||||
await db.close();
|
|
||||||
|
|
||||||
router.push('/');
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError('key', {
|
setError('key', {
|
||||||
@ -63,7 +57,7 @@ export default function Page() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col justify-between">
|
<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col justify-between px-8">
|
||||||
<div>{/* spacer */}</div>
|
<div>{/* spacer */}</div>
|
||||||
<motion.div layoutId="form">
|
<motion.div layoutId="form">
|
||||||
<div className="mb-8 flex flex-col gap-3">
|
<div className="mb-8 flex flex-col gap-3">
|
||||||
@ -82,7 +76,7 @@ export default function Page() {
|
|||||||
<input
|
<input
|
||||||
{...register('key', { required: true, minLength: 32 })}
|
{...register('key', { required: true, minLength: 32 })}
|
||||||
placeholder="Paste key here..."
|
placeholder="Paste key here..."
|
||||||
className="relative w-full rounded-lg border border-black/5 px-3.5 py-2 shadow-input shadow-black/5 !outline-none placeholder:text-zinc-400 dark:bg-zinc-900 dark:text-zinc-200 dark:shadow-black/10 dark:placeholder:text-zinc-600"
|
className="relative w-full rounded-lg border border-black/5 px-3.5 py-2 shadow-input shadow-black/5 !outline-none placeholder:text-zinc-400 dark:bg-zinc-800 dark:text-zinc-200 dark:shadow-black/10 dark:placeholder:text-zinc-600"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm text-red-400">{errors.key && <p>{errors.key.message}</p>}</span>
|
<span className="text-sm text-red-400">{errors.key && <p>{errors.key.message}</p>}</span>
|
||||||
|
@ -34,7 +34,7 @@ export default function Page() {
|
|||||||
<Link
|
<Link
|
||||||
href="/onboarding/import"
|
href="/onboarding/import"
|
||||||
className="hover:bg-zinc-900/2.5 transform rounded-lg border border-black/5 bg-zinc-800 px-3.5 py-2 font-medium ring-1 ring-inset ring-zinc-900/10 hover:text-zinc-900 active:translate-y-1 dark:text-zinc-300 dark:ring-white/10 dark:hover:bg-zinc-700 dark:hover:text-white">
|
className="hover:bg-zinc-900/2.5 transform rounded-lg border border-black/5 bg-zinc-800 px-3.5 py-2 font-medium ring-1 ring-inset ring-zinc-900/10 hover:text-zinc-900 active:translate-y-1 dark:text-zinc-300 dark:ring-white/10 dark:hover:bg-zinc-700 dark:hover:text-white">
|
||||||
Import key
|
Login
|
||||||
</Link>
|
</Link>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user