-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr.js
65 lines (57 loc) · 1.47 KB
/
qr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
import { toDash } from './utils.js'
let qrWidth = 2 + 33 + 2;
/**
* @typedef QrOpts
* @property {String} [background]
* @property {String} [color]
* @property {String} [ecl]
* @property {Number} [height]
* @property {Number} [indent]
* @property {Number} [padding]
* @property {"mini" | "micro"} [size]
* @property {Number} [width]
* @property {"svg" | "svg-viewbox" | "g"} [container]
* @property {Boolean} [join]
*/
/**
* @param {String} data
* @param {QrOpts} opts
*/
export function create(data, opts) {
return new QRCode({
...opts,
content: data,
padding: opts?.padding || 4,
width: opts?.width || 256,
height: opts?.height || 256,
color: opts?.color || "#000000",
background: opts?.background || "#ffffff",
ecl: opts?.ecl || "M",
});
};
/**
* @param {String} data
* @param {QrOpts} opts
*/
export function qrSvg (data, opts) {
let qrcode = create(data, opts);
return qrcode.svg();
};
/**
* @param {String} addr - Base58Check pubKeyHash address
* @param {Number} duffs - 1/100000000 of a DASH
*/
export function showQr(addr, duffs = 0) {
let dashAmount = toDash(duffs);
let dashUri = `dash://${addr}`;
if (duffs) {
dashUri += `?amount=${dashAmount}`;
}
let dashQr = qrSvg(dashUri, { indent: 4, size: "mini" });
// let addrPad = Math.max(0, Math.ceil((qrWidth - dashUri.length) / 2));
// console.info(dashQr);
// console.info();
// console.info(" ".repeat(addrPad) + dashUri);
return dashQr
}