From e024c3725d73bd6a2de104ca484873374bbc6adc Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Mon, 1 Dec 2025 18:17:07 +0530 Subject: [PATCH] add signer required and signer permissions dialogs --- src/components/NostrPermissionDialog.tsx | 67 +++++++++++++++++++ src/components/NostrSignerRequiredDialog.tsx | 65 ++++++++++++++++++ src/components/Shakespeare/PreviewPane.tsx | 69 +++++++++++++++++++- 3 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 src/components/NostrPermissionDialog.tsx create mode 100644 src/components/NostrSignerRequiredDialog.tsx diff --git a/src/components/NostrPermissionDialog.tsx b/src/components/NostrPermissionDialog.tsx new file mode 100644 index 00000000..950bfd48 --- /dev/null +++ b/src/components/NostrPermissionDialog.tsx @@ -0,0 +1,67 @@ +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { + Alert, + AlertDescription, + AlertTitle, +} from '@/components/ui/alert'; +import { Button } from '@/components/ui/button'; + +interface NostrPermissionDialogProps { + open: boolean; + onResponse: (granted: boolean) => void; +} + +export function NostrPermissionDialog({ open, onResponse }: NostrPermissionDialogProps) { + return ( + { + if (!isOpen) { + onResponse(false); + } + }}> + + + Allow Nostr Access? + +

+ This project is requesting access to your Nostr signer (window.nostr). +

+ + Warning + + Granting access will allow this app to take actions on your behalf, including: +
    +
  • Read your public key
  • +
  • Sign events (publish posts, reactions, etc.)
  • +
  • Encrypt and decrypt messages
  • +
+
+
+

+ Only grant access if you trust this application. +

+
+
+ + + + +
+
+ ); +} diff --git a/src/components/NostrSignerRequiredDialog.tsx b/src/components/NostrSignerRequiredDialog.tsx new file mode 100644 index 00000000..d7c74d9c --- /dev/null +++ b/src/components/NostrSignerRequiredDialog.tsx @@ -0,0 +1,65 @@ +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; + +interface NostrSignerRequiredDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; +} + +export function NostrSignerRequiredDialog({ open, onOpenChange }: NostrSignerRequiredDialogProps) { + return ( + + + + Nostr Signer Required + +

+ This page tried to use a NIP-07 signer, but you don't have one installed! +

+

+ Please install a Nostr signer extension to continue: +

+ +
+
+ + + +
+
+ ); +} diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 780b9da5..66e643e4 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -26,6 +26,8 @@ import { PopoverContent, PopoverTrigger, } from '@/components/ui/popover'; +import { NostrPermissionDialog } from '@/components/NostrPermissionDialog'; +import { NostrSignerRequiredDialog } from '@/components/NostrSignerRequiredDialog'; import { cn } from '@/lib/utils'; import { FileTree } from './FileTree'; import { FileEditor } from './FileEditor'; @@ -331,6 +333,46 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o } }, [historyIndex, navigationHistory, sendNavigationCommand]); + // Track which projects have been granted Nostr access + const [nostrPermissions, setNostrPermissions] = useState>(new Set()); + const [nostrPermissionDialog, setNostrPermissionDialog] = useState<{ + open: boolean; + projectId: string; + resolve: (granted: boolean) => void; + } | null>(null); + const [noSignerDialog, setNoSignerDialog] = useState(false); + + const requestNostrPermission = useCallback(async (projectId: string): Promise => { + // Check if permission already granted + if (nostrPermissions.has(projectId)) { + return true; + } + + // Show permission dialog and wait for user response + return new Promise((resolve) => { + setNostrPermissionDialog({ + open: true, + projectId, + resolve, + }); + }); + }, [nostrPermissions]); + + const handleNostrPermissionResponse = useCallback((granted: boolean) => { + if (nostrPermissionDialog) { + const { projectId, resolve } = nostrPermissionDialog; + + if (granted) { + // Grant permission for this project + setNostrPermissions(prev => new Set([...prev, projectId])); + } + + // Close dialog and resolve the promise + setNostrPermissionDialog(null); + resolve(granted); + } + }, [nostrPermissionDialog]); + const handleNostr = useCallback(async (request: NostrRPCRequest) => { const { params, id } = request; const { method, args } = params; @@ -338,9 +380,18 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o console.log('[NOSTR BRIDGE] Handling request:', method, args); try { - // Check if user is logged in + // Check if user is logged in with a signer if (!user?.signer) { - throw new Error('No Nostr signer available. Please log in with a Nostr extension.'); + // Show the "no signer" dialog + setNoSignerDialog(true); + throw new Error('NO_SIGNER_INSTALLED'); + } + + // Request permission if this is the first Nostr access from this project + const hasPermission = await requestNostrPermission(projectId); + + if (!hasPermission) { + throw new Error('User denied Nostr access'); } let result: unknown; @@ -429,7 +480,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o }, targetOrigin); } } - }, [user, projectId, previewDomain]); + }, [user, projectId, previewDomain, requestNostrPermission]); const handleFetch = useCallback(async (request: JSONRPCRequest) => { const { params, id } = request; @@ -1062,6 +1113,18 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o onOpenChange={setDeployDialogOpen} /> )} + + {/* Nostr Permission Dialog */} + + + {/* No Signer Installed Dialog */} + ); }