aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-10-28 00:28:23 -0700
committerAdam Soltys <[email protected]>2022-10-28 00:28:23 -0700
commit740ec7ed160034ee435fc52fa0056b0fad708e59 (patch)
tree81d860345b8163611aee6c2ed30c5cf4a9fa75bd
parent83d6a7ee834b2f2b3c23216ce867e2726dfe8e9a (diff)
parent25f27e55943562215139de8a11db07d1cfb6df5f (diff)
downloadcoinos-server-740ec7ed160034ee435fc52fa0056b0fad708e59.tar.gz
coinos-server-740ec7ed160034ee435fc52fa0056b0fad708e59.zip
Merge branch 'prod'
-rw-r--r--Dockerfile2
-rw-r--r--lib/send.js1
-rw-r--r--lib/sendInternal.js63
-rw-r--r--routes/payments.js37
4 files changed, 64 insertions, 39 deletions
diff --git a/Dockerfile b/Dockerfile
index 80f6851c..a8a125ef 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,6 +9,6 @@ RUN npm i -g pnpm
COPY . /app
WORKDIR /app
-RUN NODE_OPTIONS="" pnpm i
+RUN NODE_ENV=development NODE_OPTIONS="" pnpm i
CMD ["pnpm", "start"]
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;
});
};
diff --git a/routes/payments.js b/routes/payments.js
index 7a728daa..0cd45829 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -26,8 +26,6 @@ app.post("/send", auth, send);
app.post("/sendToTokenHolders", auth, async (req, res, next) => {
let { asset, amount } = req.body;
-
-
let accounts = await db.Account.findAll({
where: {
asset,
@@ -103,19 +101,44 @@ setTimeout(async () => {
}, 50);
app.get("/payments", auth, async (req, res) => {
+ let { start, end, limit, offset, v2 } = req.query;
+
+ if (limit) limit = parseInt(limit);
+ if (offset) offset = parseInt(offset);
+
+ let dayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
+
+ let where = {
+ account_id: req.user.account_id,
+ createdAt: { [Op.gte]: dayAgo }
+ };
+
+ if (start) where.createdAt[Op.gte] = new Date(start * 1000);
+ if (end) where.createdAt[Op.lte] = new Date(end * 1000);
+
if (!req.user.account_id) return res.send([]);
+
+ let total = await db.Payment.count({
+ where
+ });
+
let payments = await db.Payment.findAll({
- where: {
- account_id: req.user.account_id
- },
+ where,
order: [["id", "DESC"]],
include: {
model: db.Account,
as: "account"
- }
+ },
+ limit,
+ offset
});
- res.send(payments);
+
+ if (v2) {
+ res.send({ transactions: payments, total });
+ } else {
+ res.send(payments);
+ }
});
app.get("/payment/:redeemcode", async (req, res) => {