minor fixes

This commit is contained in:
Ren Amamiya
2023-04-20 09:47:02 +07:00
parent a3ca2ef548
commit d7c7983963
9 changed files with 61 additions and 73 deletions

View File

@@ -5,6 +5,7 @@ import FormChannelMessage from '@components/form/channelMessage';
import { RelayContext } from '@components/relaysProvider';
import { channelMessagesAtom, channelReplyAtom } from '@stores/channel';
import { FULL_RELAYS } from '@stores/constants';
import useLocalStorage from '@rehooks/local-storage';
import { useSetAtom } from 'jotai';
@@ -12,7 +13,7 @@ import { useResetAtom } from 'jotai/utils';
import { Suspense, useContext, useEffect, useRef } from 'react';
export default function Page({ params }: { params: { id: string } }) {
const [pool, relays]: any = useContext(RelayContext);
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const setChannelMessages = useSetAtom(channelMessagesAtom);
@@ -41,7 +42,7 @@ export default function Page({ params }: { params: { id: string } }) {
since: 0,
},
],
relays,
FULL_RELAYS,
(event: any) => {
if (event.kind === 44) {
muted.current = muted.current.add(event.tags[0][1]);
@@ -62,7 +63,7 @@ export default function Page({ params }: { params: { id: string } }) {
return () => {
unsubscribe();
};
}, [pool, relays, activeAccount.pubkey, params.id, setChannelMessages, resetChannelReply, resetChannelMessages]);
}, [pool, activeAccount.pubkey, params.id, setChannelMessages, resetChannelReply, resetChannelMessages]);
return (
<div className="flex h-full w-full flex-col justify-between">

View File

@@ -5,6 +5,7 @@ import FormChat from '@components/form/chat';
import { RelayContext } from '@components/relaysProvider';
import { chatMessagesAtom } from '@stores/chat';
import { FULL_RELAYS } from '@stores/constants';
import useLocalStorage from '@rehooks/local-storage';
import { useSetAtom } from 'jotai';
@@ -12,7 +13,7 @@ import { useResetAtom } from 'jotai/utils';
import { Suspense, useCallback, useContext, useEffect, useRef } from 'react';
export default function Page({ params }: { params: { pubkey: string } }) {
const [pool, relays]: any = useContext(RelayContext);
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const setChatMessages = useSetAtom(chatMessagesAtom);
@@ -34,12 +35,12 @@ export default function Page({ params }: { params: { pubkey: string } }) {
'#p': [params.pubkey],
},
],
relays,
FULL_RELAYS,
(event: any) => {
setChatMessages((data) => [...data, event]);
}
);
}, [activeAccount.pubkey, params.pubkey, pool, relays, setChatMessages]);
}, [activeAccount.pubkey, params.pubkey, pool, setChatMessages]);
useEffect(() => {
// reset stored messages

View File

@@ -1,3 +0,0 @@
export default function Page() {
return <></>;
}

View File

@@ -1,31 +1,13 @@
'use client';
import { DEFAULT_RELAYS } from '@stores/constants';
import { RelayPool } from 'nostr-relaypool';
import { createContext, useMemo } from 'react';
export const RelayContext = createContext({});
/*
const relays = [
'wss://relay.damus.io',
'wss://nostr-pub.wellorder.net',
'wss://nostr.bongbong.com',
'wss://nostr.zebedee.cloud',
'wss://nostr.fmt.wiz.biz',
'wss://relay.snort.social',
'wss://offchain.pub',
'wss://relay.current.fyi',
'wss://nostr.bitcoiner.social',
'wss://relay.nostr.info',
'wss://nostr-01.dorafactory.org',
'wss://nostr.zhongwen.world',
'wss://nostro.cc',
'wss://relay.nostr.net.in',
'wss://nos.lol',
];
*/
const relays = ['wss://welcome.nostr.wine', 'wss://relay.nostr.band', 'wss://nostr.mutinywallet.com'];
const relays = DEFAULT_RELAYS;
export default function RelayProvider({ children }: { children: React.ReactNode }) {
const pool = useMemo(() => new RelayPool(relays, { useEventCache: false, logSubscriptions: false }), []);

View File

@@ -22,3 +22,13 @@ export const DEFAULT_CHANNELS = [
created_at: 1661333723,
},
];
export const DEFAULT_RELAYS = ['wss://welcome.nostr.wine', 'wss://relay.nostr.band', 'wss://nostr.mutinywallet.com'];
export const FULL_RELAYS = [
'wss://relay.damus.io',
'wss://nostr-pub.wellorder.net',
'wss://nostr.zebedee.cloud',
'wss://nostr.fmt.wiz.biz',
'wss://relay.snort.social',
'wss://offchain.pub',
'wss://relay.current.fyi',
];