aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/handler.ts
blob: baca442d459b51d52ee95742bb2ecae29c49131f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
import { goto } from "$app/navigation";
import { applyAction } from "$app/forms";

export default (toggle) => () => {
	toggle();
	return async ({ result }) => {
		if (result.type === "redirect") {
			goto(result.location);
		} else {
			await applyAction(result);
		}
	};
};
est } }); if (!invoice) return; const { text: hash, currency, rate, tip, user } = invoice; const amount = parseInt(msg.value) - tip; const payment = await db.Payment.create({ user_id: user.id, hash, amount, currency, rate, received: true, confirmed: true, asset, tip, }); invoice.received += amount + tip; user.balance += amount + tip; await invoice.save(); await payment.save(); await user.save(); payments.push(msg.payment_request); l.info("lightning payment received", user.username, payment.amount, payment.tip); emit(user.username, "payment", payment); emit(user.username, "user", user); }; const invoices = lna.subscribeInvoices({}); invoices.on("data", handlePayment); const invoicesb = lnb.subscribeInvoices({}); invoicesb.on("data", handlePayment);