From 88990faa498ab269d1745dc6524cddf2fe9e5245 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 4 May 2023 10:05:51 -0700 Subject: set rate for pot invoices --- lib/payments.js | 1 + routes/payments.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/payments.js b/lib/payments.js index 7dbc1775..e1e0590e 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -122,6 +122,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let equivalentRate = invoice.rate * (store.rates[currency] / store.rates[invoice.currency]); + if (Math.abs(invoice.rate / store.rates[invoice.currency] - 1) < 0.01) { rate = equivalentRate; } else { diff --git a/routes/payments.js b/routes/payments.js index cb942940..282a8682 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -111,6 +111,7 @@ export default { await credit(hash, amount, memo, user.id); } else { let pot = name || v4(); + memo = pot; p = await debit(hash, amount, 0, memo, user, types.pot); await db.incrBy(`pot:${pot}`, amount); await db.lPush(`pot:${pot}:payments`, p.id); @@ -202,7 +203,10 @@ export default { }); let hash = v4(); + let { currency } = user; await s(`invoice:${hash}`, { + currency, + rate: store.rates[currency], uid: user.id, received: 0 }); -- cgit v1.2.3