cancel fast zap

This commit is contained in:
Kieran 2023-02-27 21:19:26 +00:00
parent 17c6b65158
commit 7463196edf
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 16 additions and 9 deletions

View File

@ -21,7 +21,7 @@ import Zap from "Icons/Zap";
import Reply from "Icons/Reply";
import { formatShort } from "Number";
import useEventPublisher from "Feed/EventPublisher";
import { hexToBech32, normalizeReaction } from "Util";
import { hexToBech32, normalizeReaction, unwrap } from "Util";
import { NoteCreator } from "Element/NoteCreator";
import Reactions from "Element/Reactions";
import SendSats from "Element/SendSats";
@ -127,15 +127,14 @@ export default function NoteFooter(props: NoteFooterProps) {
try {
const handler = new LNURL(lnurl);
await handler.load();
const zap = await publisher.zap(prefs.defaultZapAmount * 1000, ev.PubKey, ev.Id);
const zap = handler.canZap ? await publisher.zap(prefs.defaultZapAmount * 1000, ev.PubKey, ev.Id) : undefined;
const invoice = await handler.getInvoice(prefs.defaultZapAmount, undefined, zap);
if (invoice.pr) {
await webln.sendPayment(invoice.pr);
}
await await webln.sendPayment(unwrap(invoice.pr));
} catch (e) {
console.warn("Instant zap failed", e);
setTip(true);
console.warn("Fast zap failed", e);
if (!(e instanceof Error) || e.message !== "User rejected") {
setTip(true);
}
} finally {
setZapping(false);
}

View File

@ -1,11 +1,19 @@
import { useEffect } from "react";
interface WebLNPaymentResponse {
paymentHash: string;
preimage: string;
route: {
total_amt: number;
total_fees: number;
};
}
declare global {
interface Window {
webln?: {
enabled: boolean;
enable: () => Promise<void>;
sendPayment: (pr: string) => Promise<unknown>;
sendPayment: (pr: string) => Promise<WebLNPaymentResponse>;
};
}
}