fix: show QR code when failing webln payment

This commit is contained in:
Alejandro Gomez
2023-07-05 21:18:26 +02:00
parent 0278886976
commit a8e7fcdffd

View File

@ -13,7 +13,11 @@ export interface LNURLLike {
get name(): string; get name(): string;
get maxCommentLength(): number; get maxCommentLength(): number;
get canZap(): boolean; get canZap(): boolean;
getInvoice(amountInSats: number, comment?: string, zap?: NostrEvent): Promise<{ pr?: string }> getInvoice(
amountInSats: number,
comment?: string,
zap?: NostrEvent
): Promise<{ pr?: string }>;
} }
export interface SendZapsProps { export interface SendZapsProps {
@ -93,8 +97,12 @@ export function SendZaps({
if (window.webln) { if (window.webln) {
await window.webln.enable(); await window.webln.enable();
try {
await window.webln.sendPayment(invoice.pr); await window.webln.sendPayment(invoice.pr);
onFinish(); onFinish();
} catch (error) {
setInvoice(invoice.pr);
}
} else { } else {
setInvoice(invoice.pr); setInvoice(invoice.pr);
} }
@ -138,7 +146,8 @@ export function SendZaps({
))} ))}
</div> </div>
</div> </div>
{svc && (svc.maxCommentLength > 0 || svc.canZap) && <div> {svc && (svc.maxCommentLength > 0 || svc.canZap) && (
<div>
<small>Your comment for {name}</small> <small>Your comment for {name}</small>
<div className="paper"> <div className="paper">
<textarea <textarea
@ -147,7 +156,8 @@ export function SendZaps({
onChange={(e) => setComment(e.target.value)} onChange={(e) => setComment(e.target.value)}
/> />
</div> </div>
</div>} </div>
)}
<div> <div>
<AsyncButton onClick={send} className="btn btn-primary"> <AsyncButton onClick={send} className="btn btn-primary">
Zap! Zap!
@ -161,12 +171,14 @@ export function SendZaps({
if (!invoice) return; if (!invoice) return;
const link = `lightning:${invoice}`; const link = `lightning:${invoice}`;
return <> return (
<>
<QrCode data={link} link={link} /> <QrCode data={link} link={link} />
<button className="btn btn-primary wide" onClick={() => onFinish()}> <button className="btn btn-primary wide" onClick={() => onFinish()}>
Back Back
</button> </button>
</>; </>
);
} }
return ( return (