aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:04:09 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:25:47 -0700
commit4742e72ec25823ceeea7848fb2e1f868bed7f472 (patch)
tree031c15d9b1aeca23bd117490c69785e3cf69e450 /src
parenta92dd4d39a86af41dd9cd6c9f58263a13f852906 (diff)
downloadcoinos-ui-4742e72ec25823ceeea7848fb2e1f868bed7f472.tar.gz
coinos-ui-4742e72ec25823ceeea7848fb2e1f868bed7f472.zip
detect internal payments
Diffstat (limited to 'src')
-rw-r--r--src/lib/invoice.ts15
-rw-r--r--src/lib/parse.ts16
-rw-r--r--src/routes/(app)/fund/[id]/withdraw/+page.svelte2
-rw-r--r--src/routes/(app)/pay/[username]/[...amount]/+page.server.ts1
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+page.server.ts6
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.server.ts49
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.svelte4
7 files changed, 49 insertions, 44 deletions
diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts
index fec845f9..a48e02a4 100644
--- a/src/lib/invoice.ts
+++ b/src/lib/invoice.ts
@@ -2,11 +2,11 @@ import { auth, get, post } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
export default async ({ cookies, request }) => {
- let aid = cookies.get("aid");
- let form = await request.formData();
+ const form = await request.formData();
+ const aid = form.get("aid") || cookies.get("aid");
- let rates = await get("/rates");
- let amount = parseInt(form.get("amount"));
+ const rates = await get("/rates");
+ const amount = parseInt(form.get("amount"));
let invoice = {
aid,
@@ -21,10 +21,13 @@ export default async ({ cookies, request }) => {
id: undefined,
};
- let user = { username: form.get("username"), currency: form.get("currency") };
+ const user = {
+ username: form.get("username"),
+ currency: form.get("currency"),
+ };
invoice = await post("/invoice", { invoice, user }, auth(cookies));
- let { id } = invoice;
+ const { id } = invoice;
if (invoice.prompt && invoice.tip === null)
redirect(307, `/invoice/${id}/tip`);
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index fcce7e1e..0ebbe003 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -29,6 +29,14 @@ export default async (t, host) => {
if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund")));
+ // invoice
+ let invoice;
+ try {
+ invoice = await get(`/invoice/${t}`);
+ } catch (e) {}
+
+ if (invoice) redirect(307, `/send/invoice/${invoice.id}`);
+
// lightning
if (t.toLowerCase().startsWith("lightning:"))
t = t.toLowerCase().replace("lightning:", "");
@@ -69,12 +77,4 @@ export default async (t, host) => {
} catch (e) {}
if (fund) redirect(307, `/send/fund/${t}`);
-
- // invoice
- let invoice;
- try {
- invoice = await get(`/invoice/${t}`);
- } catch (e) {}
-
- if (invoice) redirect(307, `/send/invoice/${invoice.id}`);
};
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte
index 7af07e38..0ad3c2cf 100644
--- a/src/routes/(app)/fund/[id]/withdraw/+page.svelte
+++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte
@@ -37,7 +37,7 @@
{/if}
<div class="container px-4 mt-20 max-w-xl mx-auto">
- <Numpad bind:amount bind:currency bind:rate {submit} />
+ <Numpad bind:amount bind:currency bind:rate />
<form method="POST" use:enhance on:submit={submit}>
<input name="id" value={id} type="hidden" />
diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
index 60288813..9c8a6927 100644
--- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
@@ -12,7 +12,6 @@ export async function load({ cookies, params, parent }) {
let rate;
- console.log("HI", amount);
if (amount) {
rate = rates[currency ? currency.toUpperCase() : subject.currency];
if (!rate) error(500, "Invalid currency symbol");
diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
index a9b72787..f27d3fab 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts
@@ -1,7 +1,7 @@
import { auth, get } from "$lib/utils";
export async function load({ cookies }) {
- let aid = cookies.get("aid");
- let { balance } = await get(`/account/${aid}`, auth(cookies));
- return { balance };
+ const aid = cookies.get("aid");
+ const { balance } = await get(`/account/${aid}`, auth(cookies));
+ return { balance };
}
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts
index f294f88d..f1c00c0f 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.server.ts
+++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts
@@ -1,38 +1,39 @@
+import { auth, fd, get, post } from "$lib/utils";
import { error, redirect } from "@sveltejs/kit";
-import { fd, auth, get, post } from "$lib/utils";
-export async function load({ params: { id }, parent }) {
- let { rates, user } = await parent();
+export async function load({ cookies, params: { id }, parent }) {
+ const aid = cookies.get("aid");
+ const { rates, user } = await parent();
- let invoice = await get(`/invoice/${id}`);
+ const invoice = await get(`/invoice/${id}`);
- if (invoice.prompt && invoice.tip === null)
- redirect(307, `/invoice/${id}/tip`);
+ if (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.account === user?.id)
- error(500, { message: "Cannot send to self" });
+ if (invoice.aid === aid) error(500, { message: "Cannot send to self" });
+ else if (user) redirect(307, `/send/${invoice.type}/${invoice.hash}`);
- if (!user) redirect(307, `/invoice/${id}`);
+ if (!user) redirect(307, `/invoice/${id}`);
- return { invoice, rates, user };
+ return { invoice, rates, user };
}
export const actions = {
- default: async ({ cookies, params: { id }, request }) => {
- let p;
- try {
- let body = await fd(request);
- body.hash = id;
+ default: async ({ cookies, params: { id }, request }) => {
+ let p;
+ try {
+ const body = await fd(request);
+ body.hash = id;
- p = await post("/payments", body, auth(cookies));
- } catch (e: any) {
- console.log("payment failed", id, e);
- error(500, e.message);
- }
+ p = await post("/payments", body, auth(cookies));
+ } catch (e: any) {
+ console.log("payment failed", id, e);
+ error(500, e.message);
+ }
- redirect(307, `/sent/${p.id}`);
- },
+ redirect(307, `/sent/${p.id}`);
+ },
};
diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte
index 4348e473..fe60c9a6 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/send/invoice/[id]/+page.svelte
@@ -48,7 +48,7 @@
amountFiat = af;
};
- let submitting;
+ let submit, submitting;
let toggle = () => (submitting = !submitting);
let external = async () => {
@@ -162,6 +162,7 @@
{currency}
bind:fiat
bind:rate
+ {submit}
/>
{/if}
@@ -188,6 +189,7 @@
</button>
{:else}
<button
+ bind:this={submit}
type="button"
class="opacity-100 hover:opacity-80'} rounded-2xl border py-5 font-bold mx-auto mt-2 bg-black text-white px-6 w-40"
on:click={setAmount}