feat: display invoice memo in Lightning invoice cards (#643)

Co-authored-by: The Daniel <dmnyc@users.noreply.github.com>
This commit is contained in:
The Daniel ⚡️ 2025-11-04 21:15:21 -05:00 committed by GitHub
parent 0eb0be4780
commit b0b9a391a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View file

@ -1,5 +1,5 @@
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { formatAmount, getAmountFromInvoice } from '@/lib/lightning' import { formatAmount, getInvoiceDetails } from '@/lib/lightning'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { useNostr } from '@/providers/NostrProvider' import { useNostr } from '@/providers/NostrProvider'
import lightning from '@/services/lightning.service' import lightning from '@/services/lightning.service'
@ -13,8 +13,8 @@ export function EmbeddedLNInvoice({ invoice, className }: { invoice: string; cla
const { checkLogin, pubkey } = useNostr() const { checkLogin, pubkey } = useNostr()
const [paying, setPaying] = useState(false) const [paying, setPaying] = useState(false)
const amount = useMemo(() => { const { amount, description } = useMemo(() => {
return getAmountFromInvoice(invoice) return getInvoiceDetails(invoice)
}, [invoice]) }, [invoice])
const handlePay = async () => { const handlePay = async () => {
@ -49,6 +49,9 @@ export function EmbeddedLNInvoice({ invoice, className }: { invoice: string; cla
<Zap className="w-5 h-5 text-yellow-400" /> <Zap className="w-5 h-5 text-yellow-400" />
<div className="font-semibold text-sm">{t('Lightning Invoice')}</div> <div className="font-semibold text-sm">{t('Lightning Invoice')}</div>
</div> </div>
{description && (
<div className="text-sm text-muted-foreground break-words">{description}</div>
)}
<div className="text-lg font-bold"> <div className="text-lg font-bold">
{formatAmount(amount)} {t('sats')} {formatAmount(amount)} {t('sats')}
</div> </div>

View file

@ -7,6 +7,14 @@ export function getAmountFromInvoice(invoice: string): number {
return _invoice.satoshi 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) { export function formatAmount(amount: number) {
if (amount < 1000) return amount if (amount < 1000) return amount
if (amount < 1000000) return `${Math.round(amount / 100) / 10}k` if (amount < 1000000) return `${Math.round(amount / 100) / 10}k`