aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/invoice.js4
-rw-r--r--src/lib/socket.js1
-rw-r--r--src/params/uuid.js1
-rw-r--r--src/routes/[username]/receive/+page.svelte1
-rw-r--r--src/routes/send/[...text]/+page.server.js13
-rw-r--r--src/routes/send/[uuid=uuid]/+page.server.js23
-rw-r--r--src/routes/send/[uuid=uuid]/+page.svelte88
-rw-r--r--src/routes/sent/+page.svelte11
8 files changed, 133 insertions, 9 deletions
diff --git a/src/lib/invoice.js b/src/lib/invoice.js
index a0aa8402..1212cbe3 100644
--- a/src/lib/invoice.js
+++ b/src/lib/invoice.js
@@ -4,12 +4,14 @@ import { redirect } from '@sveltejs/kit';
export default async ({ cookies, request }) => {
let form = await request.formData();
+ let rates = await get('/rates');
+
let invoice = {
amount: parseInt(form.get('amount')),
tip: parseInt(form.get('tip')),
network: 'lightning',
prompt: form.get('prompt') === 'true',
- rate: await get('/rate')
+ rate: rates[form.get('currency')]
};
let user = { username: form.get('username') };
diff --git a/src/lib/socket.js b/src/lib/socket.js
index 7908f7b7..b32aa14a 100644
--- a/src/lib/socket.js
+++ b/src/lib/socket.js
@@ -20,6 +20,7 @@ export const messages = (data) => ({
payment() {
let { amount, invoice } = data;
+ console.log("INVOICE", invoice)
if (invoice) {
invoices.set({ ...get(invoices), [invoice.uuid]: invoice });
}
diff --git a/src/params/uuid.js b/src/params/uuid.js
new file mode 100644
index 00000000..b71f68f1
--- /dev/null
+++ b/src/params/uuid.js
@@ -0,0 +1 @@
+export let match = (p) => p.split('-').length > 4
diff --git a/src/routes/[username]/receive/+page.svelte b/src/routes/[username]/receive/+page.svelte
index d205e6e6..7b0562d5 100644
--- a/src/routes/[username]/receive/+page.svelte
+++ b/src/routes/[username]/receive/+page.svelte
@@ -11,6 +11,7 @@
<form method="POST" class="flex justify-center items-center mt-24 mb-3 px-3" use:enhance>
<input type="hidden" name="amount" value={amount} />
+ <input type="hidden" name="currency" value={currency} />
<input type="hidden" name="username" value={username} />
<input type="hidden" name="prompt" value="true" />
diff --git a/src/routes/send/[...text]/+page.server.js b/src/routes/send/[...text]/+page.server.js
index ca1ce652..6bd3ae6a 100644
--- a/src/routes/send/[...text]/+page.server.js
+++ b/src/routes/send/[...text]/+page.server.js
@@ -5,31 +5,28 @@ import { invalid, redirect } from '@sveltejs/kit';
let parse = async (t) => {
if (!t) return;
- let user;
+ let uuid;
// lightning
if (t.startsWith('ln')) {
try {
- ({ user } = await get(`/invoice/${t}`));
+ ({ uuid } = await get(`/invoice/${t}`));
} catch (e) {
throw redirect(303, `/send/lightning/${t}`);
}
- if (user) {
- let { amount } = await post('/lightning/parse', { payreq: t });
- throw redirect(303, `/send/user/${user.username}/${amount}`);
- }
+ if (uuid) throw redirect(303, `/send/${uuid}`);
}
// bitcoin
if (validate(t)) {
try {
- ({ user } = await get(`/invoice/${t}`));
+ ({ uuid } = await get(`/invoice/${t}`));
} catch (e) {
throw redirect(303, `/send/bitcoin/${t}`);
}
- if (user) throw redirect(303, `/send/user/${user.username}`);
+ if (uuid) throw redirect(303, `/send/${uuid}`);
}
// ln address
diff --git a/src/routes/send/[uuid=uuid]/+page.server.js b/src/routes/send/[uuid=uuid]/+page.server.js
new file mode 100644
index 00000000..661e9e7b
--- /dev/null
+++ b/src/routes/send/[uuid=uuid]/+page.server.js
@@ -0,0 +1,23 @@
+import { error, invalid, redirect } from '@sveltejs/kit';
+import { btc as asset, auth, get, post } from '$lib/utils';
+
+export async function load({ params, parent }) {
+ let { user } = await parent();
+ let { amount, address, text, user: recipient } = await get(`/invoice/${params.uuid}`);
+ if (recipient.username === user.username) throw error(500, { message: 'Cannot send to self' });
+ return { amount, address, payreq: text, recipient };
+}
+
+export const actions = {
+ default: async ({ cookies, params, request }) => {
+ let body = Object.fromEntries(await request.formData());
+ let { confirmed } = body;
+
+ if (!confirmed) {
+ return invalid(403, { amount, confirm: true });
+ }
+
+ await post('/send', body, auth(cookies));
+ throw redirect(307, '/sent');
+ }
+};
diff --git a/src/routes/send/[uuid=uuid]/+page.svelte b/src/routes/send/[uuid=uuid]/+page.svelte
new file mode 100644
index 00000000..f625978f
--- /dev/null
+++ b/src/routes/send/[uuid=uuid]/+page.svelte
@@ -0,0 +1,88 @@
+<script>
+ import { goto } from "$app/navigation";
+ import { selectedRate } from '$lib/store';
+ import { enhance } from '$app/forms';
+ import { Icon, Numpad, Spinner } from '$comp';
+ import { page } from '$app/stores';
+ import { back, f, s, sats } from '$lib/utils';
+ export let data;
+ export let form;
+
+ let { address, payreq, recipient, user } = data;
+ let { currency } = user;
+
+ let amount = form?.amount || data.amount;
+ let a,
+ af,
+ amountFiat = amount * ($selectedRate / sats),
+ fiat = !amount;
+
+ let setAmount = () => {
+ amount = a;
+ amountFiat = af;
+ };
+
+ let handleBack = () => {
+ if (amount) {
+ amount = undefined;
+ goto(`/send/user/${recipient.username}`);
+ } else back();
+ };
+
+ let loading;
+ let submit = () => (loading = true);
+</script>
+
+<button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={handleBack}>
+ <Icon icon="arrow-left" style="w-10" />
+</button>
+
+<div class="container px-4 mt-20 max-w-xl mx-auto">
+ {#if amount}
+ <div class="text-center mb-8">
+ <h1 class="text-xl md:text-2xl text-secondary mb-2">Send</h1>
+ <p class="text-6xl break-words mb-4">
+ {fiat ? f(amountFiat, currency) : s(amount)}
+ {#if !fiat}
+ <span class="text-xl md:text-2xl text-secondary">sats</span>
+ {/if}
+ </p>
+
+ <h1 class="text-xl md:text-2xl text-secondary mb-2">to</h1>
+ <p class="text-6xl break-words">{recipient.username}</p>
+ </div>
+ {:else}
+ <Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat />
+ {/if}
+
+ <form method="POST" use:enhance on:submit={submit}>
+ <input name="address" value={address} type="hidden" />
+ <input name="amount" value={amount} type="hidden" />
+ <input name="payreq" value={payreq} type="hidden" />
+ <input name="username" value={recipient.username} type="hidden" />
+ <input name="confirmed" value={form?.confirm} type="hidden" />
+
+ <div class="flex w-full">
+ {#if amount}
+ <button
+ type="submit"
+ class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24"
+ >
+ {#if loading}
+ <Spinner />
+ {:else}
+ Send
+ {/if}
+ </button>
+ {:else}
+ <button
+ type="button"
+ class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24"
+ on:click={setAmount}
+ >
+ Next
+ </button>
+ {/if}
+ </div>
+ </form>
+</div>
diff --git a/src/routes/sent/+page.svelte b/src/routes/sent/+page.svelte
index f79166e4..95612a17 100644
--- a/src/routes/sent/+page.svelte
+++ b/src/routes/sent/+page.svelte
@@ -1,4 +1,5 @@
<script>
+ import { f, s, sats } from '$lib/utils';
import { scale } from 'svelte/transition';
import { Icon } from '$comp';
import { toast } from '@zerodevx/svelte-toast';
@@ -7,6 +8,12 @@
export let data;
let { user } = data;
+ let payment = user.payments[0];
+ let { amount, rate } = payment;
+ amount = Math.abs(amount);
+
+ let fiat = (amount * rate) / sats;
+
toast.pop(0);
</script>
@@ -15,6 +22,10 @@
<Icon icon="check" style="mx-auto" />
</div>
<h1 class="text-3xl md:text-4xl font-bold mb-6">Sent!</h1>
+ <h2 class="text-2xl md:text-3xl font-semibold">
+ {f(fiat, user.currency)}
+ </h2>
+ <h3 class="text-secondary md:text-lg mb-6 mt-1">({s(amount)} SAT)</h3>
<a href={`/${user.username}/transactions`}>
<button class="bg-black text-white rounded-2xl w-20 py-3 font-bold hover:opacity-80">
{$t('invoice.done')}