diff options
| author | Adam Soltys <[email protected]> | 2023-02-15 22:47:27 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-15 22:47:27 -0800 |
| commit | af598ffa4432706fd518c2fedd6b685f52fd1ae1 (patch) | |
| tree | 013bd0cac2d9a02ea343f86ba40f131f5ec7e8fe /src/routes/(app)/buy/+page.server.js | |
| parent | 2f33da23a44773fb1728bd2405abf2faae33bea8 (diff) | |
| download | coinos-ui-af598ffa4432706fd518c2fedd6b685f52fd1ae1.tar.gz coinos-ui-af598ffa4432706fd518c2fedd6b685f52fd1ae1.zip | |
buy page
Diffstat (limited to 'src/routes/(app)/buy/+page.server.js')
| -rw-r--r-- | src/routes/(app)/buy/+page.server.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/routes/(app)/buy/+page.server.js b/src/routes/(app)/buy/+page.server.js index e03d6c0a..8a88ed4e 100644 --- a/src/routes/(app)/buy/+page.server.js +++ b/src/routes/(app)/buy/+page.server.js @@ -1,5 +1,5 @@ import { env } from '$env/dynamic/private'; -import { error, redirect } from '@sveltejs/kit'; +import { error, fail, redirect } from '@sveltejs/kit'; import { post, auth } from '$lib/utils'; import { createTicket } from '$lib/ticket'; @@ -7,13 +7,21 @@ export const actions = { default: async ({ cookies, request }) => { let form = await request.formData(); - await post('/buy', { - number: form.get('number').replace(/\s+/g, ''), - month: form.get('expiry').slice(0, 2), - year: form.get('expiry').slice(-2), - cvc: form.get('cvc') - }, auth(cookies)); + let amount = parseFloat(form.get('amount')); + if (!amount || amount < 0 || amount > 500) return fail(400, { message: 'Invalid amount' }); - throw redirect(307, `/launch/thanks/${asset}`); + await post( + '/buy', + { + amount: form.get('amount'), + number: form.get('number').replace(/\s+/g, ''), + month: form.get('expiry').slice(0, 2), + year: form.get('expiry').slice(-2), + cvc: form.get('cvc') + }, + auth(cookies) + ); + + throw redirect(307, `/${form.get('username')}/payments`); } }; |
