This commit is contained in:
Ren Amamiya
2023-06-03 08:45:47 +07:00
parent e2491e47c0
commit 6e1fa10402
12 changed files with 104 additions and 76 deletions

View File

@@ -1,10 +1,12 @@
import { EyeOffIcon, EyeOnIcon } from "@shared/icons";
import { createAccount } from "@utils/storage";
import { useActiveAccount } from "@stores/accounts";
import { generatePrivateKey, getPublicKey, nip19 } from "nostr-tools";
import { useMemo, useState } from "react";
import { navigate } from "vite-plugin-ssr/client/router";
export function Page() {
const createAccount = useActiveAccount((state: any) => state.create);
const [type, setType] = useState("password");
const privkey = useMemo(() => generatePrivateKey(), []);
@@ -22,11 +24,8 @@ export function Page() {
};
const submit = async () => {
const account = await createAccount(npub, pubkey, privkey, null, 1);
if (account) {
navigate("/app/auth/create/step-2");
}
createAccount(npub, pubkey, privkey, null, 1);
navigate("/app/auth/create/step-2");
};
return (

View File

@@ -10,11 +10,8 @@ import { navigate } from "vite-plugin-ssr/client/router";
export function Page() {
const pool: any = useContext(RelayContext);
const account = useActiveAccount((state: any) => state.account);
const [account, fetchAccount] = useActiveAccount((state: any) => [
state.account,
state.fetch,
]);
const [image, setImage] = useState(DEFAULT_AVATAR);
const [loading, setLoading] = useState(false);
@@ -52,10 +49,6 @@ export function Page() {
);
};
useEffect(() => {
fetchAccount();
}, [fetchAccount]);
useEffect(() => {
setValue("picture", image);
}, [setValue, image]);

View File

@@ -3,7 +3,6 @@ import { CheckCircleIcon } from "@shared/icons";
import { RelayContext } from "@shared/relayProvider";
import { useActiveAccount } from "@stores/accounts";
import { WRITEONLY_RELAYS } from "@stores/constants";
import { updateAccount } from "@utils/storage";
import { arrayToNIP02 } from "@utils/transform";
import { getEventHash, getSignature } from "nostr-tools";
import { useContext, useState } from "react";
@@ -130,11 +129,8 @@ export function Page() {
const submit = async () => {
setLoading(true);
// update account follows in database
updateAccount("follows", follows, account.pubkey);
// update account follows in state
updateFollows(JSON.stringify(follows));
// update account follows
updateFollows(follows);
const tags = arrayToNIP02(follows);
@@ -155,7 +151,7 @@ export function Page() {
// redirect to step 3
setTimeout(
() =>
navigate("/app/prefetch", {
navigate("/", {
overwriteLastHistoryEntry: true,
}),
2000,

View File

@@ -1,4 +1,4 @@
import { createAccount } from "@utils/storage";
import { useActiveAccount } from "@stores/accounts";
import { getPublicKey, nip19 } from "nostr-tools";
import { Resolver, useForm } from "react-hook-form";
import { navigate } from "vite-plugin-ssr/client/router";
@@ -22,6 +22,7 @@ const resolver: Resolver<FormValues> = async (values) => {
};
export function Page() {
const createAccount = useActiveAccount((state: any) => state.create);
const {
register,
setError,
@@ -41,11 +42,8 @@ export function Page() {
const pubkey = getPublicKey(privkey);
const npub = nip19.npubEncode(pubkey);
const account = await createAccount(npub, pubkey, privkey, null, 1);
if (account) {
navigate("/app/auth/import/step-2");
}
createAccount(npub, pubkey, privkey, null, 1);
navigate("/app/auth/import/step-2");
}
} catch (error) {
setError("key", {

View File

@@ -1,31 +1,31 @@
import { User } from "@app/auth/components/user";
import { RelayContext } from "@shared/relayProvider";
import { useActiveAccount } from "@stores/accounts";
import { READONLY_RELAYS } from "@stores/constants";
import { updateAccount } from "@utils/storage";
import { METADATA_RELAY } from "@stores/constants";
import { nip02ToArray } from "@utils/transform";
import { useContext, useEffect, useState } from "react";
import { useContext, useState } from "react";
import useSWRSubscription from "swr/subscription";
import { navigate } from "vite-plugin-ssr/client/router";
export function Page() {
const pool: any = useContext(RelayContext);
const [account, fetchAccount, updateFollows] = useActiveAccount(
(state: any) => [state.account, state.fetch, state.updateFollows],
);
const [account, updateFollows] = useActiveAccount((state: any) => [
state.account,
state.updateFollows,
]);
const [loading, setLoading] = useState(false);
const [follows, setFollows] = useState([]);
const [follows, setFollows] = useState(null);
useSWRSubscription(account ? account.pubkey : null, (key: string) => {
useSWRSubscription(account ? ["follows", account.pubkey] : null, () => {
const unsubscribe = pool.subscribe(
[
{
kinds: [3],
authors: [key],
authors: [account.pubkey],
},
],
READONLY_RELAYS,
METADATA_RELAY,
(event: any) => {
setFollows(event.tags);
},
@@ -43,23 +43,13 @@ export function Page() {
// follows as list
const followsList = nip02ToArray(follows);
// update account follows in database
updateAccount("follows", followsList, account.pubkey);
// update account follows in store
updateFollows(JSON.stringify(followsList));
updateFollows(followsList);
// redirect to home
setTimeout(
() => navigate("/app/prefetch", { overwriteLastHistoryEntry: true }),
2000,
);
setTimeout(() => navigate("/", { overwriteLastHistoryEntry: true }), 2000);
};
useEffect(() => {
fetchAccount();
}, [fetchAccount]);
return (
<div className="flex h-full w-full items-center justify-center">
<div className="mx-auto w-full max-w-md">