From b0b9a391a40f22cdc3a2c543f7999cb69de67ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=20Daniel=20=E2=9A=A1=EF=B8=8F?= Date: Tue, 4 Nov 2025 21:15:21 -0500 Subject: [PATCH] feat: display invoice memo in Lightning invoice cards (#643) Co-authored-by: The Daniel --- src/components/Embedded/EmbeddedLNInvoice.tsx | 9 ++++++--- src/lib/lightning.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Embedded/EmbeddedLNInvoice.tsx b/src/components/Embedded/EmbeddedLNInvoice.tsx index 376606f..bbc959f 100644 --- a/src/components/Embedded/EmbeddedLNInvoice.tsx +++ b/src/components/Embedded/EmbeddedLNInvoice.tsx @@ -1,5 +1,5 @@ import { Button } from '@/components/ui/button' -import { formatAmount, getAmountFromInvoice } from '@/lib/lightning' +import { formatAmount, getInvoiceDetails } from '@/lib/lightning' import { cn } from '@/lib/utils' import { useNostr } from '@/providers/NostrProvider' import lightning from '@/services/lightning.service' @@ -13,8 +13,8 @@ export function EmbeddedLNInvoice({ invoice, className }: { invoice: string; cla const { checkLogin, pubkey } = useNostr() const [paying, setPaying] = useState(false) - const amount = useMemo(() => { - return getAmountFromInvoice(invoice) + const { amount, description } = useMemo(() => { + return getInvoiceDetails(invoice) }, [invoice]) const handlePay = async () => { @@ -49,6 +49,9 @@ export function EmbeddedLNInvoice({ invoice, className }: { invoice: string; cla
{t('Lightning Invoice')}
+ {description && ( +
{description}
+ )}
{formatAmount(amount)} {t('sats')}
diff --git a/src/lib/lightning.ts b/src/lib/lightning.ts index 94b5d95..f5d29d7 100644 --- a/src/lib/lightning.ts +++ b/src/lib/lightning.ts @@ -7,6 +7,14 @@ export function getAmountFromInvoice(invoice: string): number { return _invoice.satoshi } +export function getInvoiceDetails(invoice: string): { amount: number; description: string | null } { + const _invoice = new Invoice({ pr: invoice }) // TODO: need to validate + return { + amount: _invoice.satoshi, + description: _invoice.description, + } +} + export function formatAmount(amount: number) { if (amount < 1000) return amount if (amount < 1000000) return `${Math.round(amount / 100) / 10}k`