aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lnurl.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/lnurl.js')
-rw-r--r--routes/lnurl.js13
1 files changed, 6 insertions, 7 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 49212330..93d939f9 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -420,13 +420,6 @@ lnurlServer.bindToHook(
transaction
});
- if (account.balance < amount) {
- throw new Error("Insufficient funds");
- } else if (account.balance < amount + conversionFee) {
- throw new Error("Insufficient funds for conversion fee");
- }
-
- // use user's credits to reduce fee, if available
let conversionFeeDeduction = Math.min(account.lightning_credits, conversionFee);
if (conversionFeeDeduction) {
await account.decrement({ lightning_credits: conversionFeeDeduction }, { transaction });
@@ -434,6 +427,12 @@ lnurlServer.bindToHook(
conversionFee -= conversionFeeDeduction;
}
+ if (account.balance < amount) {
+ throw new Error("Insufficient funds");
+ } else if (account.balance < amount + conversionFee) {
+ throw new Error("Insufficient funds for conversion fee");
+ }
+
let fee_payment_id = null;
if (conversionFee) {
await receiverAccount.increment({ balance: conversionFee }, { transaction });