Skip to content

Commit

Permalink
Merge pull request #15 from ostyjs/update-nostr-hooks
Browse files Browse the repository at this point in the history
Update nostr hooks
  • Loading branch information
sepehr-safari authored Dec 2, 2024
2 parents e11af41 + fac8c80 commit 9d92255
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-osty",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"license": "MIT",
"author": "Sepehr Safari",
Expand Down
2 changes: 1 addition & 1 deletion templates/react-shadcn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"embla-carousel-react": "^8.4.0",
"lucide-react": "^0.460.0",
"next-themes": "^0.4.3",
"nostr-hooks": "^3.0.0",
"nostr-hooks": "^4.1.6",
"nostr-tools": "^2.10.3",
"react": "^18.3.1",
"react-day-picker": "^9.3.2",
Expand Down
8 changes: 4 additions & 4 deletions templates/react-shadcn/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLogin, useNdk } from 'nostr-hooks';
import { useEffect } from 'react';
import { RouterProvider } from 'react-router-dom';

Expand All @@ -8,13 +9,12 @@ import { router } from '@/pages';
import { ThemeProvider } from '@/shared/components/theme-provider';
import { Toaster } from '@/shared/components/ui/toaster';

import { useNdk } from '@/shared/hooks';

export const App = () => {
const { initNdk, ndk, loginFromLocalStorage } = useNdk();
const { initNdk, ndk } = useNdk();
const { loginFromLocalStorage } = useLogin();

useEffect(() => {
initNdk({ explicitRelayUrls: ['wss://nos.lol'] });
initNdk({ explicitRelayUrls: ['wss://nos.lol', 'wss://relay.primal.net'] });
}, [initNdk]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { useLogin } from 'nostr-hooks';
import { nsecEncode } from 'nostr-tools/nip19';
import { generateSecretKey } from 'nostr-tools/pure';
import { useState } from 'react';

import { useToast } from '@/shared/components/ui/use-toast';

import { useNdk } from '@/shared/hooks';

export const useLoginWidget = () => {
const [nip46Input, setNip46Input] = useState('');
const [nsecInput, setNsecInput] = useState('');
const [loading, setLoading] = useState(false);

const [isModalOpen, setIsModalOpen] = useState(false);

const { loginWithExtension, loginWithRemoteSigner, loginWithPrivateKey } = useNdk();
const { loginWithExtension, loginWithRemoteSigner, loginWithPrivateKey } = useLogin();

const { toast } = useToast();

Expand Down
6 changes: 3 additions & 3 deletions templates/react-shadcn/src/features/logout-widget/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Button } from '@/shared/components/ui/button';
import { useLogin } from 'nostr-hooks';

import { useNdk } from '@/shared/hooks';
import { Button } from '@/shared/components/ui/button';

export const LogoutWidget = () => {
const { logout } = useNdk();
const { logout } = useLogin();

return <Button onClick={() => logout()}>Logout</Button>;
};
6 changes: 2 additions & 4 deletions templates/react-shadcn/src/features/zap-widget/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { NDKEvent, NDKTag, NDKUser } from '@nostr-dev-kit/ndk';
import { useProfile } from 'nostr-hooks';
import { useNdk, useProfile } from 'nostr-hooks';
import { useState } from 'react';

import { useToast } from '@/shared/components/ui/use-toast';

import { useNdk } from '@/shared/hooks';

import { ZAP_AMOUNTS } from '../config';
import { payInvoiceByWebln } from '../utils';

Expand All @@ -19,7 +17,7 @@ export const useZapWidget = (target: NDKEvent | NDKUser | undefined) => {

const { ndk } = useNdk();

const { profile } = useProfile(ndk, { pubkey: target?.pubkey });
const { profile } = useProfile({ pubkey: target?.pubkey });

const process = () => {
if (!target || !ndk) return;
Expand Down
6 changes: 2 additions & 4 deletions templates/react-shadcn/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitHubLogoIcon } from '@radix-ui/react-icons';
import { useActiveUser } from 'nostr-hooks';
import { useActiveUser, useNdk } from 'nostr-hooks';

import { ModeToggle } from '@/shared/components/mode-toggle';
import { Button } from '@/shared/components/ui/button';
Expand All @@ -17,11 +17,9 @@ import { LoginWidget } from '@/features/login-widget';
import { LogoutWidget } from '@/features/logout-widget';
import { ZapWidget } from '@/features/zap-widget';

import { useNdk } from '@/shared/hooks';

export const HomePage = () => {
const { ndk } = useNdk();
const { activeUser } = useActiveUser(ndk);
const { activeUser } = useActiveUser();

const zapTarget = ndk?.getUser({
pubkey: '3e294d2fd339bb16a5403a86e3664947dd408c4d87a0066524f8a573ae53ca8e', // Sep
Expand Down
1 change: 0 additions & 1 deletion templates/react-shadcn/src/shared/hooks/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions templates/react-shadcn/src/shared/hooks/use-ndk/index.ts

This file was deleted.

0 comments on commit 9d92255

Please sign in to comment.