reuse relayprovider
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import User from '@lume/auth/components/user';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { onboardingAtom } from '@lume/stores/onboarding';
|
||||
import { createAccount, createPleb } from '@lume/utils/storage';
|
||||
@@ -6,9 +7,8 @@ import { arrayToNIP02 } from '@lume/utils/transform';
|
||||
|
||||
import { CheckCircle } from 'iconoir-react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useState } from 'react';
|
||||
import { useContext, useState } from 'react';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
const initialList = [
|
||||
@@ -47,6 +47,8 @@ const initialList = [
|
||||
];
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [follows, setFollows] = useState([]);
|
||||
const [onboarding] = useAtom(onboardingAtom);
|
||||
@@ -58,7 +60,6 @@ export function Page() {
|
||||
};
|
||||
|
||||
const broadcastAccount = () => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
// build event
|
||||
const event: any = {
|
||||
content: JSON.stringify(onboarding.metadata),
|
||||
@@ -74,7 +75,6 @@ export function Page() {
|
||||
};
|
||||
|
||||
const broadcastContacts = () => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const nip02 = arrayToNIP02(follows);
|
||||
// build event
|
||||
const event: any = {
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
import { DEFAULT_AVATAR, READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||
import { onboardingAtom } from '@lume/stores/onboarding';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
import { createAccount, createPleb } from '@lume/utils/storage';
|
||||
|
||||
import { useAtom } from 'jotai';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getPublicKey } from 'nostr-tools';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useContext, useMemo, 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 [loading, setLoading] = useState(false);
|
||||
const [onboarding, setOnboarding] = useAtom(onboardingAtom);
|
||||
const pubkey = useMemo(() => (onboarding.privkey ? getPublicKey(onboarding.privkey) : ''), [onboarding.privkey]);
|
||||
|
||||
const { data: user, error } = useSWRSubscription(
|
||||
pubkey && !loading
|
||||
? [
|
||||
{
|
||||
kinds: [0, 3],
|
||||
authors: [pubkey],
|
||||
},
|
||||
]
|
||||
: null,
|
||||
(key, { next }) => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
|
||||
const unsubscribe = pool.subscribe(key, READONLY_RELAYS, (event: any) => {
|
||||
const { data: user, error } = useSWRSubscription(pubkey && !loading ? pubkey : null, (key, { next }) => {
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
kinds: [0, 3],
|
||||
authors: [key],
|
||||
},
|
||||
],
|
||||
null,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
case 0:
|
||||
// update state
|
||||
@@ -41,13 +40,13 @@ export function Page() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
// show loading indicator
|
||||
|
||||
Reference in New Issue
Block a user