1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import { auth, get, post } from '$lib/utils';
import tickets from '$lib/tickets';
import { redirect } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { invalidateAll } from '$app/navigation';
import { browser } from '$app/environment';
import { createTicket } from '$lib/ticket';
export const load = async ({ parent }) => {
let tickets = await get('/tickets');
let { user } = await parent();
let hasTicket = !!user?.accounts.find((a) => tickets.includes(a.asset));
if (hasTicket) throw redirect(307, '/launch/ticket');
return { tickets };
};
export const actions = {
internal: async ({ cookies, request }) => {
let form = await request.formData();
let asset = await createTicket(cookies, form.get('username'));
await post('/payments', { amount: 22000, username: 'launch' }, auth(cookies));
throw redirect(307, `/launch/thanks/${asset}`);
},
lightning: async ({ cookies, request }) => {
let form = await request.formData();
let rates = await get('/rates');
let invoice = {
amount: 22000,
memo: 'launch',
type: 'lightning',
prompt: false,
rate: rates[form.get('currency')]
};
let user = { username: form.get('username') };
let { id } = await post('/invoice', { invoice, user }, auth(cookies));
throw redirect(307, `/${user.username}/invoice/${id}`);
}
};
|