aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-08-10 18:53:31 -0700
committerAdam Soltys <[email protected]>2025-08-10 18:53:34 -0700
commit05b18b10c42fe6a21549f05813db6adad59e3362 (patch)
tree4c7cfd8973b743c11a34bb646d12938727875b59 /routes
parent7d914fe065dbe31f22853db2fa3e2a1c8bc1fbd2 (diff)
downloadcoinos-server-05b18b10c42fe6a21549f05813db6adad59e3362.tar.gz
coinos-server-05b18b10c42fe6a21549f05813db6adad59e3362.zip
authorizations
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts30
1 files changed, 25 insertions, 5 deletions
diff --git a/routes/payments.ts b/routes/payments.ts
index 1aab736f..def8dc69 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -229,12 +229,12 @@ export default {
async fund(req, res) {
const {
- params: { name },
+ params: { id },
} = req;
- const amount = await g(`fund:${name}`);
+ const amount = await g(`fund:${id}`);
if (typeof amount === "undefined" || amount === null)
return bail(res, "fund not found");
- let payments = (await db.lRange(`fund:${name}:payments`, 0, -1)) || [];
+ let payments = (await db.lRange(`fund:${id}:payments`, 0, -1)) || [];
payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`)));
await Promise.all(
@@ -242,7 +242,9 @@ export default {
);
payments = payments.filter((p) => p);
- res.send({ amount, payments });
+
+ const { amount: authorization } = await g(`authorization:${id}`);
+ res.send({ amount, authorization, payments });
},
// async withdraw(req, res) {
@@ -263,6 +265,24 @@ export default {
// });
// },
+ async authorize(req, res) {
+ const { id: uid } = req.user;
+ const { id, fiat, currency, amount } = req.body;
+
+ const managers = await db.sMembers(`fund:${id}:managers`);
+ if (managers.length && !managers.includes(uid)) fail("Unauthorized");
+
+ const authorization = {
+ uid,
+ currency,
+ fiat,
+ amount,
+ };
+
+ await s(`authorization:${id}`, authorization);
+ res.send({});
+ },
+
async take(req, res) {
let {
body: { id, amount, invoice: iid },
@@ -285,7 +305,7 @@ export default {
const authorization = await g(`authorization:${id}`);
if (authorization && !authorization.claimed) {
const { currency, fiat } = authorization;
- amount = sats(fiat / rates[currency]);
+ amount = Math.min(amount, sats(fiat / rates[currency]));
const sender = await getUser(authorization.uid);
authorization.claimed = true;