diff options
Diffstat (limited to 'src/routes/launch/purchase/+page.server.js')
| -rw-r--r-- | src/routes/launch/purchase/+page.server.js | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/src/routes/launch/purchase/+page.server.js b/src/routes/launch/purchase/+page.server.js index 3317b420..8568c0e7 100644 --- a/src/routes/launch/purchase/+page.server.js +++ b/src/routes/launch/purchase/+page.server.js @@ -4,45 +4,21 @@ 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'); + if (hasTicket) throw redirect(307, '/launch/ticket'); return { tickets }; }; export const actions = { internal: async ({ cookies, request }) => { let form = await request.formData(); - let username = form.get('username'); - - let { address } = await post( - '/invoice', - { invoice: { network: 'liquid' }, user: { username } }, - auth(cookies) - ); - - let { ticket } = await get('/ticket'); - - let { asset } = await post( - '/assets', - { - address, - name: `Launch Party Ticket ${ticket}`, - ticker: 'LPT', - precision: 0, - asset_amount: '1', - token_amount: 0, - domain: 'coinos.io', - filename: tickets[ticket] - }, - { authorization: `Bearer ${env.LAUNCH}` } - ); - - await post('/send', { amount: 25000, username: 'launch' }, auth(cookies)); - await post('/ticket', { asset }, { authorization: `Bearer ${env.LAUNCH}` }); + await createTicket(cookies, form.get('username')); + await post('/send', { amount: 22000, username: 'launch' }, auth(cookies)); throw redirect(307, `/launch/thanks/${asset}`); }, @@ -53,7 +29,7 @@ export const actions = { let rates = await get('/rates'); let invoice = { - amount: 25000, + amount: 22000, memo: 'launch', network: 'lightning', prompt: false, @@ -66,19 +42,4 @@ export const actions = { throw redirect(307, `/invoice/${uuid}`); }, - bitcoin: () => console.log('YYEAH') }; - -export async function POST({ request }) { - let { address, amount, confirmed } = await request.json(); - if (!confirmed) return; - - if (request.headers.get('x-webhook') !== env.WEBHOOK) { - throw new Error('access denied'); - } - - let username = invoices[address]; - amount = Math.round(amount / 2100); - - await post('/send', { username, asset, amount }, { authorization: `Bearer ${token}` }); -} |
