diff options
| author | Adam Soltys <[email protected]> | 2022-10-18 21:03:27 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-18 21:03:27 -0700 |
| commit | ad24f34434368d3767fd147d80d45adc3c28f106 (patch) | |
| tree | f98eea88a95a2c1fbe79283cfa3f77e4ff737449 /src/routes/launch/purchase | |
| parent | 02af363d2f0d552a72dc1c90bf8d785e04465d3a (diff) | |
| download | coinos-ui-ad24f34434368d3767fd147d80d45adc3c28f106.tar.gz coinos-ui-ad24f34434368d3767fd147d80d45adc3c28f106.zip | |
tickets wip
Diffstat (limited to 'src/routes/launch/purchase')
| -rw-r--r-- | src/routes/launch/purchase/+page.server.js | 19 | ||||
| -rw-r--r-- | src/routes/launch/purchase/+page.svelte | 28 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/routes/launch/purchase/+page.server.js b/src/routes/launch/purchase/+page.server.js index ff5efc84..3317b420 100644 --- a/src/routes/launch/purchase/+page.server.js +++ b/src/routes/launch/purchase/+page.server.js @@ -7,16 +7,29 @@ import { browser } from '$app/environment'; export const load = async ({ parent }) => { let tickets = await get('/tickets'); - return { ...(await parent()), 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 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, @@ -25,9 +38,10 @@ export const actions = { domain: 'coinos.io', filename: tickets[ticket] }, - auth(cookies) + { authorization: `Bearer ${env.LAUNCH}` } ); + await post('/send', { amount: 25000, username: 'launch' }, auth(cookies)); await post('/ticket', { asset }, { authorization: `Bearer ${env.LAUNCH}` }); throw redirect(307, `/launch/thanks/${asset}`); @@ -40,6 +54,7 @@ export const actions = { let invoice = { amount: 25000, + memo: 'launch', network: 'lightning', prompt: false, rate: rates[form.get('currency')] diff --git a/src/routes/launch/purchase/+page.svelte b/src/routes/launch/purchase/+page.svelte index d31d20f0..d78b95d2 100644 --- a/src/routes/launch/purchase/+page.svelte +++ b/src/routes/launch/purchase/+page.svelte @@ -1,6 +1,7 @@ <script> + import { onMount } from 'svelte'; import { enhance } from '$app/forms'; - import { invoiceRedirect, selectedRate } from '$lib/store'; + import { selectedRate } from '$lib/store'; import { post } from '$lib/utils'; import { goto } from '$app/navigation'; @@ -8,7 +9,6 @@ let amount = 25000; let { - address, currency, account: { balance }, username @@ -16,24 +16,6 @@ let { tickets } = data; let ticket = tickets.length; - - let invoice; - let get = async (network) => { - let { uuid } = await post('/invoice', { - amount, - rate: $selectedRate, - network, - username - }); - - $invoiceRedirect = '/launch/purchase'; - goto(`/invoice/${uuid}`); - }; - - let lightning = () => get('lightning'); - let bitcoin = () => get('bitcoin'); - - // if (balance < amount) throw redirect(307, `/${username}/fund/${amount - balance}`); </script> <div class="mx-auto h-screen flex items-center justify-center px-4"> @@ -48,9 +30,10 @@ alt="Ticket" /> - {#if balance > amount} + {#if balance >= amount} <form action="?/internal" method="POST" use:enhance> - <input type="hidden" name="ticket" value={ticket} /> + <input type="hidden" name="username" value={username} /> + <div class="w-full flex"> <button class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-2xl" @@ -77,7 +60,6 @@ <form action="?/bitcoin" method="POST"> <button class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-2xl" - on:click={bitcoin} > Bitcoin </button> |
