aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/send
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
committerAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
commit13466248004327e9a026cb89f94926f9b060d1c1 (patch)
tree47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/routes/(app)/send
parent3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff)
downloadcoinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz
coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip
linting
Diffstat (limited to 'src/routes/(app)/send')
-rw-r--r--src/routes/(app)/send/+layout.server.ts4
-rw-r--r--src/routes/(app)/send/[...text]/+page.server.ts22
-rw-r--r--src/routes/(app)/send/[...text]/+page.svelte3
-rw-r--r--src/routes/(app)/send/ark/[address]/+layout.server.ts36
-rw-r--r--src/routes/(app)/send/ark/[address]/+page.server.ts10
-rw-r--r--src/routes/(app)/send/ark/[address]/+page.svelte6
-rw-r--r--src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts81
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+layout.server.ts34
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+page.server.ts10
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+page.svelte9
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts112
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte11
-rw-r--r--src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts30
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.server.ts118
-rw-r--r--src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts90
-rw-r--r--src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte25
-rw-r--r--src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts54
-rw-r--r--src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte4
18 files changed, 343 insertions, 316 deletions
diff --git a/src/routes/(app)/send/+layout.server.ts b/src/routes/(app)/send/+layout.server.ts
index dbb3efad..38ed57cf 100644
--- a/src/routes/(app)/send/+layout.server.ts
+++ b/src/routes/(app)/send/+layout.server.ts
@@ -1,6 +1,6 @@
import { redirect } from "@sveltejs/kit";
export async function load({ cookies, url }) {
- if (!cookies.get("token"))
- redirect(307, `/register?redirect=${url.pathname}`);
+ if (!cookies.get("token"))
+ redirect(307, `/register?redirect=${url.pathname}`);
}
diff --git a/src/routes/(app)/send/[...text]/+page.server.ts b/src/routes/(app)/send/[...text]/+page.server.ts
index 59d53dbe..dc76da7f 100644
--- a/src/routes/(app)/send/[...text]/+page.server.ts
+++ b/src/routes/(app)/send/[...text]/+page.server.ts
@@ -5,20 +5,20 @@ import { fail, redirect } from "@sveltejs/kit";
const limit = 10;
export async function load({ cookies, depends, params, parent, url }) {
depends("app:contacts");
- const { user } = await parent();
- if (!user) redirect(307, "/login");
- const { text } = params;
+ const { user } = await parent();
+ if (!user) redirect(307, "/login");
+ const { text } = params;
- await parse(text, url.host, cookies);
- const contacts = await get(`/contacts/${limit}`, auth(cookies));
+ await parse(text, url.host, cookies);
+ const contacts = await get(`/contacts/${limit}`, auth(cookies));
- return { contacts };
+ return { contacts };
}
export const actions = {
- default: async ({ cookies, request, url }) => {
- const { text } = await fd(request);
- await parse(text, url.host, cookies);
- return fail(400, { error: "default" });
- },
+ default: async ({ cookies, request, url }) => {
+ const { text } = await fd(request);
+ await parse(text, url.host, cookies);
+ return fail(400, { error: "default" });
+ },
};
diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte
index 34acb4b0..58db231a 100644
--- a/src/routes/(app)/send/[...text]/+page.svelte
+++ b/src/routes/(app)/send/[...text]/+page.svelte
@@ -6,7 +6,8 @@
import { tick } from "svelte";
import { browser } from "$app/environment";
import { t } from "$lib/translations";
- import Avatar from "$comp/Avatar.svelte"; import Spinner from "$comp/Spinner.svelte";
+ import Avatar from "$comp/Avatar.svelte";
+ import Spinner from "$comp/Spinner.svelte";
import { back, get, post, fail, focus } from "$lib/utils";
let { data = $bindable(), form } = $props();
diff --git a/src/routes/(app)/send/ark/[address]/+layout.server.ts b/src/routes/(app)/send/ark/[address]/+layout.server.ts
index cf16ea36..bb167d2d 100644
--- a/src/routes/(app)/send/ark/[address]/+layout.server.ts
+++ b/src/routes/(app)/send/ark/[address]/+layout.server.ts
@@ -2,25 +2,25 @@ import { auth, get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
- const { user } = await parent();
- const aid = cookies.get("aid") || user.id;
- const { address, amount } = params;
- const { balance } = await get(`/account/${aid}`, auth(cookies));
+ const { user } = await parent();
+ const aid = cookies.get("aid") || user.id;
+ const { address, amount } = params;
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
- let invoice;
- try {
- invoice = await get(`/invoice/${address}`);
- } catch (e) {
- // invoice not found
- }
+ let invoice;
+ try {
+ invoice = await get(`/invoice/${address}`);
+ } catch {
+ // invoice not found
+ }
- if (invoice) {
- const recipient = await get(`/users/${invoice.uid}`);
- let r = `/pay/${recipient.username}`;
- if (amount) r += `/${amount}`;
- if (recipient?.id !== user.id && recipient.id === invoice.aid)
- redirect(307, r);
- }
+ if (invoice) {
+ const recipient = await get(`/users/${invoice.uid}`);
+ let r = `/pay/${recipient.username}`;
+ if (amount) r += `/${amount}`;
+ if (recipient?.id !== user.id && recipient.id === invoice.aid)
+ redirect(307, r);
+ }
- return { balance };
+ return { balance };
}
diff --git a/src/routes/(app)/send/ark/[address]/+page.server.ts b/src/routes/(app)/send/ark/[address]/+page.server.ts
index b7d3c5cf..fdf129a0 100644
--- a/src/routes/(app)/send/ark/[address]/+page.server.ts
+++ b/src/routes/(app)/send/ark/[address]/+page.server.ts
@@ -2,9 +2,9 @@ import getRates from "$lib/rates";
import { auth, get } from "$lib/utils";
export async function load({ cookies, parent }) {
- const { user } = await parent();
- const rates = await getRates();
- const aid = cookies.get("aid") || user.id;
- const { balance } = await get(`/account/${aid}`, auth(cookies));
- return { balance, rate: rates[user.currency] };
+ const { user } = await parent();
+ const rates = await getRates();
+ const aid = cookies.get("aid") || user.id;
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
+ return { balance, rate: rates[user.currency] };
}
diff --git a/src/routes/(app)/send/ark/[address]/+page.svelte b/src/routes/(app)/send/ark/[address]/+page.svelte
index 531047fe..0bf9e0de 100644
--- a/src/routes/(app)/send/ark/[address]/+page.svelte
+++ b/src/routes/(app)/send/ark/[address]/+page.svelte
@@ -27,7 +27,6 @@
await tick();
submit.click();
};
-
</script>
<div class="container px-4 max-w-xl mx-auto space-y-5 text-center">
@@ -57,10 +56,7 @@
{/if}</button
>
- <form
- action={`/send/ark/${address}/${amount}`}
- class="contents"
- >
+ <form action={`/send/ark/${address}/${amount}`} class="contents">
<button
bind:this={submit}
type="submit"
diff --git a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
index 309d75fa..07972e6c 100644
--- a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
+++ b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
@@ -3,47 +3,58 @@ import { auth, fd, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({ params: { address, amount }, cookies, parent }) {
- const rates = await getRates();
- const { user } = await parent();
- const aid = cookies.get("aid") || user.id;
+ const rates = await getRates();
+ const { user } = await parent();
+ const aid = cookies.get("aid") || user.id;
- const account = await get(`/account/${aid}`, auth(cookies));
+ const account = await get(`/account/${aid}`, auth(cookies));
- if (account.type === "bitcoin") {
- const inv = await post(
- "/invoice",
- { invoice: { type: "bitcoin", amount: parseInt(amount), forward: address }, user },
- auth(cookies),
- );
- redirect(307, `/send/bitcoin/${inv.hash}/${amount}`);
- }
+ if (account.type === "bitcoin") {
+ const inv = await post(
+ "/invoice",
+ {
+ invoice: {
+ type: "bitcoin",
+ amount: parseInt(amount),
+ forward: address,
+ },
+ user,
+ },
+ auth(cookies),
+ );
+ redirect(307, `/send/bitcoin/${inv.hash}/${amount}`);
+ }
- const rate = rates[user.currency];
+ const rate = rates[user.currency];
- return {
- account,
- amount,
- address,
- rate,
- };
+ return {
+ account,
+ amount,
+ address,
+ rate,
+ };
}
export const actions = {
- default: async ({
- cookies,
- params: { address, amount, feeRate },
- request,
- }) => {
- let p;
- try {
- const body = await fd(request);
- p = await post("/ark/send", { ...body, address, amount: parseInt(amount) }, auth(cookies));
- } catch (e) {
- console.log("problem sending bitcoin", e);
- const { message } = e as Error;
- return fail(400, { address, amount, feeRate, message });
- }
+ default: async ({
+ cookies,
+ params: { address, amount, feeRate },
+ request,
+ }) => {
+ let p;
+ try {
+ const body = await fd(request);
+ p = await post(
+ "/ark/send",
+ { ...body, address, amount: parseInt(amount) },
+ auth(cookies),
+ );
+ } catch (e) {
+ console.log("problem sending bitcoin", e);
+ const { message } = e as Error;
+ return fail(400, { address, amount, feeRate, message });
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
index e7a216d6..d8df1986 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
@@ -2,24 +2,24 @@ import { auth, get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
- const { user } = await parent();
- const aid = cookies.get("aid") || user.id;
- const { address, amount } = params;
- const { balance } = await get(`/account/${aid}`, auth(cookies));
+ const { user } = await parent();
+ const aid = cookies.get("aid") || user.id;
+ const { address, amount } = params;
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
- let invoice;
- try {
- invoice = await get(`/invoice/${address}`);
- } catch (e) {
- // invoice not found
- }
+ let invoice;
+ try {
+ invoice = await get(`/invoice/${address}`);
+ } catch {
+ // invoice not found
+ }
- if (invoice) {
- const recipient = await get(`/users/${invoice.uid}`);
- let r = `/pay/${recipient.username}`;
- if (amount) r += `/${amount}`;
- if (recipient?.id !== user.id) redirect(307, r);
- }
+ if (invoice) {
+ const recipient = await get(`/users/${invoice.uid}`);
+ let r = `/pay/${recipient.username}`;
+ if (amount) r += `/${amount}`;
+ if (recipient?.id !== user.id) redirect(307, r);
+ }
- return { balance };
+ return { balance };
}
diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
index b7d3c5cf..fdf129a0 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
@@ -2,9 +2,9 @@ import getRates from "$lib/rates";
import { auth, get } from "$lib/utils";
export async function load({ cookies, parent }) {
- const { user } = await parent();
- const rates = await getRates();
- const aid = cookies.get("aid") || user.id;
- const { balance } = await get(`/account/${aid}`, auth(cookies));
- return { balance, rate: rates[user.currency] };
+ const { user } = await parent();
+ const rates = await getRates();
+ const aid = cookies.get("aid") || user.id;
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
+ return { balance, rate: rates[user.currency] };
}
diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/+page.svelte
index 96b3fbd9..6c49ad6c 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+page.svelte
+++ b/src/routes/(app)/send/bitcoin/[address]/+page.svelte
@@ -34,7 +34,14 @@
<div class="text-xl text-secondary break-all">{address}</div>
- <Numpad bind:amount={a} bind:fiat {currency} {submit} bind:rate={$rate} {locale} />
+ <Numpad
+ bind:amount={a}
+ bind:fiat
+ {currency}
+ {submit}
+ bind:rate={$rate}
+ {locale}
+ />
<div class="flex justify-center gap-2">
<button
diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
index 9695247b..7cdd86f5 100644
--- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
@@ -3,68 +3,68 @@ import { auth, fd, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({
- params: { address, amount, feeRate },
- cookies,
- parent,
+ params: { address, amount, feeRate },
+ cookies,
+ parent,
}) {
- const rates = await getRates();
- const { user } = await parent();
- const aid = cookies.get("aid") || user.id;
- const account = await get(`/account/${aid}`, auth(cookies));
+ const rates = await getRates();
+ const { user } = await parent();
+ const aid = cookies.get("aid") || user.id;
+ const account = await get(`/account/${aid}`, auth(cookies));
- if (account.type === "ark") {
- const serverArkAddress = await get("/ark/address");
- return {
- account,
- amount,
- address,
- rate: rates[user.currency],
- serverArkAddress,
- };
- }
+ if (account.type === "ark") {
+ const serverArkAddress = await get("/ark/address");
+ return {
+ account,
+ amount,
+ address,
+ rate: rates[user.currency],
+ serverArkAddress,
+ };
+ }
- try {
- const { fee, fees, inputs, ourfee, hex, subtract } = await post(
- "/bitcoin/fee",
- { address, amount, feeRate, aid },
- auth(cookies),
- );
+ try {
+ const { fee, fees, inputs, ourfee, hex, subtract } = await post(
+ "/bitcoin/fee",
+ { address, amount, feeRate, aid },
+ auth(cookies),
+ );
- return {
- account,
- amount,
- address,
- fee,
- fees,
- feeRate,
- rate: rates[user.currency],
- ourfee,
- subtract,
- hex,
- inputs,
- };
- } catch (e) {
- const { message } = e as Error;
- return { amount, address, feeRate, message };
- }
+ return {
+ account,
+ amount,
+ address,
+ fee,
+ fees,
+ feeRate,
+ rate: rates[user.currency],
+ ourfee,
+ subtract,
+ hex,
+ inputs,
+ };
+ } catch (e) {
+ const { message } = e as Error;
+ return { amount, address, feeRate, message };
+ }
}
export const actions = {
- default: async ({
- cookies,
- params: { address, amount, feeRate },
- request,
- }) => {
- let p;
- try {
- const body = await fd(request);
- p = await post("/bitcoin/send", body, auth(cookies));
- } catch (e) {
- console.log("problem sending bitcoin", e);
- const { message } = e as Error;
- return fail(400, { address, amount, feeRate, message });
- }
+ default: async ({
+ cookies,
+ params: { address, amount, feeRate },
+ request,
+ }) => {
+ let p;
+ try {
+ const body = await fd(request);
+ p = await post("/bitcoin/send", body, auth(cookies));
+ } catch (e) {
+ console.log("problem sending bitcoin", e);
+ const { message } = e as Error;
+ return fail(400, { address, amount, feeRate, message });
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
index ecdb3b08..6581e12f 100644
--- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
+++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
@@ -78,7 +78,8 @@
return;
}
- if ((account.seed || data.user.seed) && !signed) cancel(), void togglePassword();
+ if ((account.seed || data.user.seed) && !signed)
+ (cancel(), void togglePassword());
return async ({ result }) => {
if (result.type === "redirect") {
goto(result.location);
@@ -102,14 +103,18 @@
import("@scure/bip39"),
import("@scure/bip39/wordlists/english.js"),
]);
- let entropy = await decrypt(account.seed || data.user.seed, password as string);
+ let entropy = await decrypt(
+ account.seed || data.user.seed,
+ password as string,
+ );
let mnemonic = entropyToMnemonic(entropy, wordlist);
let seed = await mnemonicToSeed(mnemonic, password as string);
let master = HDKey.fromMasterSeed(seed, network as any);
let child = master.derive(`m/84'/0'/${account.accountIndex ?? 0}'`);
let raw = decode(hex);
- let isPSBT = raw[0] === 0x70 && raw[1] === 0x73 && raw[2] === 0x62 && raw[3] === 0x74;
+ let isPSBT =
+ raw[0] === 0x70 && raw[1] === 0x73 && raw[2] === 0x62 && raw[3] === 0x74;
let tx: any = isPSBT ? Transaction.fromPSBT(raw) : Transaction.fromRaw(raw);
for (let [i, input] of tx.inputs.entries()) {
diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts
index 428d8d78..0c4b4d96 100644
--- a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts
@@ -5,24 +5,24 @@ import { fail, redirect } from "@sveltejs/kit";
export async function load({ parent, params }) {
let { name, amount } = params;
if (!name) name = crypto.randomUUID();
- const { user } = await parent();
- const rates = await getRates();
- const rate = rates[user.currency];
- return { name, amount, rate };
+ const { user } = await parent();
+ const rates = await getRates();
+ const rate = rates[user.currency];
+ return { name, amount, rate };
}
export const actions = {
- default: async ({ cookies, request }) => {
- const body = await fd(request);
- let p;
+ default: async ({ cookies, request }) => {
+ const body = await fd(request);
+ let p;
- try {
- p = await post("/payments", body, auth(cookies));
- } catch (e) {
- const { message } = e as Error;
- return fail(400, { message });
- }
+ try {
+ p = await post("/payments", body, auth(cookies));
+ } catch (e) {
+ const { message } = e as Error;
+ return fail(400, { message });
+ }
- if (p) redirect(307, `/fund/${body.fund}`);
- },
+ if (p) redirect(307, `/fund/${body.fund}`);
+ },
};
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts
index c9c7dbd9..2e268b99 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.server.ts
+++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts
@@ -3,76 +3,76 @@ import { auth, fd, get, post, types } from "$lib/utils";
import { error, fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, depends, params: { id }, parent }) {
- depends("app:trust");
- const { subject, user } = await parent();
- const aid = cookies.get("aid") || user.id;
- const pin = cookies.get("pin");
+ depends("app:trust");
+ const { user } = await parent();
+ const aid = cookies.get("aid") || user.id;
+ const pin = cookies.get("pin");
- let invoice = await get(`/invoice/${id}`);
+ let invoice = await get(`/invoice/${id}`);
- const trust = await get("/trust", auth(cookies));
- const trusted = trust.includes(invoice.uid);
- if (trusted && (pin || !user.haspin)) {
- let p;
- try {
- if (!invoice.tip && invoice.user.prompt) {
- if (user.tip > 0) {
- invoice.tip = Math.round(invoice.amount * (user.tip / 100));
- invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies));
- } else {
- throw new Error("tip");
- }
- }
- p = await post("/payments", { ...invoice, pin }, auth(cookies));
- } catch (e) {
- const { message } = e as Error;
- if (message === "tip") redirect(307, `/invoice/${id}/tip`);
- fail(400, { message });
- }
- if (p) redirect(307, `/sent/${p.id}`);
- }
+ const trust = await get("/trust", auth(cookies));
+ const trusted = trust.includes(invoice.uid);
+ if (trusted && (pin || !user.haspin)) {
+ let p;
+ try {
+ if (!invoice.tip && invoice.user.prompt) {
+ if (user.tip > 0) {
+ invoice.tip = Math.round(invoice.amount * (user.tip / 100));
+ invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies));
+ } else {
+ throw new Error("tip");
+ }
+ }
+ p = await post("/payments", { ...invoice, pin }, auth(cookies));
+ } catch (e) {
+ const { message } = e as Error;
+ if (message === "tip") redirect(307, `/invoice/${id}/tip`);
+ fail(400, { message });
+ }
+ if (p) redirect(307, `/sent/${p.id}`);
+ }
- if (invoice.amount && invoice.prompt && invoice.tip === null)
- redirect(307, `/invoice/${id}/tip`);
+ if (invoice.amount && invoice.prompt && invoice.tip === null)
+ redirect(307, `/invoice/${id}/tip`);
- if (invoice.memoPrompt && invoice.memo === null)
- redirect(307, `/invoice/${id}/memo`);
+ if (invoice.memoPrompt && invoice.memo === null)
+ redirect(307, `/invoice/${id}/memo`);
- if (user && invoice.aid === aid)
- error(500, { message: "Cannot send to self" });
- else if (user && ![types.lightning, types.bolt12].includes(invoice.type))
- redirect(
- 307,
- `/send/${invoice.type === types.ecash ? "ecash" : "bitcoin"}/${
- invoice.hash
- }`,
- );
+ if (user && invoice.aid === aid)
+ error(500, { message: "Cannot send to self" });
+ else if (user && ![types.lightning, types.bolt12].includes(invoice.type))
+ redirect(
+ 307,
+ `/send/${invoice.type === types.ecash ? "ecash" : "bitcoin"}/${
+ invoice.hash
+ }`,
+ );
- if (!user) redirect(307, `/invoice/${id}`);
+ if (!user) redirect(307, `/invoice/${id}`);
- const rates = await getRates();
- const rate = rates[user.currency];
- const invoiceRate = rates[invoice.currency];
+ const rates = await getRates();
+ const rate = rates[user.currency];
+ const invoiceRate = rates[invoice.currency];
- const { balance } = await get(`/account/${aid}`, auth(cookies));
- return { balance, invoice, user, rate, invoiceRate, trusted };
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
+ return { balance, invoice, user, rate, invoiceRate, trusted };
}
export const actions = {
- default: async ({ cookies, params: { id }, request }) => {
- let p;
- try {
- const body = await fd(request);
- body.hash = id;
- body.aid = cookies.get("aid");
+ default: async ({ cookies, params: { id }, request }) => {
+ let p;
+ try {
+ const body = await fd(request);
+ body.hash = id;
+ body.aid = cookies.get("aid");
- p = await post("/payments", body, auth(cookies));
- } catch (e) {
- const { message } = e as Error;
- console.log("payment failed", id, e);
- error(500, { message });
- }
+ p = await post("/payments", body, auth(cookies));
+ } catch (e) {
+ const { message } = e as Error;
+ console.log("payment failed", id, e);
+ error(500, { message });
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts
index 7a5514e8..de123e2e 100644
--- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts
+++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts
@@ -3,61 +3,61 @@ import { auth, fd, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
- const { user } = await parent();
- let data: any = { ...params };
- const rates = await getRates();
- if (!params.payreq.startsWith("lno")) {
- data = { ...data, ...(await post("/parse", params, auth(cookies))) };
- }
+ const { user } = await parent();
+ let data: any = { ...params };
+ const rates = await getRates();
+ if (!params.payreq.startsWith("lno")) {
+ data = { ...data, ...(await post("/parse", params, auth(cookies))) };
+ }
- data.rate = rates[user.currency];
+ data.rate = rates[user.currency];
- const aid = cookies.get("aid") || user.id;
- if (aid !== user.id) {
- const account = await get(`/account/${aid}`, auth(cookies));
- if (account.type === "ark") {
- data.account = account;
- data.serverArkAddress = await get("/ark/address");
- } else if (account.type === "bitcoin") {
- data.account = account;
- }
- }
+ const aid = cookies.get("aid") || user.id;
+ if (aid !== user.id) {
+ const account = await get(`/account/${aid}`, auth(cookies));
+ if (account.type === "ark") {
+ data.account = account;
+ data.serverArkAddress = await get("/ark/address");
+ } else if (account.type === "bitcoin") {
+ data.account = account;
+ }
+ }
- return data;
+ return data;
}
export const actions = {
- setAmount: async ({ cookies, params, request }) => {
- let data = await fd(request);
- const { payreq } = params;
- const { amount } = data;
- if (payreq.startsWith("lno")) {
- const { invoice } = await post("/fetchinvoice", {
- amount,
- offer: payreq,
- });
+ setAmount: async ({ cookies, params, request }) => {
+ let data = await fd(request);
+ const { payreq } = params;
+ const { amount } = data;
+ if (payreq.startsWith("lno")) {
+ const { invoice } = await post("/fetchinvoice", {
+ amount,
+ offer: payreq,
+ });
- data = await post("/parse", { payreq: invoice }, auth(cookies));
- data.payreq = invoice;
- }
+ data = await post("/parse", { payreq: invoice }, auth(cookies));
+ data.payreq = invoice;
+ }
- return data;
- },
+ return data;
+ },
- send: async ({ cookies, request }) => {
- let p;
- try {
- const body = await fd(request);
- body.aid = cookies.get("aid");
+ send: async ({ cookies, request }) => {
+ let p;
+ try {
+ const body = await fd(request);
+ body.aid = cookies.get("aid");
- console.log("BODY", body);
+ console.log("BODY", body);
- p = await post("/payments", body, auth(cookies));
- } catch (e) {
- const { message } = e as Error;
- return fail(400, { message });
- }
+ p = await post("/payments", body, auth(cookies));
+ } catch (e) {
+ const { message } = e as Error;
+ return fail(400, { message });
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte
index 526038fa..718f3ee2 100644
--- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte
+++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte
@@ -18,8 +18,12 @@
let { currency, locked } = $derived(user);
let locale = $derived(loc(user));
- $effect(() => { $rate ||= data.rate; });
- $effect(() => { if (form) loading = false; });
+ $effect(() => {
+ $rate ||= data.rate;
+ });
+ $effect(() => {
+ if (form) loading = false;
+ });
let showMax = $state();
let error = $state("");
@@ -33,7 +37,9 @@
let maxfee = $state(
Math.max(5, Math.round(untrack(() => amount) * 0.02 || 0)),
);
- $effect(() => { maxfee = Math.max(5, Math.round(amount * 0.02) || 0); });
+ $effect(() => {
+ maxfee = Math.max(5, Math.round(amount * 0.02) || 0);
+ });
let handler = ({ cancel }) => {
loading = true;
@@ -67,7 +73,11 @@
(async () => {
try {
const inv = await post("/post/invoice", {
- invoice: { type: "bitcoin", amount: parseInt(amount), forward: payreq },
+ invoice: {
+ type: "bitcoin",
+ amount: parseInt(amount),
+ forward: payreq,
+ },
user,
});
@@ -126,12 +136,7 @@
</div>
{/if}
- <form
- method="POST"
- use:enhance={handler}
- action="?/send"
- class="space-y-2"
- >
+ <form method="POST" use:enhance={handler} action="?/send" class="space-y-2">
<input name="payreq" value={payreq} type="hidden" />
<input name="amount" value={amount} type="hidden" />
<input name="pin" value={$pin} type="hidden" />
diff --git a/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts b/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts
index 2219c370..a658a5c1 100644
--- a/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts
@@ -3,41 +3,41 @@ import { auth, fd, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
- const { user } = await parent();
- const { amount, id } = params;
- const rates = await getRates();
+ const { user } = await parent();
+ const { amount, id } = params;
+ const rates = await getRates();
- let request;
- if (amount)
- request = await post("/zapRequest", { amount, id }, auth(cookies));
+ let request;
+ if (amount)
+ request = await post("/zapRequest", { amount, id }, auth(cookies));
- const rate = rates[user.currency];
- return { amount, id, rates, rate, request };
+ const rate = rates[user.currency];
+ return { amount, id, rates, rate, request };
}
export const actions = {
- setAmount: async ({ cookies, params, request }) => {
- const data = await fd(request);
- const { id } = params;
- const { amount } = data;
+ setAmount: async ({ cookies, params, request }) => {
+ const data = await fd(request);
+ const { id } = params;
+ const { amount } = data;
- data.request = await post("/zapRequest", { amount, id }, auth(cookies));
+ data.request = await post("/zapRequest", { amount, id }, auth(cookies));
- return data;
- },
+ return data;
+ },
- send: async ({ cookies, request }) => {
- let p;
- try {
- const body = await fd(request);
+ send: async ({ cookies, request }) => {
+ let p;
+ try {
+ const body = await fd(request);
- p = await post("/payments", body, auth(cookies));
- console.log("P", p);
- } catch (_) {
- console.log("WHAT", _);
- return fail(400, { message: "payments.failedToRoute" });
- }
+ p = await post("/payments", body, auth(cookies));
+ console.log("P", p);
+ } catch (_) {
+ console.log("WHAT", _);
+ return fail(400, { message: "payments.failedToRoute" });
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte b/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte
index 78b4d64f..3d0d144c 100644
--- a/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte
+++ b/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte
@@ -20,7 +20,9 @@
let locale = $derived(loc(user));
let event = $state();
- $effect(() => { $rate ||= data.rate; });
+ $effect(() => {
+ $rate ||= data.rate;
+ });
$effect(() => {
if (form || request) {
(async () => {