7 changed files with 72 additions and 31 deletions
@ -0,0 +1,27 @@ |
|||||||
|
import { formatNpub } from '@renderer/lib/pubkey' |
||||||
|
import { Check, Copy } from 'lucide-react' |
||||||
|
import { nip19 } from 'nostr-tools' |
||||||
|
import { useMemo, useState } from 'react' |
||||||
|
|
||||||
|
export default function PubkeyCopy({ pubkey }: { pubkey: string }) { |
||||||
|
const npub = useMemo(() => (pubkey ? nip19.npubEncode(pubkey) : ''), [pubkey]) |
||||||
|
const [copied, setCopied] = useState(false) |
||||||
|
|
||||||
|
const copyNpub = () => { |
||||||
|
if (!npub) return |
||||||
|
|
||||||
|
navigator.clipboard.writeText(npub) |
||||||
|
setCopied(true) |
||||||
|
setTimeout(() => setCopied(false), 2000) |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<div |
||||||
|
className="flex gap-2 text-sm text-muted-foreground items-center bg-muted w-fit px-2 rounded-full hover:text-foreground cursor-pointer" |
||||||
|
onClick={() => copyNpub()} |
||||||
|
> |
||||||
|
<div>{formatNpub(npub, 24)}</div> |
||||||
|
{copied ? <Check size={14} /> : <Copy size={14} />} |
||||||
|
</div> |
||||||
|
) |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@renderer/components/ui/popover' |
||||||
|
import { QrCode } from 'lucide-react' |
||||||
|
import { nip19 } from 'nostr-tools' |
||||||
|
import { useMemo } from 'react' |
||||||
|
import { QRCodeSVG } from 'qrcode.react' |
||||||
|
|
||||||
|
export default function QrCodePopover({ pubkey }: { pubkey: string }) { |
||||||
|
const npub = useMemo(() => (pubkey ? nip19.npubEncode(pubkey) : ''), [pubkey]) |
||||||
|
if (!npub) return null |
||||||
|
|
||||||
|
return ( |
||||||
|
<Popover> |
||||||
|
<PopoverTrigger> |
||||||
|
<div className="bg-muted rounded-full h-5 w-5 flex flex-col items-center justify-center text-muted-foreground hover:text-foreground"> |
||||||
|
<QrCode size={14} /> |
||||||
|
</div> |
||||||
|
</PopoverTrigger> |
||||||
|
<PopoverContent className="w-fit h-fit"> |
||||||
|
<QRCodeSVG value={`nostr:${npub}`} /> |
||||||
|
</PopoverContent> |
||||||
|
</Popover> |
||||||
|
) |
||||||
|
} |
||||||
Loading…
Reference in new issue