diff options
Diffstat (limited to 'lib/sendInternal.js')
| -rw-r--r-- | lib/sendInternal.js | 63 |
1 files changed, 33 insertions, 30 deletions
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; }); }; |
