diff --git a/package-lock.json b/package-lock.json index 2c713b6..846fd4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1387,6 +1387,14 @@ } } }, + "fmtbtc": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/fmtbtc/-/fmtbtc-0.0.3.tgz", + "integrity": "sha512-3awolswh6476ce5gIvzjw6OgT7ae2WD5NSinOC/de8gLeaDQPdYlW94Hb6nCoTXMUP6AFe3eh3IQiuT+dp4c8A==", + "requires": { + "move-decimal-point": "0.0.4" + } + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/package.json b/package.json index feba0da..8462e3a 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "express": "^4.16.3", "file-extension": "^4.0.2", "file-type": "^7.6.0", + "fmtbtc": "0.0.3", "fs-extra": "^5.0.0", "gm": "^1.23.1", "js-yaml": "^3.11.0", @@ -35,7 +36,6 @@ "markdown-it": "^8.4.1", "mime-types": "^2.1.18", "morgan": "^1.9.0", - "move-decimal-point": "0.0.4", "pretty-bytes": "^4.0.2", "pug": "^2.0.3", "qruri": "0.0.3", diff --git a/src/app.js b/src/app.js index 98d3237..bc928ae 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,7 @@ import fs from 'fs' import path from 'path' -import { pwrap, pick, fcurrency, fmsat, pngPixel } from './lib/util' +import { msat2milli } from 'fmtbtc' +import { pwrap, pick, fcurrency, pngPixel } from './lib/util' // Setup const app = require('express')() @@ -23,7 +24,7 @@ app.enable('case sensitive routing') // View locals Object.assign(app.locals, { - conf, fmsat, fcurrency + conf, msat2milli, fcurrency , prettybytes: require('pretty-bytes') , markdown: require('markdown-it')() , qruri: require('qruri') diff --git a/src/lib/config.js b/src/lib/config.js index b51667a..d5a2727 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -41,7 +41,7 @@ module.exports = basePath => { const parsePrice = str => { const m = str.match(/^([\d.]+) ([a-z]+)$/i) if (!m) throw new Error(`invalid price: ${ str }`) - return { amount: m[1], currency: m[2] } + return { amount: m[1], currency: m[2].toUpperCase() } } const parseFiles = (files, prefix='') => diff --git a/src/lib/util.js b/src/lib/util.js index 6453987..5c7d45b 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -1,6 +1,6 @@ -import { execFile } from 'child_process' -import moveDec from 'move-decimal-point' -import CurrencyF from 'currency-formatter' +import { execFile } from 'child_process' +import { btc2milli } from 'fmtbtc' +import CurrencyF from 'currency-formatter' // Promise wrapper for express handler functions const pwrap = fn => (req, res, next, ...a) => @@ -14,13 +14,12 @@ const exec = (cmd, ...args) => new Promise((resolve, reject) => // Pick specified object properties const pick = (O, ...K) => K.reduce((o, k) => (o[k]=O[k], o), {}) -// Format milli-satoshis as milli-bitcoins -const fmsat = msat => moveDec(msat, -8) - // Format price with currency symbol -const fcurrency = p => CurrencyF.format(p.amount, { code: p.currency.toUpperCase() }) +// +const fcurrency = p => p.currency === 'BTC' ? `${btc2milli(p.amount, true)} mBTC` + : CurrencyF.format(p.amount, { code: p.currency }) // Empty 1x1 PNG pixel const pngPixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', 'base64') -module.exports = { pwrap, exec, pick, fmsat, fcurrency, pngPixel } +module.exports = { pwrap, exec, pick, fcurrency, pngPixel } diff --git a/views/_checkout.pug b/views/_checkout.pug index c3b4c72..87543cd 100644 --- a/views/_checkout.pug +++ b/views/_checkout.pug @@ -7,7 +7,10 @@ if invoice.status == 'expired' else .checkout h3 Pay with Lightning - h4 #[strong= invoice.quoted_amount] #{invoice.quoted_currency } = #[strong= fmsat(invoice.msatoshi)] mBTC + if invoice.quoted_currency && invoice.quoted_currency != 'BTC' + h4 #[strong= invoice.quoted_amount] #{invoice.quoted_currency} ≈ #[strong= msat2milli(invoice.msatoshi)] mBTC + else + h4 #[strong= msat2milli(invoice.msatoshi)] mBTC .row .pay.col-sm-8 pre= invoice.payreq