Improve formatting for BTC amounts
This commit is contained in:
parent
6068bc8be4
commit
99dbf42d86
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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='') =>
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue