From 16b4bdb602ffad75e485d85a85f547946a9e2339 Mon Sep 17 00:00:00 2001 From: highperfocused Date: Sun, 5 Oct 2025 19:53:42 +0200 Subject: [PATCH] Add copy button for npub in ProfilePage with toast notifications --- src/pages/ProfilePage.tsx | 50 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 9832bb0..6b1faaf 100644 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -6,13 +6,18 @@ import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { Badge } from '@/components/ui/badge'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; -import { Calendar, Link2, Mail } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Calendar, Link2, Mail, Copy, Check } from 'lucide-react'; import { genUserName } from '@/lib/genUserName'; import { RelaySelector } from '@/components/RelaySelector'; +import { useToast } from '@/hooks/useToast'; import NotFound from '@/pages/NotFound'; +import { useState } from 'react'; export default function ProfilePage() { const { nip19: npub } = useParams<{ nip19: string }>(); + const { toast } = useToast(); + const [copied, setCopied] = useState(false); // Decode npub/nprofile to get pubkey let pubkey = ''; @@ -48,6 +53,27 @@ export default function ProfilePage() { const website = metadata?.website; const nip05 = metadata?.nip05; + // Generate npub for copy button + const userNpub = pubkey ? nip19.npubEncode(pubkey) : ''; + + const handleCopyNpub = async () => { + try { + await navigator.clipboard.writeText(userNpub); + setCopied(true); + toast({ + title: "Copied!", + description: "npub copied to clipboard", + }); + setTimeout(() => setCopied(false), 2000); + } catch { + toast({ + title: "Failed to copy", + description: "Could not copy npub to clipboard", + variant: "destructive", + }); + } + }; + // If not a valid profile identifier, show 404 if (!isValidProfile || !pubkey) { return ; @@ -127,7 +153,27 @@ export default function ProfilePage() { {/* User Info */}
-

{displayName}

+
+

{displayName}

+ +
{metadata?.name && metadata.name !== displayName && (

@{userName}

)}