reuse relayprovider

This commit is contained in:
Ren Amamiya
2023-04-29 10:25:40 +07:00
parent be8b40c86d
commit 3f06193c59
27 changed files with 151 additions and 156 deletions

View File

@@ -1,15 +1,15 @@
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
import { updateChannelMetadata } from '@lume/utils/storage';
import { getChannel } from '@lume/utils/storage';
import { RelayPool } from 'nostr-relaypool';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useContext, useEffect, useState } from 'react';
export const useChannelMetadata = (id: string, channelPubkey: string) => {
const pool: any = useContext(RelayContext);
const [metadata, setMetadata] = useState(null);
const fetchFromRelay = useCallback(() => {
const pool = new RelayPool(READONLY_RELAYS);
const unsubscribe = pool.subscribe(
[
{

View File

@@ -1,11 +1,13 @@
import { FULL_RELAYS } from '@lume/stores/constants';
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
import { RelayPool } from 'nostr-relaypool';
import { useContext } from 'react';
import useSWRSubscription from 'swr/subscription';
export const useChannelProfile = (id: string, channelPubkey: string) => {
const pool: any = useContext(RelayContext);
const { data } = useSWRSubscription(id ? id : null, (key, { next }) => {
const pool = new RelayPool(FULL_RELAYS);
const unsubscribe = pool.subscribe(
[
{
@@ -17,7 +19,7 @@ export const useChannelProfile = (id: string, channelPubkey: string) => {
kinds: [40],
},
],
FULL_RELAYS,
READONLY_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) {
case 40: