aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lnurl.js
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-06-16 12:23:23 -0500
committerAdrien Hopkins <[email protected]>2022-06-16 12:23:23 -0500
commit51ed4347d0dfcaac16957abf31848e0dd9d86b40 (patch)
treecad6b3e196562a170967c0c566f5512c7bbb7753 /routes/lnurl.js
parent55d4763146916e7e168bdc0ffd6d97c0d82f8e83 (diff)
downloadcoinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.tar.gz
coinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.zip
Whether you can pay takes into account fee deductions
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 });