aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/send.js1
-rw-r--r--lib/sendInternal.js63
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;
});
};