Skip to content

Commit 032b6b5

Browse files
committed
Display node URI on checkout page
1 parent bf20707 commit 032b6b5

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const apiToken = process.env.API_TOKEN || (console.error('Please configure your
2929
app.get('/info', auth, wrap(async (req, res) => res.send(await ln.getinfo())))
3030

3131
require('./invoicing')(app, payListen, model, auth)
32-
require('./checkout')(app, payListen)
32+
require('./checkout')(app, payListen, ln)
3333

3434
require('./sse')(app, payListen, auth)
3535
require('./webhook')(app, payListen, model, auth)

src/checkout.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import wrap from './lib/promise-wrap'
77

88
const rpath = name => path.join(__dirname, name)
99

10-
module.exports = (app, payListen) => {
10+
module.exports = (app, payListen, ln) => {
1111
app.set('url', process.env.URL || '/')
1212
app.set('static_url', process.env.STATIC_URL || app.settings.url + 'static/')
1313
app.set('view engine', 'pug')
@@ -29,8 +29,9 @@ module.exports = (app, payListen) => {
2929

3030
if (req.invoice.status == 'unpaid')
3131
res.locals.qr = await qrcode.toDataURL(`lightning:${req.invoice.payreq}`.toUpperCase(), { margin: 1 })
32+
const node_info = await ln.getinfo()
3233

33-
res.render('checkout', req.invoice)
34+
res.render('checkout', {invoice: req.invoice, node: node_info })
3435
}))
3536

3637
// like /invoice/:invoice/wait, but user-accessible, doesn't reveal the full invoice fields,

views/checkout.pug

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ meta(charset='utf-8')
55
base(href=settings.url)
66
meta(name='viewport', content='width=device-width, initial-scale=1')
77

8-
meta(name='invoice-id', content=id)
8+
meta(name='invoice-id', content=invoice.id)
99

10-
if status == 'unpaid'
11-
meta(name='invoice-poll-url', content=settings.url+'checkout/'+id+'/wait')
12-
meta(name='invoice-expiry', content=expires_at)
10+
if invoice.status == 'unpaid'
11+
meta(name='invoice-poll-url', content=settings.url+'checkout/'+invoice.id+'/wait')
12+
meta(name='invoice-expiry', content=invoice.expires_at)
1313

1414
mixin css(path)
1515
link(rel='stylesheet', href=settings.static_url+path)
1616

1717
+css('bootstrap.min.css')
1818
+css('checkout.css')
1919

20-
- opt = metadata && metadata.checkout || {}
20+
- opt = invoice.metadata && invoice.metadata.checkout || {}
2121

2222
body: .checkout.container
2323
script window.parent != window && (document.body.className += ' iframed')
@@ -28,33 +28,39 @@ body: .checkout.container
2828
h4= opt.desc || 'Pay with Lightning'
2929
if msatoshi
3030
.amounts.col-sm-6
31-
if quoted_currency
32-
h3 #{ quoted_amount } #{ quoted_currency }
33-
h4 #{ formatMsat(msatoshi) }
31+
if invoice.quoted_currency
32+
h3 #{ invoice.quoted_amount } #{ invoice.quoted_currency }
33+
h4 #{ formatMsat(invoice.msatoshi) }
3434
else
35-
h3 #{ formatMsat(msatoshi) }
35+
h3 #{ formatMsat(invoice.msatoshi) }
3636

37-
if status == 'paid'
37+
if invoice.status == 'paid'
3838
p.thankyou= opt.thank_you || 'Thank you! Your payment has been received.'
39-
script window.parent != window && window.parent.postMessage({ type: 'completed', invoice: '#{ id }' }, '*')
39+
script window.parent != window && window.parent.postMessage({ type: 'completed', invoice: '#{ invoice.id }' }, '*')
4040

41-
else if status == 'expired'
41+
else if invoice.status == 'expired'
4242
p.expired= opt.expired || 'Your invoice has expired. Please try again.'
4343

44-
else if status == 'unpaid'
44+
else if invoice.status == 'unpaid'
4545
.row
4646
.qr.col-sm-4: img(src=qr)
4747
.pay.col-sm-8
48-
pre= payreq
49-
a.btn.btn-lg.btn-primary(href=`lightning:${payreq}`)= opt.button || 'Pay with wallet'
48+
pre= invoice.payreq
49+
a.btn.btn-lg.btn-primary(href=`lightning:${invoice.payreq}`)= opt.button || 'Pay with wallet'
5050

5151
p.expiry.text-muted Invoice expires in #[span]
52+
53+
if node.address.length
54+
.row
55+
.qr.col-sm-12
56+
h4 Our node
57+
pre= node.id + "@" + node.address[0].address + ":" + node.address[0].port
5258

5359
script(src=settings.static_url+'checkout.js')
5460

5561
script.
5662
if (window.parent != window) {
57-
function updateHeight() { window.parent.postMessage({ type: 'height', value: document.body.scrollHeight, invoice: '#{ id }' }, '*') }
63+
function updateHeight() { window.parent.postMessage({ type: 'height', value: document.body.scrollHeight, invoice: '#{ invoice.id }' }, '*') }
5864
updateHeight()
5965
window.addEventListener('resize', updateHeight)
6066
}

0 commit comments

Comments
 (0)