fixed import private key process

This commit is contained in:
Ren Amamiya 2023-02-24 20:19:26 +07:00
parent 8125180709
commit 4bc0f1d51d
3 changed files with 18 additions and 41 deletions

View File

@ -3,7 +3,6 @@ import BaseLayout from '@layouts/baseLayout';
import OnboardingLayout from '@layouts/onboardingLayout'; import OnboardingLayout from '@layouts/onboardingLayout';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { GetStaticPaths } from 'next';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useNostrEvents } from 'nostr-react'; import { useNostrEvents } from 'nostr-react';
import { import {
@ -16,11 +15,12 @@ import {
} from 'react'; } from 'react';
import Database from 'tauri-plugin-sql-api'; import Database from 'tauri-plugin-sql-api';
export default function Page({ pubkey }: { pubkey: string }) { export default function Page() {
const [follows, setFollows] = useState([null]); const [follows, setFollows] = useState([null]);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const router = useRouter(); const router = useRouter();
const { pubkey }: any = router.query;
const { onEvent } = useNostrEvents({ const { onEvent } = useNostrEvents({
filter: { filter: {
@ -45,7 +45,7 @@ export default function Page({ pubkey }: { pubkey: string }) {
follows.forEach(async (item) => { follows.forEach(async (item) => {
if (item) { if (item) {
await db.execute( await db.execute(
`INSERT INTO follows (pubkey, account) VALUES ("${item[1]}", "${pubkey}")` `INSERT OR IGNORE INTO follows (pubkey, account) VALUES ("${item[1]}", "${pubkey}")`
); );
} }
}); });
@ -56,7 +56,7 @@ export default function Page({ pubkey }: { pubkey: string }) {
.then(() => { .then(() => {
setTimeout(() => { setTimeout(() => {
setLoading(false); setLoading(false);
router.push('/feed/following'); router.push('/');
}, 1500); }, 1500);
}) })
.catch(console.error); .catch(console.error);
@ -108,20 +108,6 @@ export default function Page({ pubkey }: { pubkey: string }) {
); );
} }
export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [],
fallback: 'blocking',
};
};
export async function getStaticProps(context) {
const pubkey = context.params.pubkey;
return {
props: { pubkey },
};
}
Page.getLayout = function getLayout( Page.getLayout = function getLayout(
page: page:
| string | string

View File

@ -3,7 +3,6 @@ import BaseLayout from '@layouts/baseLayout';
import OnboardingLayout from '@layouts/onboardingLayout'; import OnboardingLayout from '@layouts/onboardingLayout';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { GetStaticPaths } from 'next';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useNostrEvents } from 'nostr-react'; import { useNostrEvents } from 'nostr-react';
import { getPublicKey, nip19 } from 'nostr-tools'; import { getPublicKey, nip19 } from 'nostr-tools';
@ -17,15 +16,16 @@ import {
} from 'react'; } from 'react';
import Database from 'tauri-plugin-sql-api'; import Database from 'tauri-plugin-sql-api';
export default function Page({ privkey }: { privkey: string }) { export default function Page() {
const router = useRouter(); const router = useRouter();
const { privkey }: any = router.query;
const [account, setAccount] = useState(null); const [account, setAccount] = useState(null);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const pubkey = getPublicKey(privkey); const pubkey = privkey ? getPublicKey(privkey) : null;
const npub = nip19.npubEncode(pubkey); const npub = privkey ? nip19.npubEncode(pubkey) : null;
const nsec = nip19.nsecEncode(privkey); const nsec = privkey ? nip19.nsecEncode(privkey) : null;
const { onEvent } = useNostrEvents({ const { onEvent } = useNostrEvents({
filter: { filter: {
@ -62,7 +62,10 @@ export default function Page({ privkey }: { privkey: string }) {
.then(() => { .then(() => {
setTimeout(() => { setTimeout(() => {
setLoading(false); setLoading(false);
router.push(`/onboarding/follows/${pubkey}`); router.push({
pathname: '/onboarding/fetch-follows',
query: { pubkey: pubkey },
});
}, 1500); }, 1500);
}) })
.catch(console.error); .catch(console.error);
@ -114,20 +117,6 @@ export default function Page({ privkey }: { privkey: string }) {
); );
} }
export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [],
fallback: 'blocking',
};
};
export async function getStaticProps(context) {
const privkey = context.params.privkey;
return {
props: { privkey },
};
}
Page.getLayout = function getLayout( Page.getLayout = function getLayout(
page: page:
| string | string

View File

@ -43,9 +43,10 @@ export default function Page() {
} }
try { try {
if (privkey) { router.push({
router.push(`/onboarding/profile/${privkey}`); pathname: '/onboarding/fetch-profile',
} query: { privkey: privkey },
});
} catch (error) { } catch (error) {
setError('key', { setError('key', {
type: 'custom', type: 'custom',
@ -73,6 +74,7 @@ export default function Page() {
<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"> <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">
<input <input
{...register('key', { required: true, minLength: 32 })} {...register('key', { required: true, minLength: 32 })}
type={'password'}
placeholder="Paste nsec or hex key here..." placeholder="Paste nsec or hex 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-800 dark:text-zinc-200 dark:shadow-black/10 dark:placeholder:text-zinc-500" 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-500"
/> />