From 3098f0c849f696b39714799c6c1663936946e61b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 26 Feb 2022 00:27:21 -0500 Subject: fix rounding errors --- lib/passport.js | 6 ++++-- lib/sync.js | 4 ++-- routes/assets.js | 2 +- routes/liquid/receive.js | 2 +- routes/payments.js | 3 ++- routes/users.js | 10 ++++++---- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/passport.js b/lib/passport.js index 7bf68c13..4580c709 100644 --- a/lib/passport.js +++ b/lib/passport.js @@ -30,8 +30,10 @@ passport = Passport.use( if (user.locked) throw new Error("account is locked"); next(null, user); } catch (e) { - console.log(e); - l.error("problem logging in", e); + if (!e.message.includes("locked")) { + console.log(e); + l.error("problem logging in", e); + } next(null, { username: "guest" }); } } diff --git a/lib/sync.js b/lib/sync.js index dda83eab..d7bdb4c5 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -288,8 +288,8 @@ const sync = async () => { } }; -setTimeout(sync, 5000); -setInterval(sync, 300000); +//setTimeout(sync, 5000); +//setInterval(sync, 300000); app.get( "/conversions", diff --git a/routes/assets.js b/routes/assets.js index ccff012d..df0e5c31 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -207,7 +207,7 @@ app.post( name, balance: 0, network: "liquid", - pending: address ? 0 : params.asset_amount * SATS + pending: address ? 0 : Math.round(params.asset_amount * SATS) }, { transaction } ); diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 92942ce4..0ee3e0c6 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -239,7 +239,7 @@ zmqRawBlock.on("message", async (topic, message, sequence) => { lock: transaction.LOCK.UPDATE, transaction }); - account.balance = asset_amount * SATS; + account.balance = Math.round(asset_amount * SATS); account.pending = 0; await account.save({ transaction }); diff --git a/routes/payments.js b/routes/payments.js index 9cc692db..ecc9a470 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -92,7 +92,8 @@ app.get( "/payments", auth, ah(async (req, res) => { - let payments = await req.user.getPayments({ + if (!req.user.account_id) return res.send([]); + let payments = await db.Payment.findAll({ where: { account_id: req.user.account_id }, diff --git a/routes/users.js b/routes/users.js index 6e6d1ddc..403c4646 100644 --- a/routes/users.js +++ b/routes/users.js @@ -623,7 +623,7 @@ app.post( res.end(); }); } catch (e) { - l.error(e.message); + l.error("problem updating account", e.message); return res.status(500).send("There was a problem updating the account"); } }) @@ -638,14 +638,16 @@ app.post( try { const account = await db.Account.findOne({ - where: { id, user_id: user.id } + where: { id } }); + if (account.user_id !== user.id) + return res.status(500).send("Failed to open wallet"); + user.account_id = account.id; await user.save(); let payments = await db.Payment.findAll({ where: { - user_id: user.id, account_id: id }, order: [["id", "DESC"]], @@ -663,7 +665,7 @@ app.post( res.send(user); } catch (e) { - l.error(e.message); + l.error("problem switching account", e.message); return res.status(500).send("There was a problem switching accounts"); } }) -- cgit v1.2.3