From 9b785618f6be4816d6fdd611e56d20c76fb61650 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Wed, 20 May 2026 19:50:28 +0200 Subject: [PATCH] lightning bug-fixes --- .../PaymentMethodsSection/index.tsx | 4 ++ .../PaytoDialog/LightningInvoiceSection.tsx | 40 ++++++++++++---- src/components/PaytoDialog/index.tsx | 6 ++- src/components/PaytoLink/index.tsx | 4 ++ src/components/ZapDialog/index.tsx | 23 ++++++--- src/i18n/locales/en.ts | 2 + src/lib/lnurl-pay.test.ts | 41 ++++++++++++++++ src/lib/lnurl-pay.ts | 31 ++++++++++++ .../WalletPage/WalletZapSendingSettings.tsx | 11 +++-- src/services/lightning.service.ts | 48 ++++++++++++++----- 10 files changed, 177 insertions(+), 33 deletions(-) create mode 100644 src/lib/lnurl-pay.test.ts create mode 100644 src/lib/lnurl-pay.ts diff --git a/src/components/PaymentMethodsSection/index.tsx b/src/components/PaymentMethodsSection/index.tsx index 789f8bcf..51073b26 100644 --- a/src/components/PaymentMethodsSection/index.tsx +++ b/src/components/PaymentMethodsSection/index.tsx @@ -11,6 +11,7 @@ export default function PaymentMethodsSection({ groups, recipientPubkey, onOpenZap, + offerTipNoticeOnClose = true, title, className, headerHelpText @@ -19,6 +20,8 @@ export default function PaymentMethodsSection({ recipientPubkey?: string /** When set, lightning rows open the zap flow with that address as the default. */ onOpenZap?: (lightningAuthority: string) => void + /** When false, PaytoDialog defer tip notice to parent (e.g. ZapDialog). */ + offerTipNoticeOnClose?: boolean title?: string className?: string /** Prominent note above the list (e.g. on-chain Bitcoin eligibility in zap dialog). */ @@ -67,6 +70,7 @@ export default function PaymentMethodsSection({ ? (_pk, authority) => onOpenZap(authority) : undefined } + offerTipNoticeOnClose={offerTipNoticeOnClose} className={cn(PRIMARY_LINK_HOVER_CLASS, 'break-all min-w-0 flex-1')} > {method.authority} diff --git a/src/components/PaytoDialog/LightningInvoiceSection.tsx b/src/components/PaytoDialog/LightningInvoiceSection.tsx index 67637fdc..ed862cfd 100644 --- a/src/components/PaytoDialog/LightningInvoiceSection.tsx +++ b/src/components/PaytoDialog/LightningInvoiceSection.tsx @@ -36,10 +36,13 @@ export default function LightningInvoiceSection({ paytoUri: string }) { const { t } = useTranslation() - const { defaultZapSats, defaultZapComment, isWalletConnected } = useZap() + const { defaultZapSats, isWalletConnected } = useZap() const [sats, setSats] = useState(() => clampZapSats(defaultZapSats)) - const [description, setDescription] = useState(defaultZapComment) + const [description, setDescription] = useState('') const [commentMax, setCommentMax] = useState(null) + const [lnurlMetadataState, setLnurlMetadataState] = useState<'loading' | 'ready' | 'error'>( + 'loading' + ) const [invoice, setInvoice] = useState(null) const [invoiceDescription, setInvoiceDescription] = useState(null) const [creating, setCreating] = useState(false) @@ -47,18 +50,27 @@ export default function LightningInvoiceSection({ useEffect(() => { setSats(clampZapSats(defaultZapSats)) - setDescription(defaultZapComment) + setDescription('') setInvoice(null) setInvoiceDescription(null) setCommentMax(null) + setLnurlMetadataState('loading') let cancelled = false void lightning.getLnurlPayInvoiceOptions(lightningAddress).then((opts) => { - if (!cancelled) setCommentMax(opts?.commentAllowed ?? 0) + if (!cancelled) { + if (opts) { + setCommentMax(opts.commentAllowed) + setLnurlMetadataState('ready') + } else { + setCommentMax(0) + setLnurlMetadataState('error') + } + } }) return () => { cancelled = true } - }, [lightningAddress, defaultZapSats, defaultZapComment]) + }, [lightningAddress, defaultZapSats]) useEffect(() => { setInvoice(null) @@ -171,23 +183,31 @@ export default function LightningInvoiceSection({ - {commentMax === null ? ( + {lnurlMetadataState === 'loading' ? ( - ) : commentMax > 0 ? ( + ) : lnurlMetadataState === 'error' ? ( +

+ {t( + 'Could not read this Lightning address (network or browser block). Descriptions need LNURL-pay support on the recipient side.' + )} +

+ ) : (commentMax ?? 0) > 0 ? (
- {description.length}/{commentMax} + {description.length}/{commentMax ?? 0}