diff options
| author | Adrien Hopkins <[email protected]> | 2022-06-16 12:23:23 -0500 |
|---|---|---|
| committer | Adrien Hopkins <[email protected]> | 2022-06-16 12:23:23 -0500 |
| commit | 51ed4347d0dfcaac16957abf31848e0dd9d86b40 (patch) | |
| tree | cad6b3e196562a170967c0c566f5512c7bbb7753 /routes/bitcoin | |
| parent | 55d4763146916e7e168bdc0ffd6d97c0d82f8e83 (diff) | |
| download | coinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.tar.gz coinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.zip | |
Whether you can pay takes into account fee deductions
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 }); |
