From 18efd3bec24d2beb1fcb5ffa5e4492af7fc3e1df Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 30 Oct 2022 22:11:10 -0700 Subject: revamped tip prompt --- src/components/Tip.svelte | 200 +++++++++++---------- src/lib/invoice.js | 8 +- src/routes/[username]/receive/+page.svelte | 3 +- src/routes/invoice/[id]/+page.svelte | 44 +---- src/routes/invoice/[id]/tip/+page.server.js | 5 + src/routes/invoice/[id]/tip/+page.svelte | 261 ++++++++++++++++++++++++++++ 6 files changed, 386 insertions(+), 135 deletions(-) create mode 100644 src/routes/invoice/[id]/tip/+page.server.js create mode 100644 src/routes/invoice/[id]/tip/+page.svelte (limited to 'src') diff --git a/src/components/Tip.svelte b/src/components/Tip.svelte index 6af1e00a..c915da80 100644 --- a/src/components/Tip.svelte +++ b/src/components/Tip.svelte @@ -6,9 +6,9 @@ import { tick } from 'svelte'; import { goto } from '$app/navigation'; - export let amountFiat, showMobileTip, tipPercent, tipAmount, amount, currency, tip, username; + export let amountFiat, showMobileTip, tipPercent, tipAmount, amount, currency, tip, username, rate; - const tipAmounts = ['None', '10%', '15%', '20%']; + const tipAmounts = ['No thanks', '10%', '15%', '20%']; let showCustomAmount; let customInput; @@ -19,10 +19,12 @@ tipPercent = (customTipAmount / amountFiat) * 100; showMobileTip = false; showCustomAmount = false; - update(); } }; + let active = (amount) => + !customTipAmount && Math.round(tipPercent) === parseInt(amount.slice(0, 2)); + const handleCustomTipAmount = (e) => { tipPercent = 0; customTipAmount = e.target.value; @@ -40,116 +42,126 @@ timeout = setTimeout(update, 800); }; - const handleTipButtonClick = (amount) => { - customTipAmount = ''; - if (customInput) { - customInput.value = ''; - } - - if (amount === 'None') { + let submitting; + const handleTipButtonClick = async (amount) => { + submitting = true; + if (amount === 'No thanks') { tipPercent = 0; } else { tipPercent = parseInt(amount.slice(0, 2)); } - showMobileTip = false; - update(); + + await tick(); + submit.click(); }; let submit; let update = async () => { await tick(); - submit.click(); + //submit.click(); }; -
-
- - - - - -

{$t('invoice.addTipq')}

- {#if !showCustomAmount} -
- {f(tipAmount, currency)} - {`(${s(tip)} SAT)`} -
{Math.round(tipPercent)}%
+ + + + + + + +

{$t('invoice.addTipq')}

+ {#if !showCustomAmount} +
{Math.round(tipPercent)}%
+ + (showMobileTip = false)} + /> + +
+
+ + {f(amountFiat, currency)} + +{f(tipAmount, currency)}
- (showMobileTip = false)} - /> - {#each tipAmounts as amount} +
+ {s(amount)} + +{s(tip)} SAT +
+
+ + {#if tip} +
submit.click()}>Next - {/each} - -
(tipPercent = 0)}>Reset
- {/if} - - handleTipButtonClick(amount)}>{amount} - -
- + {/each} + {/if} + +
+ +
{/if} -
- + +{/if} diff --git a/src/lib/invoice.js b/src/lib/invoice.js index 1212cbe3..e8a5f615 100644 --- a/src/lib/invoice.js +++ b/src/lib/invoice.js @@ -11,12 +11,16 @@ export default async ({ cookies, request }) => { tip: parseInt(form.get('tip')), network: 'lightning', prompt: form.get('prompt') === 'true', - rate: rates[form.get('currency')] + rate: parseFloat(form.get('rate')) || rates[form.get('currency')] }; let user = { username: form.get('username') }; let { uuid } = await post('/invoice', { invoice, user }, auth(cookies)); - throw redirect(307, `/invoice/${uuid}`); + if (invoice.prompt) { + throw redirect(307, `/invoice/${uuid}/tip`); + } else { + throw redirect(307, `/invoice/${uuid}`); + } }; diff --git a/src/routes/[username]/receive/+page.svelte b/src/routes/[username]/receive/+page.svelte index 7b0562d5..7425740a 100644 --- a/src/routes/[username]/receive/+page.svelte +++ b/src/routes/[username]/receive/+page.svelte @@ -24,8 +24,7 @@ : 'opacity-100 hover:opacity-80'}" disabled={!amount} > - - {$t('user.receive.showQR')} + Next
diff --git a/src/routes/invoice/[id]/+page.svelte b/src/routes/invoice/[id]/+page.svelte index 84b03593..7dd6d51c 100644 --- a/src/routes/invoice/[id]/+page.svelte +++ b/src/routes/invoice/[id]/+page.svelte @@ -1,5 +1,5 @@ -
+
@@ -69,40 +61,14 @@
- {#if invoice.prompt} - - {/if} - -
- - - Scan to pay {username} - +
diff --git a/src/routes/invoice/[id]/tip/+page.server.js b/src/routes/invoice/[id]/tip/+page.server.js new file mode 100644 index 00000000..1068f273 --- /dev/null +++ b/src/routes/invoice/[id]/tip/+page.server.js @@ -0,0 +1,5 @@ +import invoice from '$lib/invoice'; + +export const actions = { + default: invoice +}; diff --git a/src/routes/invoice/[id]/tip/+page.svelte b/src/routes/invoice/[id]/tip/+page.svelte new file mode 100644 index 00000000..26eeba31 --- /dev/null +++ b/src/routes/invoice/[id]/tip/+page.svelte @@ -0,0 +1,261 @@ + + + + +
+
+ + + + + + +

{$t('invoice.addTipq')}

+ {#if !showCustomAmount} +
{Math.round(tipPercent)}%
+ + + +
+
+ + {f(amountFiat, currency)} + +{f(tipAmount, currency)} +
+ +
+ {s(amount)} + +{s(tip)} SAT +
+
+ + {#if tip} +
+ + +
+ {:else} + {#each tipAmounts as amount} + + {/each} + {/if} + +
+ +
+ {/if} + +
+
+ + {/if} +
+ + -- cgit v1.2.3