|
252 | 252 | } |
253 | 253 | }; |
254 | 254 |
|
| 255 | + D.renderTunnelInvoiceQr = async function (bolt11) { |
| 256 | + const qrEl = D.el('tunnel-invoice-qr'); |
| 257 | + if (!qrEl) return; |
| 258 | + qrEl.replaceChildren(); |
| 259 | + if (!bolt11) return; |
| 260 | + |
| 261 | + try { |
| 262 | + const resp = await fetch('/box/api/qrcode', { |
| 263 | + method: 'POST', |
| 264 | + headers: { 'Content-Type': 'application/json' }, |
| 265 | + body: JSON.stringify({ text: bolt11 }), |
| 266 | + }); |
| 267 | + if (!resp.ok) { |
| 268 | + throw new Error('QR render failed'); |
| 269 | + } |
| 270 | + const blob = await resp.blob(); |
| 271 | + const imageUrl = URL.createObjectURL(blob); |
| 272 | + const image = document.createElement('img'); |
| 273 | + image.src = imageUrl; |
| 274 | + image.alt = 'Tunnel invoice QR code'; |
| 275 | + image.width = 220; |
| 276 | + image.height = 220; |
| 277 | + image.className = 'block'; |
| 278 | + image.addEventListener('load', function () { |
| 279 | + URL.revokeObjectURL(imageUrl); |
| 280 | + }, { once: true }); |
| 281 | + qrEl.appendChild(image); |
| 282 | + } catch (error) { |
| 283 | + const message = document.createElement('p'); |
| 284 | + message.className = 'text-red-400 font-mono text-xs text-center p-4'; |
| 285 | + message.textContent = 'Failed to render QR code.'; |
| 286 | + qrEl.appendChild(message); |
| 287 | + } |
| 288 | + }; |
| 289 | + |
255 | 290 | D.openTunnelInvoiceModal = function (bolt11) { |
256 | 291 | const modal = D.el('tunnel-invoice-modal'); |
257 | 292 | const textarea = D.el('tunnel-invoice-text'); |
258 | 293 | const status = D.el('tunnel-invoice-status'); |
259 | | - const qrEl = D.el('tunnel-invoice-qr'); |
260 | | - if (!modal || !textarea || !status || !qrEl) return; |
| 294 | + if (!modal || !textarea || !status) return; |
261 | 295 | modal.classList.remove('hidden'); |
262 | 296 | textarea.value = bolt11 || ''; |
263 | 297 | status.textContent = 'Waiting for payment...'; |
264 | | - qrEl.innerHTML = ''; |
265 | | - if (bolt11 && typeof QRCode !== 'undefined') { |
266 | | - D.state.tunnelInvoiceQr = new QRCode(qrEl, { text: bolt11, width: 220, height: 220, correctLevel: QRCode.CorrectLevel.M }); |
267 | | - } |
| 298 | + D.renderTunnelInvoiceQr(bolt11); |
268 | 299 | }; |
269 | 300 |
|
270 | 301 | D.closeTunnelInvoiceModal = function () { |
|
0 commit comments