aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:03:23 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:03:23 -0700
commit2ff6a289f142636beee1846132049cae7cfd82ea (patch)
treea23313129b1aa54c8e7925471fc3e9f873192a86 /lib
parentb3203b848a25b5aadebfe8fff3e0f01dda1919fa (diff)
downloadcoinos-server-2ff6a289f142636beee1846132049cae7cfd82ea.tar.gz
coinos-server-2ff6a289f142636beee1846132049cae7cfd82ea.zip
detect internal payments
Diffstat (limited to 'lib')
-rw-r--r--lib/locations.ts3
-rw-r--r--lib/notifications.ts38
-rw-r--r--lib/payments.ts6
3 files changed, 25 insertions, 22 deletions
diff --git a/lib/locations.ts b/lib/locations.ts
index bb8b08cf..abf578d8 100644
--- a/lib/locations.ts
+++ b/lib/locations.ts
@@ -18,7 +18,7 @@ const dedup = (array) =>
export const getLocations = async () => {
try {
- const previous = await g("locations") || [];
+ const previous = (await g("locations")) || [];
let since = await g("locations:since");
if (!since) since = "2022-09-19T00:00:00Z";
if (Date.now() - new Date(since).getTime() < 60000) return;
@@ -45,6 +45,7 @@ export const getLocations = async () => {
for await (const l of locations) {
const username = l.tags["payment:coinos"];
if (username) {
+ console.log(username);
const uid = await g(`user:${username}`);
const user = await g(`user:${uid}`);
if (user) l.osm_json.tags.user = pick(user, fields);
diff --git a/lib/notifications.ts b/lib/notifications.ts
index 023fdeff..08d96507 100644
--- a/lib/notifications.ts
+++ b/lib/notifications.ts
@@ -1,10 +1,10 @@
-import { emit } from "$lib/sockets";
-import { err, warn } from "$lib/logging";
-import { db } from "$lib/db";
-import mqtt from "$lib/mqtt";
import config from "$config";
+import { db } from "$lib/db";
+import { err, warn } from "$lib/logging";
import { mail, templates } from "$lib/mail";
-import { f, fmt, link, fiat, t } from "$lib/utils";
+import mqtt from "$lib/mqtt";
+import { emit } from "$lib/sockets";
+import { f, fiat, fmt, link, t } from "$lib/utils";
import webpush from "web-push";
if (config.vapid) {
@@ -17,8 +17,8 @@ if (config.vapid) {
export const notify = async (p, user, withdrawal) => {
emit(user.id, "payment", p);
- let { username } = user;
- let { paymentReceived } = t(user);
+ const { username } = user;
+ const { paymentReceived } = t(user);
try {
if (user.verified && user.notify) {
@@ -32,16 +32,14 @@ export const notify = async (p, user, withdrawal) => {
fiat: f(fiat(p.amount, p.rate), p.currency),
fiatTip: p.tip ? f(fiat(p.tip, p.rate), p.currency) : undefined,
memo: p.memo,
- items:
- p.items &&
- p.items.map((i) => {
- return {
- quantity: i.quantity,
- name: i.name,
- total: i.quantity * i.price,
- totalFiat: f(i.quantity * i.price, p.currency),
- };
- }),
+ items: p.items?.map((i) => {
+ return {
+ quantity: i.quantity,
+ name: i.name,
+ total: i.quantity * i.price,
+ totalFiat: f(i.quantity * i.price, p.currency),
+ };
+ }),
},
withdrawal,
});
@@ -50,15 +48,15 @@ export const notify = async (p, user, withdrawal) => {
err("problem emailing", e.message);
}
- let subscriptions = await db.sMembers(`${user.id}:subscriptions`);
+ const subscriptions = await db.sMembers(`${user.id}:subscriptions`);
- let payload = {
+ const payload = {
title: paymentReceived,
body: `${fmt(p.amount)} ${f(fiat(p.amount, p.rate), p.currency)}`,
url: `/payment/${p.id}`,
};
- for (let s of subscriptions) {
+ for (const s of subscriptions) {
webpush
.sendNotification(JSON.parse(s), JSON.stringify(payload))
.catch((e) => {
diff --git a/lib/payments.ts b/lib/payments.ts
index 88b9230d..98c4bc50 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -65,6 +65,9 @@ export const debit = async ({
let iid;
if (invoice) {
+ console.log("AMT", amount);
+ console.log("RCVD", invoice.received);
+ console.log(invoice.received >= amount);
if (invoice.received >= amount) fail("Invoice already paid");
({ id: iid } = invoice);
@@ -436,7 +439,8 @@ export const sendLightning = async ({
if (typeof amount !== "undefined") {
amount = parseInt(amount);
- if (amount < 0 || amount > SATS || isNaN(amount)) fail("Invalid amount");
+ if (amount < 0 || amount > SATS || Number.isNaN(amount))
+ fail("Invalid amount");
}
let total = amount;