diff --git a/src/pages/onboarding/create.tsx b/src/pages/onboarding/create.tsx index 66532ce4..d5ba257e 100644 --- a/src/pages/onboarding/create.tsx +++ b/src/pages/onboarding/create.tsx @@ -53,7 +53,7 @@ export default function Page() { const pubKey = getPublicKey(privKey); const npub = nip19.npubEncode(pubKey); - const nsec = nip19.nsecEncode(pubKey); + const nsec = nip19.nsecEncode(privKey); // auto-generated profile const data = { @@ -96,7 +96,7 @@ export default function Page() { pubkey: pubKey, }); - // redirect to following newsfeed + // redirect to pre-follow setTimeout(() => { setLoading(false); router.push('/onboarding/following'); diff --git a/src/pages/onboarding/fetch-profile.tsx b/src/pages/onboarding/fetch-profile.tsx new file mode 100644 index 00000000..d3ba1788 --- /dev/null +++ b/src/pages/onboarding/fetch-profile.tsx @@ -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 ( +
+
{/* spacer */}
+ +
+ + Getting your old profile + + + 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 + +
+
+

#TODO: show profile

+
+
+ +
+
+ +
+
+
+
+ ); +} + +Page.getLayout = function getLayout( + page: + | string + | number + | boolean + | ReactElement> + | ReactFragment + | ReactPortal +) { + return ( + + {page} + + ); +}; diff --git a/src/pages/onboarding/import.tsx b/src/pages/onboarding/import.tsx index 38642e01..9a2b4a26 100644 --- a/src/pages/onboarding/import.tsx +++ b/src/pages/onboarding/import.tsx @@ -7,7 +7,6 @@ import { useRouter } from 'next/router'; import { getPublicKey, nip19 } from 'nostr-tools'; import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal } from 'react'; import { Resolver, useForm } from 'react-hook-form'; -import Database from 'tauri-plugin-sql-api'; type FormValues = { key: string; @@ -44,15 +43,10 @@ export default function Page() { try { const pubKey = getPublicKey(privKey); if (pubKey) { - const npub = nip19.npubEncode(pubKey); - const db = await Database.load('sqlite:lume.db'); - - await db.execute( - `INSERT INTO accounts (privkey, pubkey, npub) VALUES ("${privKey}", "${pubKey}", "${npub}")` - ); - await db.close(); - - router.push('/'); + router.push({ + pathname: '/onboarding/fetch-profile', + query: { privkey: privKey }, + }); } } catch (error) { setError('key', { @@ -63,7 +57,7 @@ export default function Page() { }; return ( -
+
{/* spacer */}
@@ -82,7 +76,7 @@ export default function Page() {
{errors.key &&

{errors.key.message}

}
diff --git a/src/pages/onboarding/index.tsx b/src/pages/onboarding/index.tsx index 0c36339d..e491ae52 100644 --- a/src/pages/onboarding/index.tsx +++ b/src/pages/onboarding/index.tsx @@ -34,7 +34,7 @@ export default function Page() { - Import key + Login