From 44664658d460ba2bee41aa87dbbb3f81ef232402 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 1 Aug 2022 11:44:56 -0700 Subject: display qr on invoice page refresh --- src/routes/invoice/[id].svelte | 49 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/routes/invoice/[id].svelte b/src/routes/invoice/[id].svelte index d9b1540e..d5a39daa 100644 --- a/src/routes/invoice/[id].svelte +++ b/src/routes/invoice/[id].svelte @@ -10,6 +10,7 @@ $: amountFiat = parseFloat(((amount * rate) / 100000000).toFixed(2)); let tipPercent = 0; + let qr; $: tipAmount = customTipAmount ? customTipAmount < 0 @@ -62,29 +63,29 @@ customTipAmount = e.target.value; }; - onMount(async () => { - if (browser) { - let { default: QRCodeStyling } = await import('qr-code-styling'); - console.log("text", text) - const qrCode = new QRCodeStyling({ - width: window.screen.width < 640 ? 250 : 300, - type: 'svg', - data: text, - image: '/images/invoice.svg', - backgroundOptions: { - color: 'rgba(0, 0, 0, 0)' - }, - dotsOptions: { - type: 'rounded' - }, - imageOptions: { - hideBackgroundDots: false - } - }); - - qrCode.append(document.getElementById('qr')); - } - }); + $: init(browser && $user); + let init = async (ready) => { + if (!ready) return; + let { default: QRCodeStyling } = await import('qr-code-styling'); + console.log('text', text); + const qrCode = new QRCodeStyling({ + width: window.screen.width < 640 ? 250 : 300, + type: 'svg', + data: text, + image: '/images/invoice.svg', + backgroundOptions: { + color: 'rgba(0, 0, 0, 0)' + }, + dotsOptions: { + type: 'rounded' + }, + imageOptions: { + hideBackgroundDots: false + } + }); + + qrCode.append(qr); + }; let showMobileTip = false; @@ -222,7 +223,7 @@ >