diff options
| author | Adam Soltys <[email protected]> | 2024-12-30 16:41:12 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-30 16:41:12 -0800 |
| commit | b83b9bf7cd49548c2cd2a15184254816ea8b4003 (patch) | |
| tree | 696c3323b3b41c330cda152ce0f771ca6819762c /src/components | |
| parent | 0349e91841edbd17117e46ae6cf5b342ac3ebe96 (diff) | |
| download | coinos-ui-b83b9bf7cd49548c2cd2a15184254816ea8b4003.tar.gz coinos-ui-b83b9bf7cd49548c2cd2a15184254816ea8b4003.zip | |
fix setmax for take funds
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Lnurlw.svelte | 49 | ||||
| -rw-r--r-- | src/components/Numpad.svelte | 11 |
2 files changed, 48 insertions, 12 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} |
