diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Lnurlw.svelte | 49 | ||||
| -rw-r--r-- | src/components/Numpad.svelte | 11 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/withdraw/+page.svelte | 9 |
3 files changed, 53 insertions, 16 deletions
diff --git a/src/components/Lnurlw.svelte b/src/components/Lnurlw.svelte index 8793d3b4..932a6c04 100644 --- a/src/components/Lnurlw.svelte +++ b/src/components/Lnurlw.svelte @@ -1,10 +1,12 @@ <script> + import { tick } from "svelte"; + import handler from "$lib/handler"; import { sats, f, s } from "$lib/utils"; import { t } from "$lib/translations"; import { enhance } from "$app/forms"; import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; - import { pin } from "$lib/store"; + import { fiat, pin } from "$lib/store"; let { data, form } = $props(); @@ -18,11 +20,19 @@ rate, } = data; - let amount = $state(Math.round(minWithdrawable / 1000)), - loading = $state(); - - let submit = () => (loading = true); + let amount = $state(Math.round(minWithdrawable / 1000)); let amountFiat = $derived(parseFloat(((amount * rate) / sats).toFixed(2))); + + let submit = $state(); + let submitting = $state(); + let toggle = () => (submitting = !submitting); + + let setMax = async (e) => { + e.preventDefault(); + $fiat = false; + await tick(); + amount = maxWithdrawable; + }; </script> <div class="container px-4 mt-20 max-w-xl mx-auto"> @@ -55,7 +65,13 @@ <Numpad bind:amount {currency} {rate} /> {/if} - <form action="?/withdraw" method="POST" use:enhance onsubmit={submit} class="space-y-5"> + <form + use:enhance={handler(toggle)} + action="?/withdraw" + method="POST" + onsubmit={submit} + class="space-y-5" + > <input name="amount" value={amount} type="hidden" /> <input name="username" value={username} type="hidden" /> <input name="currency" value={currency} type="hidden" /> @@ -64,12 +80,25 @@ <input name="callback" value={callback} type="hidden" /> <input name="k1" value={k1} type="hidden" /> - <div class="flex w-full"> - <button type="submit" class="btn btn-accent"> - {#if loading} + <div class="flex gap-2"> + <button + type="button" + class="btn !w-auto grow" + onclick={setMax} + disabled={submitting} + onkeydown={setMax}>Max ⚡️{s(balance)}</button + > + + <button + use:focus + bind:this={submit} + type="submit" + class="btn btn-accent !w-auto grow" + > + {#if submitting} <Spinner /> {:else} - {$t("payments.withdraw")} + <div class="my-auto">{$t("payments.next")}</div> {/if} </button> </div> diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index f79f749a..e69caf87 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -53,6 +53,7 @@ let update = (a, f) => { if ($fiat) { amount = f ? Math.round(strip(f) / (rate / sats)) : 0; + console.log("settung amount", amount, f); } else { amountFiat = a ? ((a * rate) / sats).toFixed(2) : 0; } @@ -203,7 +204,10 @@ {symbol} {/if} {:else} - <iconify-icon noobserver icon="ph:lightning-fill" class="text-yellow-300" + <iconify-icon + noobserver + icon="ph:lightning-fill" + class="text-yellow-300" ></iconify-icon> {/if} </div> @@ -228,7 +232,10 @@ on:click|preventDefault|stopPropagation={swap} > {#if $fiat} - <iconify-icon noobserver icon="ph:lightning-fill" class="text-yellow-300" + <iconify-icon + noobserver + icon="ph:lightning-fill" + class="text-yellow-300" ></iconify-icon> {s(amount, locale)} {:else} diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte index f6f12b1a..78f9b16c 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.svelte +++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte @@ -1,4 +1,5 @@ <script> + import { tick } from "svelte"; import handler from "$lib/handler"; import { t } from "$lib/translations"; import { enhance } from "$app/forms"; @@ -6,7 +7,7 @@ import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; import { s } from "$lib/utils"; - import { pin } from "$lib/store"; + import { fiat, pin } from "$lib/store"; let { data, form } = $props(); @@ -14,7 +15,6 @@ let loading = $state(); let { id, balance, rate } = $derived(data); let { amount } = $state(data); - let fiat = $state(); let submit = $state(); let submitting = $state(); @@ -24,9 +24,10 @@ loading = false; }); - let setMax = (e) => { + let setMax = async (e) => { e.preventDefault(); - fiat = false; + $fiat = false; + await tick(); amount = balance; }; </script> |
