aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-04 20:40:35 -0700
committerAdam Soltys <[email protected]>2024-09-04 20:51:14 -0700
commit33d67e431416ea8b69b424e7d043ef63953c355a (patch)
tree58d8fed75e94d6d6fcb21d83b8b860670659fe5d /lib
parentdfde1c88ebb52e50f983f5a36e8868dd0938c3fc (diff)
downloadcoinos-server-33d67e431416ea8b69b424e7d043ef63953c355a.tar.gz
coinos-server-33d67e431416ea8b69b424e7d043ef63953c355a.zip
fx endpoint
Diffstat (limited to 'lib')
-rw-r--r--lib/invoices.ts12
-rw-r--r--lib/rates.ts15
-rw-r--r--lib/rpc.ts6
3 files changed, 18 insertions, 15 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index 04e1200b..ee0eb73d 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -1,16 +1,16 @@
-import crypto from "crypto";
-import store from "$lib/store";
-import { l } from "$lib/logging";
import { emit } from "$lib/sockets";
import { db, g, s } from "$lib/db";
import { getUser, bip21, fail, SATS } from "$lib/utils";
import { types } from "$lib/payments";
import { v4 } from "uuid";
-import lq from "$lib/liquid";
-import bc from "$lib/bitcoin";
+import bc_ from "$lib/bitcoin";
+import lq_ from "$lib/liquid";
import ln from "$lib/ln";
+let bc = bc_ as any;
+let lq = lq_ as any;
+
export let generate = async ({ invoice, user, sender = undefined }) => {
let {
bolt11,
@@ -37,7 +37,7 @@ export let generate = async ({ invoice, user, sender = undefined }) => {
else if (sender) user = await getUser(sender.username);
if (!user) fail("user not provided");
- let rates = await g('rates');
+ let rates = await g("rates");
if (!currency) currency = user.currency;
if (!rate) rate = rates[currency];
if (fiat) amount = Math.round((SATS * fiat) / rate);
diff --git a/lib/rates.ts b/lib/rates.ts
index fe942453..f840592e 100644
--- a/lib/rates.ts
+++ b/lib/rates.ts
@@ -1,7 +1,6 @@
import got from "got";
import config from "$config";
-import store from "$lib/store";
-import { err, warn } from "$lib/logging";
+import { err } from "$lib/logging";
import { g, s } from "$lib/db";
import { sleep } from "$lib/utils";
import WebSocket from "ws";
@@ -51,10 +50,14 @@ export let getFx = async () => {
if (Date.now() - date > 24 * 60 * 60 * 1000) {
date = Date.now();
try {
- let r = await got(
- `http://data.fixer.io/api/latest?access_key=${config.fixer}`,
- ).json();
- let { rates: fx } = r;
+ if (config.fixer) {
+ ({ rates: fx } = (await got(
+ `http://data.fixer.io/api/latest?access_key=${config.fixer}`,
+ ).json()) as any);
+ } else {
+ ({ fx } = (await got("https://coinos.io/api/fx").json()) as any);
+ }
+
let USD = fx["USD"];
Object.keys(fx).map((k) => {
diff --git a/lib/rpc.ts b/lib/rpc.ts
index bb57d075..bcf695a4 100644
--- a/lib/rpc.ts
+++ b/lib/rpc.ts
@@ -1,11 +1,11 @@
import got from "got";
-export default ({ host, port, wallet, username, password }) =>
+export default ({ host, port, wallet, username, password })=>
new Proxy(
{},
{
get:
- (target, prop) =>
+ (_, prop) =>
(...params) =>
((method, ...params) => {
let url = `http://${host}:${port}/wallet/${wallet}`;
@@ -23,6 +23,6 @@ export default ({ host, port, wallet, username, password }) =>
})
.json()
.then(({ result }) => result);
- })(prop.toLowerCase(), ...params),
+ })((prop as string).toLowerCase(), ...params),
},
);