From 2761363d694d3f24600abbe656769f64d7a67605 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 25 Nov 2024 22:13:04 -0800 Subject: fix amount prompt --- src/components/SetAmount.svelte | 14 ++++++-------- src/routes/(app)/[username]/receive/+page.svelte | 23 +++++++++++++---------- src/routes/(app)/invoice/[id]/+page.svelte | 11 ++++++++--- 3 files changed, 27 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/components/SetAmount.svelte b/src/components/SetAmount.svelte index 332c2eca..5b703896 100644 --- a/src/components/SetAmount.svelte +++ b/src/components/SetAmount.svelte @@ -1,6 +1,5 @@ @@ -25,13 +23,13 @@
-
+
@@ -49,7 +47,7 @@
{t("payments.amountPrompt")}
- +
diff --git a/src/routes/(app)/[username]/receive/+page.svelte b/src/routes/(app)/[username]/receive/+page.svelte index be4ed3d0..ddb17e71 100644 --- a/src/routes/(app)/[username]/receive/+page.svelte +++ b/src/routes/(app)/[username]/receive/+page.svelte @@ -16,10 +16,8 @@ let showOptions; - let { id, rates, subject, user, src, text } = $state(data); - let refresh = (data) => { - ({ id, rates, subject, user, src, text } = data); - }; + let { id, rates, subject, user, text } = $state(data); + let { src } = $derived(data); let { currency, username } = subject; let rate = rates[currency]; @@ -52,12 +50,17 @@ }); }; - let setAmount = async () => { - if (typeof $amountPrompt === "undefined") $amountPrompt = true; + let setAmount = async (e) => { + e.preventDefault(); + e.stopPropagation(); + settingAmount = false; + + if (typeof $amountPrompt === "undefined") $amountPrompt = true; amount = newAmount; invoice.amount = newAmount; invoice.tip = 0; + ({ id } = await post(`/invoice`, { invoice, user: { username, currency }, @@ -75,15 +78,16 @@ let fiat = $state(true); let toggleAmount = () => (settingAmount = !settingAmount); let submit; - run(() => { - refresh(data); - }); let link = $derived( [types.bitcoin, types.liquid].includes(type) ? text : `lightning:${text}`, ); let txt = $derived( [types.bitcoin, types.liquid].includes(type) ? hash : text, ); + + onMount(() => { + if ($amountPrompt && !amount) toggleAmount(); + });
@@ -126,6 +130,5 @@ {settingAmount} {setAmount} {toggleAmount} - amountPrompt={$amountPrompt} t={$t} /> diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index 15dc97ae..8c6e2b75 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -65,11 +65,16 @@ goto(`./${id}?options=true`, { invalidateAll: true, noScroll: true }); }; - let setAmount = $state(async () => { - if (typeof $amountPrompt === "undefined") $amountPrompt = true; + let setAmount = async (e) => { + e.preventDefault(); + e.stopPropagation(); + settingAmount = false; + + if (typeof $amountPrompt === "undefined") $amountPrompt = true; invoice.amount = newAmount; invoice.tip = 0; + ({ id } = await post(`/invoice`, { invoice, user: { username, currency }, @@ -80,7 +85,7 @@ else url += "?options=true"; goto(url, { invalidateAll: true, noScroll: true }); - }); + }; let newAmount = $state(0); let settingAmount = $state(); -- cgit v1.2.3