aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Lnurlp.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Lnurlp.svelte')
-rw-r--r--src/components/Lnurlp.svelte22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/components/Lnurlp.svelte b/src/components/Lnurlp.svelte
index 8f14ddff..c1ae0c95 100644
--- a/src/components/Lnurlp.svelte
+++ b/src/components/Lnurlp.svelte
@@ -6,15 +6,19 @@
import Numpad from "$comp/Numpad.svelte";
import Spinner from "$comp/Spinner.svelte";
import { pin } from "$lib/store";
+ import { s } from "$lib/utils";
let { data, form, send = $bindable(), comment = $bindable() } = $props();
let { currency } = data.user;
- let { minSendable, maxSendable, commentAllowed, callback, metadata, rate } =
+ let { minSendable, maxSendable, commentAllowed, callback, metadata, rate, balance } =
data;
+ let max = $derived(Math.min(balance || 0, Math.floor(maxSendable / 1000)));
let amount = $state(Math.round(minSendable / 1000)),
loading = $state();
let submit = () => (loading = true);
+ // An action result (an error, since success redirects) ends the wait
+ $effect(() => form && (loading = false));
</script>
<div class="container px-4 mt-20 max-w-xl mx-auto space-y-2">
@@ -56,8 +60,20 @@
></textarea>
{/if}
- <div class="flex w-full">
- <button bind:this={send} type="submit" class="btn">
+ <div class="flex w-full gap-2">
+ {#if max >= Math.round(minSendable / 1000)}
+ <!-- loading is set by the form's onsubmit, not here: flipping
+ `disabled` from a click handler lands in the DOM before the
+ browser's submit activation runs, and a disabled button submits
+ nothing (the page just sat on a spinner). -->
+ <button
+ type="submit"
+ class="btn !w-auto grow"
+ formaction="?/max"
+ disabled={loading}>Max ⚡️{s(max)}</button
+ >
+ {/if}
+ <button bind:this={send} type="submit" class="btn btn-accent !w-auto grow">
{#if loading}
<Spinner />
{:else}