mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
Create mkstack
This commit is contained in:
80 files changed
+14388
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { NostrEvent, NPool, NRelay1 } from '@nostrify/nostrify';
|
||||
import { NostrContext } from '@nostrify/react';
|
||||
import React, { useRef } from 'react';
|
||||
|
||||
interface NostrProviderProps {
|
||||
children: React.ReactNode;
|
||||
relays: `wss://${string}`[];
|
||||
}
|
||||
|
||||
const NostrProvider: React.FC<NostrProviderProps> = (props) => {
|
||||
const { children, relays } = props;
|
||||
|
||||
// Create NPool instance only once
|
||||
const pool = useRef<NPool | undefined>(undefined);
|
||||
|
||||
if (!pool.current) {
|
||||
pool.current = new NPool({
|
||||
open(url: string) {
|
||||
return new NRelay1(url);
|
||||
},
|
||||
reqRouter(filters) {
|
||||
return new Map(relays.map((url) => [url, filters]));
|
||||
},
|
||||
eventRouter(_event: NostrEvent) {
|
||||
return relays;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<NostrContext.Provider value={{ nostr: pool.current }}>
|
||||
{children}
|
||||
</NostrContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default NostrProvider;
|
||||
Reference in new issue
Block a user