aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-03-08 23:01:49 -0800
committerAdam Soltys <[email protected]>2024-03-08 23:01:49 -0800
commit6b8c43f3577513427bddc57503cbb5c2f1cbf462 (patch)
tree80bbac096126aee555bb8d566e5164aec57674b0 /src/routes
parent59e2f69f0b0ab31e18bdc36e1d605ba2c82bed1d (diff)
downloadcoinos-ui-lnurl-fiat.tar.gz
coinos-ui-lnurl-fiat.zip
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.js44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.js b/src/routes/(app)/ln/[lnurl]/+page.server.js
index 910ce5a5..6acfcfce 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.js
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.js
@@ -2,7 +2,7 @@ import { fd, auth, get, post } from "$lib/utils";
import { error, fail, redirect } from "@sveltejs/kit";
export async function load({ params, parent }) {
- let { user } = await parent();
+ let { rates, user } = await parent();
if (!user) redirect(307, "/register");
let data;
@@ -14,12 +14,46 @@ export async function load({ params, parent }) {
error(500, e.message);
}
+ let currencies = [
+ {
+ code: "BRL",
+ name: "Reais",
+ symbol: "R$",
+ decimals: 2,
+ multiplier: 2932.290939091977,
+ convertible: { max: 100000, min: 100 },
+ },
+ {
+ code: "USDT",
+ name: "Tether",
+ symbol: "$",
+ decimals: 6,
+ multiplier: 1.4602808876678048,
+ convertible: { max: 200000000, min: 200000 },
+ },
+ ];
+
+ if (data.currencies) {
+ data.currencies.map(
+ (c) => (rates[c.code] = c.multiplier * 10 ** (c.decimals - 3) * 1000)
+ );
+ }
+
+ data.rates = rates;
+
if (!["payRequest", "withdrawRequest"].includes(data.tag))
error(500, "We only support LNURLp and LNURLw at this time");
return data;
}
+const convertAmount = (amount, multiplier, decimals) => {
+ const conversionFactor = multiplier * 10 ** (decimals - 3);
+ const convertedAmount = amount / conversionFactor;
+
+ return convertedAmount.toFixed(decimals);
+};
+
export const actions = {
pay: async ({ cookies, fetch, request }) => {
let error;
@@ -28,13 +62,19 @@ export const actions = {
minSendable = Math.round(minSendable / 1000);
maxSendable = Math.round(maxSendable / 1000);
+
+
if (amount < minSendable)
error = `Amount must be at least ${minSendable} sats`;
if (amount > maxSendable)
error = `Amount must be at most ${maxSendable} sats`;
if (error) return fail(400, { error });
- let { pr } = await fetch(`${callback}?amount=${amount * 1000}`).then((r) =>
+ const a = currency
+ ? `${Math.trunc(+amount * 10 ** currency.decimals)}.${currency.code}`
+ : (+amount * 1000).toString();
+
+ let { pr } = await fetch(`${callback}?amount=${a}`).then((r) =>
r.json()
);
redirect(307, `/send/lightning/${pr}`);