index.tsx raw
1 import { Pubkey } from '@/domain'
2 import { Check, Copy } from 'lucide-react'
3 import { useMemo, useState } from 'react'
4
5 export default function PubkeyCopy({ pubkey }: { pubkey: string }) {
6 const pk = useMemo(() => Pubkey.tryFromString(pubkey), [pubkey])
7 const npub = pk?.npub ?? ''
8 const [copied, setCopied] = useState(false)
9
10 const copyNpub = () => {
11 if (!npub) return
12
13 navigator.clipboard.writeText(npub)
14 setCopied(true)
15 setTimeout(() => setCopied(false), 2000)
16 }
17
18 return (
19 <div
20 className="flex gap-2 text-sm text-muted-foreground items-center bg-muted w-fit px-2 rounded-full clickable"
21 onClick={() => copyNpub()}
22 >
23 <div>{pk?.formatNpub(24) ?? npub}</div>
24 {copied ? <Check size={14} /> : <Copy size={14} />}
25 </div>
26 )
27 }
28