From 7bd39ca6f942c146a6e21be625c03bef84c1d3ee 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 ++++++++++++++++++++++++++++ static/icon-192x192.png | Bin 0 -> 12678 bytes static/icon-256x256.png | Bin 0 -> 14597 bytes static/icon-384x384.png | Bin 0 -> 35715 bytes static/icon-512x512.png | Bin 0 -> 41410 bytes static/icons/coinos.png | Bin 0 -> 74097 bytes static/icons/logo-symbol.png | Bin 74097 -> 0 bytes static/manifest.json | 17 ++ static/manifest.webmanifest | 32 ++++ 14 files changed, 435 insertions(+), 135 deletions(-) create mode 100644 src/routes/invoice/[id]/tip/+page.server.js create mode 100644 src/routes/invoice/[id]/tip/+page.svelte create mode 100644 static/icon-192x192.png create mode 100644 static/icon-256x256.png create mode 100644 static/icon-384x384.png create mode 100644 static/icon-512x512.png create mode 100644 static/icons/coinos.png delete mode 100644 static/icons/logo-symbol.png create mode 100644 static/manifest.json create mode 100644 static/manifest.webmanifest 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} +
+ + diff --git a/static/icon-192x192.png b/static/icon-192x192.png new file mode 100644 index 00000000..5638c430 Binary files /dev/null and b/static/icon-192x192.png differ diff --git a/static/icon-256x256.png b/static/icon-256x256.png new file mode 100644 index 00000000..45d60ada Binary files /dev/null and b/static/icon-256x256.png differ diff --git a/static/icon-384x384.png b/static/icon-384x384.png new file mode 100644 index 00000000..0ddbcfd7 Binary files /dev/null and b/static/icon-384x384.png differ diff --git a/static/icon-512x512.png b/static/icon-512x512.png new file mode 100644 index 00000000..8fe3bd26 Binary files /dev/null and b/static/icon-512x512.png differ diff --git a/static/icons/coinos.png b/static/icons/coinos.png new file mode 100644 index 00000000..233fcb5c Binary files /dev/null and b/static/icons/coinos.png differ diff --git a/static/icons/logo-symbol.png b/static/icons/logo-symbol.png deleted file mode 100644 index 233fcb5c..00000000 Binary files a/static/icons/logo-symbol.png and /dev/null differ diff --git a/static/manifest.json b/static/manifest.json new file mode 100644 index 00000000..ba1383ab --- /dev/null +++ b/static/manifest.json @@ -0,0 +1,17 @@ +{ + "short_name": "coinos", + "name": "coinos", + "icons": [ + { + "src": "/icons/coinos.png", + "type": "image/webp", + "sizes": "1024x1024", + "purpose": "any maskable" + } + ], + "start_url": "/", + "background_color": "#000000", + "display": "standalone", + "scope": "/", + "theme_color": "#000000" +} diff --git a/static/manifest.webmanifest b/static/manifest.webmanifest new file mode 100644 index 00000000..de84394a --- /dev/null +++ b/static/manifest.webmanifest @@ -0,0 +1,32 @@ +{ + "theme_color": "#fff", + "background_color": "#000", + "display": "fullscreen", + "scope": "/", + "start_url": "/", + "name": "Coinos", + "description": "Bitcoin web wallet", + "short_name": "Coinos", + "icons": [ + { + "src": "/icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icon-256x256.png", + "sizes": "256x256", + "type": "image/png" + }, + { + "src": "/icon-384x384.png", + "sizes": "384x384", + "type": "image/png" + }, + { + "src": "/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} \ No newline at end of file -- cgit v1.2.3