From 50b270db6fda60b5b3e39a9dbada5c27a14cbad1 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 22 Feb 2023 19:38:55 -0800 Subject: fee slider wip --- .../bitcoin/[address]/[...amount]/+page.server.js | 18 +++--- .../bitcoin/[address]/[...amount]/+page.svelte | 70 +++++++++++++++++----- src/routes/(app)/send/invoice/[id]/+page.server.js | 4 +- .../(app)/send/lightning/[payreq]/+page.server.js | 4 +- .../send/pot/[name]/[...amount]/+page.server.js | 2 +- .../user/[username]/[...amount]/+page.server.js | 4 +- 6 files changed, 72 insertions(+), 30 deletions(-) (limited to 'src/routes/(app)/send') diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js index 59e9326d..7b1900cc 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js @@ -1,22 +1,26 @@ import { fail, redirect } from '@sveltejs/kit'; -import { auth, post } from '$lib/utils'; +import { auth, post, fd } from '$lib/utils'; let seen = {}; export const actions = { default: async ({ cookies, request }) => { try { - let feeRate, subtract; - let { address, amount, pin, ts } = Object.fromEntries(await request.formData()); - + let { address, amount, confirmed, feeRate, subtract, pin, stale, ts } = await await fd(request); if (seen[ts]) return fail(400, { message: 'Duplicate form submission' }); - seen[ts] = 1; - setTimeout(() => delete seen[ts], 30000); - let { tx } = await post( + let estimate = await post( '/bitcoin/fee', { address, amount, feeRate, subtract }, auth(cookies) ); + + let { tx } = estimate; + + if (stale || !confirmed) return fail(400, estimate); + + seen[ts] = 1; + setTimeout(() => delete seen[ts], 30000); + await post('/bitcoin/send', { pin, tx }, auth(cookies)); } catch (e) { return fail(400, { message: e.message }); diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index cabe895f..3fb7cefb 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -1,31 +1,44 @@ + {#if !confirmed} + + {/if} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js index 2df19985..0ae097af 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.js +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -1,5 +1,5 @@ import { error, fail, redirect } from '@sveltejs/kit'; -import { btc as asset, auth, get, post } from '$lib/utils'; +import { fd, btc as asset, auth, get, post } from '$lib/utils'; export async function load({ params: { id }, parent }) { let { user } = await parent(); @@ -13,7 +13,7 @@ export async function load({ params: { id }, parent }) { export const actions = { default: async ({ cookies, params: { hash }, request }) => { try { - let body = Object.fromEntries(await request.formData()); + let body = await fd(request); let { confirmed } = body; body.amount = parseInt(body.amount); body.hash = hash; diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.server.js b/src/routes/(app)/send/lightning/[payreq]/+page.server.js index 90e6c0cc..e9e2b12a 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.server.js +++ b/src/routes/(app)/send/lightning/[payreq]/+page.server.js @@ -7,12 +7,12 @@ export async function load({ params }) { export const actions = { setAmount: async ({ cookies, request }) => { - return Object.fromEntries(await request.formData()); + return await fd(request); }, send: async ({ cookies, request }) => { try { - let body = Object.fromEntries(await request.formData()); + let body = await fd(request); let { amount, confirmed } = body; if (!confirmed) { diff --git a/src/routes/(app)/send/pot/[name]/[...amount]/+page.server.js b/src/routes/(app)/send/pot/[name]/[...amount]/+page.server.js index 0e1b7f5b..6c11811c 100644 --- a/src/routes/(app)/send/pot/[name]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/pot/[name]/[...amount]/+page.server.js @@ -3,7 +3,7 @@ import { auth, post } from '$lib/utils'; export const actions = { default: async ({ cookies, request }) => { - let body = Object.fromEntries(await request.formData()); + let body = await fd(request); let p; try { diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js index 42b47c8f..40c2d919 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -1,5 +1,5 @@ import { error, fail, redirect } from '@sveltejs/kit'; -import { btc as asset, auth, get, post } from '$lib/utils'; +import { fd, btc as asset, auth, get, post } from '$lib/utils'; export async function load({ params, parent }) { let { user } = await parent(); @@ -12,7 +12,7 @@ export async function load({ params, parent }) { export const actions = { default: async ({ cookies, request }) => { try { - let body = Object.fromEntries(await request.formData()); + let body = await fd(request); let { amount, confirmed } = body; amount = parseInt(amount); -- cgit v1.2.3