diff options
| author | Adam Soltys <[email protected]> | 2022-10-28 00:28:23 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-28 00:28:23 -0700 |
| commit | 740ec7ed160034ee435fc52fa0056b0fad708e59 (patch) | |
| tree | 81d860345b8163611aee6c2ed30c5cf4a9fa75bd /lib | |
| parent | 83d6a7ee834b2f2b3c23216ce867e2726dfe8e9a (diff) | |
| parent | 25f27e55943562215139de8a11db07d1cfb6df5f (diff) | |
| download | coinos-server-740ec7ed160034ee435fc52fa0056b0fad708e59.tar.gz coinos-server-740ec7ed160034ee435fc52fa0056b0fad708e59.zip | |
Merge branch 'prod'
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/send.js | 1 | ||||
| -rw-r--r-- | lib/sendInternal.js | 63 |
2 files changed, 33 insertions, 31 deletions
diff --git a/lib/send.js b/lib/send.js index f717d8f8..4f264509 100644 --- a/lib/send.js +++ b/lib/send.js @@ -68,7 +68,6 @@ export default async (amount, memo, hash, user) => { conversionFeeDeduction = Math.min(account.lightning_credits, conversionFee); total = amount + conversionFee - conversionFeeDeduction; - console.log("a t lc cf cfd", amount, total, account.lightning_credits, conversionFee, conversionFeeDeduction); if (!account || account.balance < total) { warn( diff --git a/lib/sendInternal.js b/lib/sendInternal.js index 2e98ed22..3090e94a 100644 --- a/lib/sendInternal.js +++ b/lib/sendInternal.js @@ -56,38 +56,10 @@ export default async ( await account.decrement({ balance: amount }, { transaction }); await account.reload({ transaction }); - let params = { - amount: -amount, - account_id: account.id, - memo, - user_id: user.id, - rate: store.rates[user.currency], - currency: user.currency, - confirmed: true, - hash: `#${v4().substr(0, 6)} ${ - username ? `Payment to ${username}` : "Internal Transfer" - }`, - network: "COINOS" - }; - - if (!username) { - l("creating redeemable payment"); - params.redeemcode = v4(); - params.hash = `${hostname}/redeem/${params.redeemcode}`; - } - - let payment = await db.Payment.create(params, { transaction }); - - payment = payment.get({ plain: true }); - payment.account = account.get({ plain: true }); - - l("sent internal", user.username, -payment.amount); - - emit(user.username, "payment", payment); - emit(user.username, "account", account); + let params, recipient, payment; if (username) { - let recipient = await db.User.findOne( + recipient = await db.User.findOne( { where: { username }, include: { @@ -210,6 +182,37 @@ export default async ( callWebhook(invoice, p2); } + params = { + amount: -amount, + account_id: account.id, + memo, + user_id: user.id, + rate: store.rates[user.currency], + currency: user.currency, + confirmed: true, + with_id: recipient && recipient.id, + hash: `#${v4().substr(0, 6)} ${ + username ? `Payment to ${username}` : "Internal Transfer" + }`, + network: "COINOS" + }; + + if (!username) { + l("creating redeemable payment"); + params.redeemcode = v4(); + params.hash = `${hostname}/redeem/${params.redeemcode}`; + } + + payment = await db.Payment.create(params, { transaction }); + + payment = payment.get({ plain: true }); + payment.account = account.get({ plain: true }); + + l("sent internal", user.username, -payment.amount); + + emit(user.username, "payment", payment); + emit(user.username, "account", account); + return payment; }); }; |
