mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
add NWC settings page for zaps
This commit is contained in:
1 parent
4676738a14
commit
67a77419df
6 files changed
+314
-8
No files matched your search
@@ -28,6 +28,7 @@ import { DynamicFavicon } from '@/components/DynamicFavicon';
|
||||
import { OfflineIndicator } from '@/components/OfflineIndicator';
|
||||
import { PWAUpdatePrompt } from '@/components/PWAUpdatePrompt';
|
||||
import { ErrorBoundary } from '@/components/ErrorBoundary';
|
||||
import { NWCProvider } from '@/contexts/NWCContext';
|
||||
|
||||
import AppRouter from './AppRouter';
|
||||
|
||||
@@ -142,6 +143,7 @@ export function App() {
|
||||
<NostrLoginProvider storageKey='nostr:login'>
|
||||
<NostrProvider>
|
||||
<NostrSync />
|
||||
<NWCProvider>
|
||||
<AISettingsProvider>
|
||||
<GitSettingsProvider>
|
||||
<DeploySettingsProvider>
|
||||
@@ -161,6 +163,7 @@ export function App() {
|
||||
</DeploySettingsProvider>
|
||||
</GitSettingsProvider>
|
||||
</AISettingsProvider>
|
||||
</NWCProvider>
|
||||
</NostrProvider>
|
||||
</NostrLoginProvider>
|
||||
</ConsoleErrorProvider>
|
||||
|
||||
@@ -11,6 +11,7 @@ import NostrSettings from "./pages/NostrSettings";
|
||||
import AISettings from "./pages/AISettings";
|
||||
import GitSettings from "./pages/GitSettings";
|
||||
import DeploySettings from "./pages/DeploySettings";
|
||||
import WalletSettings from "./pages/WalletSettings";
|
||||
import SystemSettings from "./pages/SystemSettings";
|
||||
import StorageSettings from "./pages/StorageSettings";
|
||||
import AboutSettings from "./pages/AboutSettings";
|
||||
@@ -48,6 +49,7 @@ export function AppRouter() {
|
||||
<Route path="ai" element={<AISettings />} />
|
||||
<Route path="git" element={<GitSettings />} />
|
||||
<Route path="deploy" element={<DeploySettings />} />
|
||||
<Route path="wallet" element={<WalletSettings />} />
|
||||
<Route path="system" element={<SystemSettings />} />
|
||||
<Route path="storage" element={<StorageSettings />} />
|
||||
<Route path="about" element={<AboutSettings />} />
|
||||
|
||||
@@ -31,6 +31,9 @@ import { detectFork } from '@/lib/detectFork';
|
||||
import { NostrRepoEditDialog } from '@/components/NostrRepoEditDialog';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useOGImage } from '@/hooks/useOGImage';
|
||||
import { ZapDialog } from '@/components/ZapDialog';
|
||||
import { Zap } from 'lucide-react';
|
||||
import type { Event } from 'nostr-tools';
|
||||
|
||||
interface RepositoryCardProps {
|
||||
repo: Repository;
|
||||
@@ -53,6 +56,8 @@ export function RepositoryCard({ repo }: RepositoryCardProps) {
|
||||
const displayName = authorData?.metadata?.name || genUserName(repo.pubkey);
|
||||
const profileImage = authorData?.metadata?.picture;
|
||||
const isOwnRepo = user?.pubkey === repo.pubkey;
|
||||
const hasLightning = !!(authorData?.metadata?.lud16 || authorData?.metadata?.lud06);
|
||||
const canZap = user && !isOwnRepo && hasLightning;
|
||||
|
||||
// Get OG metadata from first web URL
|
||||
const firstWebUrl = repo.webUrls?.[0];
|
||||
@@ -158,12 +163,20 @@ export function RepositoryCard({ repo }: RepositoryCardProps) {
|
||||
{repo.name}
|
||||
</h3>
|
||||
</div>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 -mt-1 -mr-2 shrink-0">
|
||||
<EllipsisVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<div className="flex items-center -mt-1 -mr-2 shrink-0">
|
||||
{canZap && (
|
||||
<ZapDialog target={repo as unknown as Event}>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8 text-amber-500 hover:text-amber-600 hover:bg-amber-500/10">
|
||||
<Zap className="h-4 w-4" />
|
||||
</Button>
|
||||
</ZapDialog>
|
||||
)}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<EllipsisVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{firstWebUrl && (
|
||||
<DropdownMenuItem asChild className="gap-2">
|
||||
@@ -187,7 +200,8 @@ export function RepositoryCard({ repo }: RepositoryCardProps) {
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Author */}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Settings, Rocket } from 'lucide-react';
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Settings, Rocket, Wallet } from 'lucide-react';
|
||||
|
||||
export interface SettingsItem {
|
||||
id: string;
|
||||
@@ -59,6 +59,12 @@ export const getSettingsCategories = (t: (key: string) => string): SettingsCateg
|
||||
title: t('nostrSettings'),
|
||||
href: '/settings/nostr',
|
||||
},
|
||||
{
|
||||
id: 'wallet',
|
||||
icon: Wallet,
|
||||
title: t('walletSettings'),
|
||||
href: '/settings/wallet',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -106,6 +106,33 @@
|
||||
"deploySettingsDescription": "Configure deployment providers",
|
||||
"nostrSettings": "Nostr",
|
||||
"nostrSettingsDescription": "Configure relay connections and Nostr preferences",
|
||||
"walletSettings": "Wallet",
|
||||
"walletSettingsDescription": "Connect Lightning wallets for zaps",
|
||||
"currentStatus": "Current Status",
|
||||
"browserExtension": "Browser extension",
|
||||
"ready": "Ready",
|
||||
"notFound": "Not Found",
|
||||
"nostrWalletConnect": "Nostr Wallet Connect",
|
||||
"walletsConnected": "{{count}} wallet(s) connected",
|
||||
"remoteWalletConnection": "Remote wallet connection",
|
||||
"none": "None",
|
||||
"noWalletsConnected": "No wallets connected",
|
||||
"addNwcWalletToGetStarted": "Add an NWC wallet to get started",
|
||||
"lightningWallet": "Lightning Wallet",
|
||||
"nwcConnection": "NWC Connection",
|
||||
"setAsActive": "Set as active",
|
||||
"activeWalletChanged": "Active wallet changed",
|
||||
"selectedWalletNowActive": "The selected wallet is now active for zaps.",
|
||||
"installWeblnOrConnectNwc": "Install a WebLN extension or connect an NWC wallet to send zaps.",
|
||||
"connectNwcWallet": "Connect NWC Wallet",
|
||||
"enterConnectionStringFromWallet": "Enter your connection string from a compatible wallet.",
|
||||
"walletNameOptional": "Wallet Name (optional)",
|
||||
"myLightningWallet": "My Lightning Wallet",
|
||||
"connectionUri": "Connection URI",
|
||||
"connecting": "Connecting...",
|
||||
"connect": "Connect",
|
||||
"connectionUriRequired": "Connection URI required",
|
||||
"pleaseEnterValidNwcUri": "Please enter a valid NWC connection URI.",
|
||||
"storageSettings": "Storage",
|
||||
"storageSettingsDescription": "Export files and manage local data",
|
||||
"emailUpdates": "Email Updates",
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Wallet, Plus, Trash2, Zap, Globe, WalletMinimal, CheckCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useNWC } from '@/hooks/useNWCContext';
|
||||
import { useWallet } from '@/hooks/useWallet';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { SettingsPageLayout } from '@/components/SettingsPageLayout';
|
||||
|
||||
export function WalletSettings() {
|
||||
const { t } = useTranslation();
|
||||
const [addDialogOpen, setAddDialogOpen] = useState(false);
|
||||
const [connectionUri, setConnectionUri] = useState('');
|
||||
const [alias, setAlias] = useState('');
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const { toast } = useToast();
|
||||
|
||||
const {
|
||||
connections,
|
||||
activeConnection,
|
||||
connectionInfo,
|
||||
addConnection,
|
||||
removeConnection,
|
||||
setActiveConnection
|
||||
} = useNWC();
|
||||
|
||||
const { webln } = useWallet();
|
||||
|
||||
const hasNWC = connections.length > 0 && connections.some(c => c.isConnected);
|
||||
|
||||
const handleAddConnection = async () => {
|
||||
if (!connectionUri.trim()) {
|
||||
toast({
|
||||
title: t('connectionUriRequired'),
|
||||
description: t('pleaseEnterValidNwcUri'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setIsConnecting(true);
|
||||
try {
|
||||
const success = await addConnection(connectionUri.trim(), alias.trim() || undefined);
|
||||
if (success) {
|
||||
setConnectionUri('');
|
||||
setAlias('');
|
||||
setAddDialogOpen(false);
|
||||
}
|
||||
} finally {
|
||||
setIsConnecting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveConnection = (connectionString: string) => {
|
||||
removeConnection(connectionString);
|
||||
};
|
||||
|
||||
const handleSetActive = (connectionString: string) => {
|
||||
setActiveConnection(connectionString);
|
||||
toast({
|
||||
title: t('activeWalletChanged'),
|
||||
description: t('selectedWalletNowActive'),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsPageLayout
|
||||
icon={Wallet}
|
||||
titleKey="walletSettings"
|
||||
descriptionKey="walletSettingsDescription"
|
||||
>
|
||||
{/* Current Status */}
|
||||
<div className="space-y-3">
|
||||
<h3 className="font-medium">{t('currentStatus')}</h3>
|
||||
<div className="grid gap-3">
|
||||
{/* WebLN */}
|
||||
<div className="flex items-center justify-between p-3 border rounded-lg">
|
||||
<div className="flex items-center gap-3">
|
||||
<Globe className="h-4 w-4 text-muted-foreground" />
|
||||
<div>
|
||||
<p className="text-sm font-medium">WebLN</p>
|
||||
<p className="text-xs text-muted-foreground">{t('browserExtension')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{webln && <CheckCircle className="h-4 w-4 text-green-600" />}
|
||||
<Badge variant={webln ? "default" : "secondary"} className="text-xs">
|
||||
{webln ? t('ready') : t('notFound')}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
{/* NWC */}
|
||||
<div className="flex items-center justify-between p-3 border rounded-lg">
|
||||
<div className="flex items-center gap-3">
|
||||
<WalletMinimal className="h-4 w-4 text-muted-foreground" />
|
||||
<div>
|
||||
<p className="text-sm font-medium">{t('nostrWalletConnect')}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{connections.length > 0
|
||||
? t('walletsConnected', { count: connections.length })
|
||||
: t('remoteWalletConnection')
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{hasNWC && <CheckCircle className="h-4 w-4 text-green-600" />}
|
||||
<Badge variant={hasNWC ? "default" : "secondary"} className="text-xs">
|
||||
{hasNWC ? t('ready') : t('none')}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* NWC Management */}
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="font-medium">{t('nostrWalletConnect')}</h3>
|
||||
<Button size="sm" variant="outline" onClick={() => setAddDialogOpen(true)}>
|
||||
<Plus className="h-4 w-4 mr-1" />
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Connected Wallets List */}
|
||||
{connections.length === 0 ? (
|
||||
<div className="text-center py-6 text-muted-foreground border border-dashed rounded-lg">
|
||||
<WalletMinimal className="h-8 w-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">{t('noWalletsConnected')}</p>
|
||||
<p className="text-xs mt-1">{t('addNwcWalletToGetStarted')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{connections.map((connection) => {
|
||||
const info = connectionInfo[connection.connectionString];
|
||||
const isActive = activeConnection === connection.connectionString;
|
||||
return (
|
||||
<div
|
||||
key={connection.connectionString}
|
||||
className={`flex items-center justify-between p-3 border rounded-lg ${isActive ? 'ring-2 ring-primary' : ''}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<WalletMinimal className="h-4 w-4 text-muted-foreground" />
|
||||
<div>
|
||||
<p className="text-sm font-medium">
|
||||
{connection.alias || info?.alias || t('lightningWallet')}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('nwcConnection')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{isActive && <CheckCircle className="h-4 w-4 text-green-600" />}
|
||||
{!isActive && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleSetActive(connection.connectionString)}
|
||||
title={t('setAsActive')}
|
||||
>
|
||||
<Zap className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleRemoveConnection(connection.connectionString)}
|
||||
title={t('remove')}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Help */}
|
||||
{!webln && connections.length === 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<div className="text-center py-4 space-y-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('installWeblnOrConnectNwc')}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Add Wallet Dialog */}
|
||||
<Dialog open={addDialogOpen} onOpenChange={setAddDialogOpen}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('connectNwcWallet')}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t('enterConnectionStringFromWallet')}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div>
|
||||
<Label htmlFor="alias">{t('walletNameOptional')}</Label>
|
||||
<Input
|
||||
id="alias"
|
||||
placeholder={t('myLightningWallet')}
|
||||
value={alias}
|
||||
onChange={(e) => setAlias(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="connection-uri">{t('connectionUri')}</Label>
|
||||
<Textarea
|
||||
id="connection-uri"
|
||||
placeholder="nostr+walletconnect://..."
|
||||
value={connectionUri}
|
||||
onChange={(e) => setConnectionUri(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
onClick={handleAddConnection}
|
||||
disabled={isConnecting || !connectionUri.trim()}
|
||||
className="w-full"
|
||||
>
|
||||
{isConnecting ? t('connecting') : t('connect')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</SettingsPageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export default WalletSettings;
|
||||
Reference in new issue
Block a user