diff options
| author | Adam Soltys <[email protected]> | 2023-03-28 22:25:46 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-28 22:25:52 -0700 |
| commit | ab49b84a8ab11b33735167fcc04b6f54a8c14a27 (patch) | |
| tree | 52fcead247e199615e6b4d991de7287b6ff0b300 /lib | |
| parent | 91f8f3bdbfc570154080a1ca70d27f61a637f56c (diff) | |
| download | coinos-server-ab49b84a8ab11b33735167fcc04b6f54a8c14a27.tar.gz coinos-server-ab49b84a8ab11b33735167fcc04b6f54a8c14a27.zip | |
calculate equivalent rate
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.js | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/payments.js b/lib/payments.js index b1e57d9c..a48a187b 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -13,7 +13,7 @@ export const types = { bitcoin: "bitcoin", lightning: "lightning", pot: "pot", - classic: "classic", + classic: "classic" }; export let debit = async ( @@ -33,7 +33,12 @@ export let debit = async ( let invoice = await g(`invoice:${hash}`); if (invoice) { ref = invoice.uid; - if (Math.abs(invoice.rate / rate - 1) < 0.01) rate = invoice.rate; + if (Math.abs(invoice.rate / store.rates[invoice.currency] - 1) < 0.01) { + rate = + invoice.rate * (store.rates[currency] / store.rates[invoice.currency]); + } else { + warn("rate slipped", hash, invoice.rate, equivalentRate); + } } let tip = parseInt(invoice?.tip) || null; @@ -81,7 +86,7 @@ export let debit = async ( type, ref, tip, - created: Date.now(), + created: Date.now() }; await s(`payment:${id}`, p); @@ -120,7 +125,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { tip, type, confirmed: true, - created: Date.now(), + created: Date.now() }; invoice.received += amount; |
