aboutsummaryrefslogtreecommitdiffstats
path: root/lib/invoices.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/invoices.js')
-rw-r--r--lib/invoices.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/invoices.js b/lib/invoices.js
index 2e5a8e64..62bbee1c 100644
--- a/lib/invoices.js
+++ b/lib/invoices.js
@@ -2,7 +2,7 @@ import store from "$lib/store";
import { l } from "$lib/logging";
import { emit } from "$lib/sockets";
import { db, g, s } from "$lib/db";
-import { getUser, bip21, fail } from "$lib/utils";
+import { getUser, bip21, fail, SATS } from "$lib/utils";
import { types } from "$lib/payments";
import { v4 } from "uuid";
@@ -13,6 +13,7 @@ export let generate = async ({ invoice, user, sender, memo }) => {
let {
currency,
expiry,
+ fiat,
tip,
amount,
rate,
@@ -26,14 +27,13 @@ export let generate = async ({ invoice, user, sender, memo }) => {
amount = parseInt(amount || 0);
tip = parseInt(tip) || null;
- if (amount < 0) fail("amount out of range");
-
if (user) user = await getUser(user.username);
else if (sender) user = await getUser(sender.username);
else fail("user not provided");
if (!currency) currency = user.currency;
if (!rate) rate = store.rates[currency];
+ if (fiat) amount = Math.round((SATS * fiat) / rate);
if (amount < 0) fail("invalid amount");
let hash, text;