From 363f1b23d00ec8ec1e4d6b66afa2b28f87e45902 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 31 Oct 2022 23:15:37 -0700 Subject: server side qr --- src/lib/invoice.js | 2 +- src/routes/invoice/[id]/+layout.server.js | 10 ++- src/routes/invoice/[id]/+page.svelte | 110 ++++++++++++++++-------------- 3 files changed, 68 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/lib/invoice.js b/src/lib/invoice.js index e8a5f615..b1330f89 100644 --- a/src/lib/invoice.js +++ b/src/lib/invoice.js @@ -16,7 +16,7 @@ export default async ({ cookies, request }) => { let user = { username: form.get('username') }; - let { uuid } = await post('/invoice', { invoice, user }, auth(cookies)); + let { uuid }= await post('/invoice', { invoice, user }, auth(cookies)); if (invoice.prompt) { throw redirect(307, `/invoice/${uuid}/tip`); diff --git a/src/routes/invoice/[id]/+layout.server.js b/src/routes/invoice/[id]/+layout.server.js index e123c7d7..690deda0 100644 --- a/src/routes/invoice/[id]/+layout.server.js +++ b/src/routes/invoice/[id]/+layout.server.js @@ -1,6 +1,14 @@ +import Qr from 'qrcode-svg'; import { get } from '$lib/utils'; export async function load({ params }) { let { id } = params; - return { id, invoice: await get(`/invoice?uuid=${id}`) }; + let invoice = await get(`/invoice?uuid=${id}`); + let svg = new Qr({ + content: invoice.text, + join: true, + container: 'svg-viewbox' + }).svg(); + + return { id, invoice, svg }; } diff --git a/src/routes/invoice/[id]/+page.svelte b/src/routes/invoice/[id]/+page.svelte index 17eac2f5..7a888d5c 100644 --- a/src/routes/invoice/[id]/+page.svelte +++ b/src/routes/invoice/[id]/+page.svelte @@ -6,10 +6,11 @@ import { Icon, Heart, Image, Qr } from '$comp'; import { goto } from '$app/navigation'; import { t } from '$lib/translations'; + import screenfull from 'screenfull'; export let data; $: refresh(data); - let { invoice, id, user } = data; + let { invoice, id, user, svg } = data; let { amount, rate, @@ -23,8 +24,6 @@ let qr; let tipPercent = 0; - let fullscreen; - let refresh = (data) => { ({ invoice, id } = data); ({ @@ -47,65 +46,72 @@ $: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2)); $: tipAmount = ((tip * rate) / sats).toFixed(2); + + let full = () => { + screenfull.toggle(qr); + let el = document.getElementById('qr'); + el.style.width = '300px'; + console.log('yes', el); + }; -
- + -
-
-
- Scan to pay {username} +
+
+
+ Scan to pay {username} - - -
- +
+
+ {@html svg}
+
-
- {#if invoice.tip} -
- {$t('invoice.invoice')} - {f(amountFiat, currency)} - {`(${s(amount)} SAT)`} -
+
+ +
-
- {$t('invoice.tip')} - {f(tipAmount, currency)} - {`(${s(tip)} SAT)`} -
- {/if} +
+ {#if invoice.tip} +
+ {$t('invoice.invoice')} + {f(amountFiat, currency)} + {`(${s(amount)} SAT)`} +
-
- {$t('invoice.total')} - {f(amountFiat + parseFloat(tipAmount), currency)} - {`(${s(tip + amount)} SAT)`} + {$t('invoice.tip')} + {f(tipAmount, currency)} + {`(${s(tip)} SAT)`}
+ {/if} + +
+ {$t('invoice.total')} + {f(amountFiat + parseFloat(tipAmount), currency)} + {`(${s(tip + amount)} SAT)`}
-- cgit v1.2.3