mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
add signer required and signer permissions dialogs
This commit is contained in:
3 files changed
+198
-3
No files matched your search
@@ -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 (
|
||||
<Dialog open={open} onOpenChange={(isOpen) => {
|
||||
if (!isOpen) {
|
||||
onResponse(false);
|
||||
}
|
||||
}}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Allow Nostr Access?</DialogTitle>
|
||||
<DialogDescription className="space-y-3">
|
||||
<p>
|
||||
This project is requesting access to your Nostr signer (window.nostr).
|
||||
</p>
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>Warning</AlertTitle>
|
||||
<AlertDescription>
|
||||
Granting access will allow this app to take actions on your behalf, including:
|
||||
<ul className="list-disc list-inside mt-2 space-y-1">
|
||||
<li>Read your public key</li>
|
||||
<li>Sign events (publish posts, reactions, etc.)</li>
|
||||
<li>Encrypt and decrypt messages</li>
|
||||
</ul>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Only grant access if you trust this application.
|
||||
</p>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter className="gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onResponse(false)}
|
||||
>
|
||||
Deny
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => onResponse(true)}
|
||||
>
|
||||
Allow
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Nostr Signer Required</DialogTitle>
|
||||
<DialogDescription className="space-y-3">
|
||||
<p>
|
||||
This page tried to use a NIP-07 signer, but you don't have one installed!
|
||||
</p>
|
||||
<p>
|
||||
Please install a Nostr signer extension to continue:
|
||||
</p>
|
||||
<div className="space-y-2 mt-4">
|
||||
<a
|
||||
href="https://github.com/soapbox-pub/soapbox-signer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block text-primary hover:underline"
|
||||
>
|
||||
• Soapbox Signer
|
||||
</a>
|
||||
<a
|
||||
href="https://getalby.com/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block text-primary hover:underline"
|
||||
>
|
||||
• Alby
|
||||
</a>
|
||||
<a
|
||||
href="https://github.com/fiatjaf/nos2x"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block text-primary hover:underline"
|
||||
>
|
||||
• nos2x
|
||||
</a>
|
||||
</div>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Close
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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<Set<string>>(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<boolean> => {
|
||||
// Check if permission already granted
|
||||
if (nostrPermissions.has(projectId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Show permission dialog and wait for user response
|
||||
return new Promise<boolean>((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 */}
|
||||
<NostrPermissionDialog
|
||||
open={nostrPermissionDialog?.open ?? false}
|
||||
onResponse={handleNostrPermissionResponse}
|
||||
/>
|
||||
|
||||
{/* No Signer Installed Dialog */}
|
||||
<NostrSignerRequiredDialog
|
||||
open={noSignerDialog}
|
||||
onOpenChange={setNoSignerDialog}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user