aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lightning.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lightning.ts')
-rw-r--r--lib/lightning.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/lightning.ts b/lib/lightning.ts
index 7a35c9f2..ce39f0ad 100644
--- a/lib/lightning.ts
+++ b/lib/lightning.ts
@@ -6,8 +6,8 @@ import { credit, types } from "$lib/payments";
import { getPayment } from "$lib/utils";
export async function listenForLightning() {
- let inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
- let {
+ const inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
+ const {
bolt11,
description,
pay_index,
@@ -18,16 +18,16 @@ export async function listenForLightning() {
await s("pay_index", pay_index);
setTimeout(listenForLightning);
- let received = Math.round(amount_received_msat / 1000);
+ const received = Math.round(amount_received_msat / 1000);
try {
if (!preimage) return;
- let id = await g(`invoice:${bolt11}`);
- let invoice = await g(`invoice:${id}`);
+ const id = await g(`invoice:${bolt11}`);
+ const invoice = await g(`invoice:${id}`);
if (!invoice) return warn("received lightning with no invoice", bolt11);
- if (invoice && invoice.memo) {
+ if (invoice?.memo) {
try {
if (JSON.parse(description).kind === 9734) await handleZap(inv);
} catch (e) {
@@ -36,10 +36,16 @@ export async function listenForLightning() {
}
}
- let p = await getPayment(bolt11);
+ const p = await getPayment(bolt11);
if (p) return warn("already processed", bolt11);
- await credit({ hash:bolt11, amount:received, memo:invoice.memo, ref:preimage, type:types.lightning});
+ await credit({
+ hash: bolt11,
+ amount: received,
+ memo: invoice.memo,
+ ref: preimage,
+ type: types.lightning,
+ });
} catch (e) {
console.log(e);
err("problem receiving lightning payment", e.message);