diff options
Diffstat (limited to 'routes/bitcoin')
| -rw-r--r-- | routes/bitcoin/send.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index 884c0db1..634b223b 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -58,14 +58,6 @@ module.exports = ah(async (req, res) => { }); } - if (total > account.balance) { - l.error("amount exceeds balance", amount, fee, account.balance); - throw new Error("low balance"); - } else if (total + conversionFee > account.balance) { - l.error("total (after conversion fee) exceeds balance", amount, fee, account.balance); - throw new Error("low balance (after conversion fee)"); - } - // use user's credits to reduce fee, if available let conversionFeeDeduction = Math.min(account.btc_credits, conversionFee); if (conversionFeeDeduction) { @@ -74,6 +66,14 @@ module.exports = ah(async (req, res) => { conversionFee -= conversionFeeDeduction; } + if (total > account.balance) { + l.error("amount exceeds balance", amount, fee, account.balance); + throw new Error("low balance"); + } else if (total + conversionFee > account.balance) { + l.error("total (after conversion fee) exceeds balance", amount, fee, account.balance); + throw new Error("low balance (after conversion fee)"); + } + await account.decrement({ balance: (total + conversionFee) }, { transaction }); await account.reload({ transaction }); |
