From 0a03fc6e5f7025eef53565b20d19d4614733ff42 Mon Sep 17 00:00:00 2001 From: secondl1ght <85003930+secondl1ght@users.noreply.github.com> Date: Sat, 17 Sep 2022 08:49:48 -0600 Subject: refactor add tip section to optimize for mobile and other feedback --- src/routes/invoice/[id]/+page.svelte | 166 +++++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 68 deletions(-) (limited to 'src/routes') diff --git a/src/routes/invoice/[id]/+page.svelte b/src/routes/invoice/[id]/+page.svelte index 3f96bf06..b4550814 100644 --- a/src/routes/invoice/[id]/+page.svelte +++ b/src/routes/invoice/[id]/+page.svelte @@ -20,6 +20,8 @@ user: { username, currency } } = invoice; + let showCustomAmount = false; + let image = '/images/invoice.svg'; let qr; let tipPercent = 0; @@ -55,9 +57,12 @@ $: totalAmountSats = s(amount + parseFloat(tipAmountSats.replace(/,/g, ''))); let apply = async () => { - tipPercent = (customTipAmount / amountFiat) * 100; - update(); - showMobileTip = false; + if (customTipAmount > 0) { + tipPercent = (customTipAmount / amountFiat) * 100; + update(); + showMobileTip = false; + showCustomAmount = false; + } }; let update = async () => { @@ -86,22 +91,27 @@ let timeout; const handleSlide = (e) => { customTipAmount = ''; - customInput.value = ''; + if (customInput) { + customInput.value = ''; + } tipPercent = e.target.value; + clearTimeout(timeout); timeout = setTimeout(update, 100); }; const handleTipButtonClick = (amount) => { customTipAmount = ''; - customInput.value = ''; + if (customInput) { + customInput.value = ''; + } if (amount === 'None') { tipPercent = 0; } else { tipPercent = parseInt(amount.slice(0, 2)); } - + showMobileTip = false; update(); }; @@ -113,15 +123,18 @@ let showMobileTip = false; const handleBackButton = () => { - if (showMobileTip) { - tipPercent = 0; + goto(`/${username}/receive`); + }; + + const handleMobileClose = () => { + tipPercent = 0; + if (customInput) { customInput.value = ''; - customTipAmount = 0; - tipAmount = 0; - showMobileTip = false; - } else { - goto(`/${username}/receive`); } + customTipAmount = 0; + tipAmount = 0; + showMobileTip = false; + showCustomAmount = false; }; let customInput; @@ -146,6 +159,7 @@ - {Math.round(tipPercent)}% - - - -
- {#each tipAmounts as amount} - {$t('invoice.addTipq')} + {#if !showCustomAmount} +
+ {tipAmountFormatted}{`(${tipAmountSats} SAT)`} - {/each} + {Math.round(tipPercent)}% +
-
- $ - handleCustomTipAmount(e)} - class="pl-10" - placeholder="Other" - /> - + {/each} + {/if} + {#if showCustomAmount} +
+ Apply - -
+ : 'opacity-100'}">$ + handleCustomTipAmount(e)} + class="pl-10" + placeholder="Other" + /> + + +
+ {:else} +
+ +
+ {/if}
@@ -262,7 +292,7 @@ >
- +
-- cgit v1.2.3