From fbf6c6cfaad34b468611931043eba93a48e347d1 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 14 Aug 2024 13:13:41 +0700 Subject: [PATCH 1/2] fix: use canvas QR instead of data URL to prevent CSP error --- src/components/pages/bc-send-payment.ts | 38 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/components/pages/bc-send-payment.ts b/src/components/pages/bc-send-payment.ts index 49cdb8e..e69d479 100644 --- a/src/components/pages/bc-send-payment.ts +++ b/src/components/pages/bc-send-payment.ts @@ -199,25 +199,45 @@ export class SendPayment extends withTwind()(BitcoinConnectElement) { return null; } - const errorCorrectionLevel = 'L'; - const qr = qrcode(0, errorCorrectionLevel); - qr.addData(this.invoice); - qr.make(); + const invoice = this.invoice; + + // wait for the canvas to be added to the dom, then render it + setTimeout(() => { + const canvas = this.shadowRoot?.getElementById('qr') as HTMLCanvasElement; + if (!canvas) { + console.error('qr canvas not found'); + return; + } + const ctx = canvas.getContext('2d'); + if (!ctx) { + console.error('could not get context for qr canvas'); + return; + } + + const errorCorrectionLevel = 'L'; + const qr = qrcode(0, errorCorrectionLevel); + qr.addData(invoice); + qr.make(); + const moduleCount = qr.getModuleCount(); + canvas.width = moduleCount * 4; + canvas.height = moduleCount * 4; + qr.renderTo2dContext(ctx, 4); + }, 100); return html` - + + ${classes[ + 'text-brand-mixed' + ]} ${classes.interactive} font-semibold text-xs" + > ${this._hasCopiedInvoice ? copiedIcon : copyIcon} ${this._hasCopiedInvoice ? 'Copied!' : 'Copy Invoice'} From 817a06681249b265ed739dd1b087db7c691fd9d4 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 14 Aug 2024 13:53:01 +0700 Subject: [PATCH 2/2] chore: bump version --- README.md | 4 ++-- demos/html/index.html | 2 +- package.json | 2 +- react/package.json | 4 ++-- react/yarn.lock | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6ac737e..09da565 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ You can use Bitcoin Connect without any build tools: ```html diff --git a/demos/html/index.html b/demos/html/index.html index c6b4053..e218b35 100644 --- a/demos/html/index.html +++ b/demos/html/index.html @@ -5,7 +5,7 @@ Bitcoin Connect