diff options
| author | Adam Soltys <[email protected]> | 2022-10-17 11:11:52 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-17 11:11:52 -0700 |
| commit | 44bee42517e70dce187534dac676f52c7b1f327f (patch) | |
| tree | 78049d1c589dbd09a4cf9eb720e4640f91482950 /src/routes/launch | |
| parent | 87fc33dfa162554b540dfb640ba1c1f66f9132d2 (diff) | |
| download | coinos-ui-44bee42517e70dce187534dac676f52c7b1f327f.tar.gz coinos-ui-44bee42517e70dce187534dac676f52c7b1f327f.zip | |
tickets wip
Diffstat (limited to 'src/routes/launch')
| -rw-r--r-- | src/routes/launch/+page.svelte | 5 | ||||
| -rw-r--r-- | src/routes/launch/purchase/+page.server.js | 31 | ||||
| -rw-r--r-- | src/routes/launch/purchase/+page.svelte | 67 | ||||
| -rw-r--r-- | src/routes/launch/purchase/card/+page.server.js | 37 | ||||
| -rw-r--r-- | src/routes/launch/purchase/card/+page.svelte | 109 | ||||
| -rw-r--r-- | src/routes/launch/ticket/+page.svelte | 5 |
6 files changed, 216 insertions, 38 deletions
diff --git a/src/routes/launch/+page.svelte b/src/routes/launch/+page.svelte index 5e519eff..da1c779c 100644 --- a/src/routes/launch/+page.svelte +++ b/src/routes/launch/+page.svelte @@ -9,8 +9,7 @@ $redirect = '/launch/purchase'; beforeNavigate(({ to }) => { - console.log(link); - if (link === '/register') info('Please sign in so we can get you a ticket'); + if (to.routeId === 'register') info('Please sign in so we can get you a ticket'); }); </script> @@ -30,7 +29,7 @@ </h1> <p class="leading-normal mb-2"> - Come join us at our launch party celebrating 10 years in business! + Come join us at our launch party celebrating our new design and 10 years since our <a href="https://github.com/coinos/coinos-server/commit/b25d11b" class="underline">first commit</a>! </p> <div class="ml-8"> <p><b>When</b></p> diff --git a/src/routes/launch/purchase/+page.server.js b/src/routes/launch/purchase/+page.server.js index 1525034c..03da1e35 100644 --- a/src/routes/launch/purchase/+page.server.js +++ b/src/routes/launch/purchase/+page.server.js @@ -1,10 +1,14 @@ import { auth, get, post } from '$lib/utils'; import tickets from '$lib/tickets'; -export const load = () => get('/ticket'); +export const load = async ({ parent }) => { + let p = await parent(); + let t = await get('/ticket'); + return { ...p, ...t }; +}; export const actions = { - default: async ({ cookies, request }) => { + internal: async ({ cookies, request, parent }) => { let { ticket } = Object.fromEntries(await request.formData()); let r = await post( @@ -22,5 +26,26 @@ export const actions = { ); console.log(r); - } + }, + + lightning: 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: rates[form.get('currency')] + }; + + let user = { username: form.get('username') }; + + let { uuid } = await post('/invoice', { invoice, user }, auth(cookies)); + + throw redirect(307, `/invoice/${uuid}`); + }, + bitcoin: () => console.log('YYEAH') }; diff --git a/src/routes/launch/purchase/+page.svelte b/src/routes/launch/purchase/+page.svelte index ecec51df..68c19076 100644 --- a/src/routes/launch/purchase/+page.svelte +++ b/src/routes/launch/purchase/+page.svelte @@ -9,6 +9,7 @@ let amount = 25000; let { address, + currency, account: { balance }, username } = data.user; @@ -35,17 +36,17 @@ <div class="mx-auto h-screen flex items-center justify-center px-4"> <div class="font-normal text-gray-800 mx-auto mb-8 space-y-8"> - {#if balance > amount} - <h1 class="mb-4 text-4xl font-bold leading-none tracking-tight text-gray-800 text-center"> - Confirm Purchase - </h1> + <h1 class="mb-4 text-4xl font-bold leading-none tracking-tight text-gray-800 text-center"> + Confirm Purchase + </h1> - <img - src={`/tickets/${(ticket + 1).toString().padStart(2, '0')}.png`} - class="w-full max-w-[800px]" - /> + <img + src={`/tickets/${(ticket + 1).toString().padStart(2, '0')}.png`} + class="w-full max-w-[800px]" + /> - <form method="POST" use:enhance> + {#if balance > amount} + <form action="?/internal" method="POST" use:enhance> <input type="hidden" name="ticket" value={ticket} /> <div class="w-full flex"> <button @@ -57,33 +58,35 @@ </form> {:else} <h1 class="mb-4 text-4xl font-bold leading-none tracking-tight text-gray-800 text-center"> - Ticket Price - </h1> - <div class="text-center text-4xl mb-12">{amount} sats</div> - - <h1 class="mb-4 text-4xl font-bold leading-none tracking-tight text-gray-800 text-center"> - Your Balance + Payment Options </h1> - <div class="text-center text-4xl mb-12">{balance} sats</div> - - <h1 class="mb-4 text-4xl font-bold leading-none tracking-tight text-gray-800 text-center"> - Funding Options - </h1> + <form action="?/lightning" method="POST"> + <input type="hidden" name="currency" value={currency} /> + <input type="hidden" name="username" value={username} /> + <button + class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-2xl" + > + Lightning + </button> + </form> - <button - class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-2xl" - on:click={lightning} - > - Lightning - </button> + <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> + </form> - <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> + <a href={`purchase/card`}> + <button + class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-2xl" + > + Credit Card + </button> + </a> {/if} </div> </div> diff --git a/src/routes/launch/purchase/card/+page.server.js b/src/routes/launch/purchase/card/+page.server.js new file mode 100644 index 00000000..1393eecc --- /dev/null +++ b/src/routes/launch/purchase/card/+page.server.js @@ -0,0 +1,37 @@ +let stripe = 'https://api.stripe.com/v1'; + +export const actions = { + default: async ({ request }) => { + let form = await request.formData(); + + let headers = new Headers(); + headers.set( + 'Authorization', + 'Basic ' + new Buffer('sk_test_mBv5bAeAhiYSDYFZJNsDwjht:').toString('base64') + ); + + let body = new URLSearchParams({ + 'card[number]': form.get('number'), + 'card[exp_month]': form.get('expiry').slice(0, 2), + 'card[exp_year]': form.get('expiry').slice(-2), + 'card[cvc]': form.get('cvc') + }); + + let method = 'POST'; + + let { id: source } = await fetch(`${stripe}/tokens`, { body, headers, method }).then((r) => + r.json() + ); + + body = new URLSearchParams({ + amount: 600, + currency: 'cad', + source, + description: 'launch ticket' + }); + + let r = await fetch(`${stripe}/charges`, { body, headers, method }).then((r) => r.json()); + + console.log(r); + } +}; diff --git a/src/routes/launch/purchase/card/+page.svelte b/src/routes/launch/purchase/card/+page.svelte new file mode 100644 index 00000000..73f2d880 --- /dev/null +++ b/src/routes/launch/purchase/card/+page.svelte @@ -0,0 +1,109 @@ +<script> +</script> + +<form method="POST" class="flex flex-wrap gap-3 w-full p-5"> + <label class="relative w-full flex flex-col"> + <span class="font-bold mb-3">Card number</span> + <input + class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300" + type="text" + name="number" + placeholder="0000 0000 0000" + value="4242424242424242" + /> + <svg + xmlns="http://www.w3.org/2000/svg" + class="absolute bottom-0 left-0 -mb-0.5 transform translate-x-1/2 -translate-y-1/2 text-black peer-placeholder-shown:text-gray-300 h-6 w-6" + fill="none" + viewBox="0 0 24 24" + stroke="currentColor" + > + <path + stroke-linecap="round" + stroke-linejoin="round" + stroke-width="2" + d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" + /> + </svg> + </label> + + <label class="relative flex-1 flex flex-col"> + <span class="font-bold mb-3">Expire date</span> + <input + class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300" + type="text" + name="expiry" + placeholder="MM/YY" + value="0123" + /> + <svg + xmlns="http://www.w3.org/2000/svg" + class="absolute bottom-0 left-0 -mb-0.5 transform translate-x-1/2 -translate-y-1/2 text-black peer-placeholder-shown:text-gray-300 h-6 w-6" + fill="none" + viewBox="0 0 24 24" + stroke="currentColor" + > + <path + stroke-linecap="round" + stroke-linejoin="round" + stroke-width="2" + d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" + /> + </svg> + </label> + + <label class="relative flex-1 flex flex-col"> + <span class="font-bold flex items-center gap-3 mb-3"> + CVC/CVV + <span class="relative group"> + <span + class="hidden group-hover:flex justify-center items-center px-2 py-1 text-xs absolute -right-2 transform translate-x-full -translate-y-1/2 w-max top-1/2 bg-black text-white" + > + 3-digit number on the back of your card</span + > + <svg + xmlns="http://www.w3.org/2000/svg" + class="h-4 w-4" + fill="none" + viewBox="0 0 24 24" + stroke="currentColor" + > + <path + stroke-linecap="round" + stroke-linejoin="round" + stroke-width="2" + d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" + /> + </svg> + </span> + </span> + <input + class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300" + type="text" + name="cvc" + placeholder="•••" + value="123" + /> + <svg + xmlns="http://www.w3.org/2000/svg" + class="absolute bottom-0 left-0 -mb-0.5 transform translate-x-1/2 -translate-y-1/2 text-black peer-placeholder-shown:text-gray-300 h-6 w-6" + fill="none" + viewBox="0 0 24 24" + stroke="currentColor" + > + <path + stroke-linecap="round" + stroke-linejoin="round" + stroke-width="2" + d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" + /> + </svg> + </label> + + <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" + type="submit">Submit</button> + </div> +</form> diff --git a/src/routes/launch/ticket/+page.svelte b/src/routes/launch/ticket/+page.svelte new file mode 100644 index 00000000..acf3b7a5 --- /dev/null +++ b/src/routes/launch/ticket/+page.svelte @@ -0,0 +1,5 @@ + + <img + src={`/tickets/${(ticket + 1).toString().padStart(2, '0')}.png`} + class="w-full max-w-[800px]" + /> |
