aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes/(app)/[username]/invoice/[hash]/+layout.server.js2
-rw-r--r--src/routes/(app)/send/user/[username]/[...amount]/+page.server.js5
-rw-r--r--src/routes/(app)/send/user/[username]/[...amount]/+page.svelte40
3 files changed, 33 insertions, 14 deletions
diff --git a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js b/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js
index 7cf87e14..df22400a 100644
--- a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js
+++ b/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js
@@ -9,6 +9,8 @@ export async function load({ depends, params, url, parent }) {
let { hash } = params;
let invoice = await get(`/invoice/${hash}`);
+ console.log("HI", invoice)
+
if (user && invoice.uid !== user.id && !url.pathname.includes('tip'))
throw redirect(307, `/send/invoice/${hash}`);
diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js
index c63328e2..a2ce4e04 100644
--- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js
+++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js
@@ -3,10 +3,11 @@ import { fd, auth, get, post } from '$lib/utils';
export async function load({ params, parent }) {
let { user } = await parent();
- let { amount } = params;
+ let [amount, currency] = params.amount.split('/');
+
let subject = await get(`/users/${params.username}`);
if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' });
- return { amount, subject };
+ return { amount, currency, subject };
}
export const actions = {
diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte
index af6a6368..ea59ffed 100644
--- a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte
+++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte
@@ -1,7 +1,7 @@
<script>
import { t } from '$lib/translations';
import { goto } from '$app/navigation';
- import { pin, selectedRate } from '$lib/store';
+ import { pin, selectedRate, rate as huh } from '$lib/store';
import { enhance } from '$app/forms';
import { AppHeader, Avatar, Icon, Numpad, Spinner } from '$comp';
import { page } from '$app/stores';
@@ -11,25 +11,17 @@
export let form;
let { subject, rates, user } = data;
- let currency = user?.currency || 'USD';
-
- let amount = form?.amount || data.amount;
- let a,
- af,
- fiat = !amount,
- hash,
- rate,
- amountFiat = 0;
-
- selectedRate.subscribe((r) => rate || (amountFiat = amount * (r / sats)));
+ let currency = data.currency || user?.currency || 'USD';
let setAmount = async () => {
+ try {
amount = a;
amountFiat = parseFloat(af).toFixed(2);
rate = fiat ? (sats * amountFiat) / amount : $selectedRate;
({ hash } = await post(`/${subject.username}/invoice`, {
invoice: {
amount,
+ currency,
hash: 'internal',
rate: rates[subject.currency],
prompt: subject.prompt,
@@ -39,8 +31,30 @@
}));
goto(`/${subject.username}/invoice/${hash}`);
+ } catch(e) {
+ console.log(e)
+ }
};
+ let amount = form?.amount || (!data.currency && data.amount) || 0;
+ let a = amount,
+ af = data.currency ? data.amount : undefined,
+ fiat = data.currency || !amount,
+ hash,
+ rate,
+ amountFiat = 0;
+
+ selectedRate.subscribe((r) => {
+ if (rate) return;
+ if (data.currency) {
+ a = Math.round((af / r) * sats);
+ } else {
+ af = amount * (r / sats);
+ }
+
+ setAmount();
+ });
+
let loading;
let submit = () => (loading = true);
@@ -60,6 +74,8 @@
{/if}
<div class="container px-4 mt-20 max-w-xl mx-auto space-y-8">
+ {af}<br />
+ {a}
<Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat />
<form method="POST" use:enhance on:submit={submit}>