forked from keep-starknet-strange/joyboy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor usenostr hook (keep-starknet-strange#118)
* feat: refactor usenostr hook * feat: refactor usenostr hook * feat: added lock file * Fix some issues - Providers moved to Wrapper - Replaced 3 Providers with 1 General Provider - Queries should return the query itself, not just data --------- Co-authored-by: Uğur Eren <[email protected]>
- Loading branch information
1 parent
249042f
commit 391e3f9
Showing
12 changed files
with
416 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import NDK, {NDKNip07Signer} from '@nostr-dev-kit/ndk'; | ||
import {SimplePool} from 'nostr-tools'; | ||
import {createContext, useContext, useMemo} from 'react'; | ||
|
||
import {RELAYS_PROD} from '../utils/relay'; | ||
|
||
export type NostrContextType = { | ||
pool: SimplePool; | ||
relays: string[]; | ||
ndk: NDK; | ||
}; | ||
|
||
export const NostrContext = createContext<NostrContextType | null>(null); | ||
|
||
export const NostrProvider: React.FC<React.PropsWithChildren> = ({children}) => { | ||
const pool = useMemo(() => new SimplePool(), []); | ||
const relays = RELAYS_PROD; | ||
|
||
const ndk = useMemo(() => { | ||
const nip07signer = new NDKNip07Signer(); | ||
return new NDK({signer: nip07signer}); | ||
}, []); | ||
|
||
return <NostrContext.Provider value={{pool, relays, ndk}}>{children}</NostrContext.Provider>; | ||
}; | ||
|
||
export const useNostrContext = () => { | ||
const nostr = useContext(NostrContext); | ||
|
||
if (!nostr) { | ||
throw new Error('NostrContext must be used within a NostrProvider'); | ||
} | ||
|
||
return nostr; | ||
}; |
Oops, something went wrong.