Skip to content

Commit efac3fd

Browse files
committed
Cleanup
1 parent 678d969 commit efac3fd

3 files changed

Lines changed: 19 additions & 85 deletions

File tree

src/misc/QrCodeUtils.js

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import qrcode from "../../libs/qrcode"
33

44
export type qrCodeOptions = {
5-
padding: number, //options.padding || 4,
6-
width: number, //options.width || 256,
7-
height: number, //options.height || 256,
8-
typeNumber: number, //options.typeNumber || 0, // Use 0 for auto detect depending on input data length (size)
9-
color: string, //options.color || "#fff",
10-
background: string, //options.background || "#000",
11-
ecl: string,// options.ecl || "M",
12-
container: string, //options.container || "svg",
13-
content: string, //options.content
5+
padding: number,
6+
width: number,
7+
height: number,
8+
typeNumber: number, // Use 0 for auto detect depending on input data length (size)
9+
fill: string,
10+
background: string,
11+
ecl: string,
12+
container: string,
13+
content: string,
1414
};
1515

1616
/** Generates QR Code as SVG image */
@@ -28,78 +28,12 @@ export function getQRCodeSvg(options: qrCodeOptions): string {
2828
var qrcodeGenerator = qrcode(options.typeNumber, options.ecl)
2929
qrcodeGenerator.addData(content)
3030
qrcodeGenerator.make()
31-
return qrcodeGenerator.createSvgTag()
32-
33-
// var modules = qrcodeGenerator.modules
34-
//
35-
// var width = options.width
36-
// var height = options.height
37-
// var length = modules.length;
38-
// var xsize = width / (length + 2 * options.padding);
39-
// var ysize = height / (length + 2 * options.padding);
40-
//
41-
// //Background rectangle
42-
// var bgrect = '<rect x="0" y="0" width="' + width + '" height="' + height + '" style="fill:' + options.background
43-
// + ';shape-rendering:optimizeSpeed;"></rect>';
44-
//
45-
// //Rectangles representing modules
46-
// var modrect = '';
47-
// var pathdata = '';
48-
//
49-
// for (var y = 0; y < length; y++) {
50-
// for (var x = 0; x < length; x++) {
51-
// var module = modules[x][y];
52-
// if (module) {
53-
//
54-
// var px = (x * xsize + options.padding * xsize);
55-
// var py = (y * ysize + options.padding * ysize);
56-
//
57-
// //Module as a part of svg path data, thanks to @danioso
58-
// var w = xsize + px
59-
// var h = ysize + py
60-
//
61-
// px = (Number.isInteger(px)) ? Number(px) : px.toFixed(2);
62-
// py = (Number.isInteger(py)) ? Number(py) : py.toFixed(2);
63-
// w = (Number.isInteger(w)) ? Number(w) : w.toFixed(2);
64-
// h = (Number.isInteger(h)) ? Number(h) : h.toFixed(2);
65-
//
66-
// pathdata += ('M' + px + ',' + py + ' V' + h + ' H' + w + ' V' + py + ' H' + px + ' Z ');
67-
// }
68-
// }
69-
// }
70-
//
71-
//
72-
// modrect = '<path x="0" y="0" style="fill:' + options.color + ';shape-rendering:optimizeSpeed;" d="' + pathdata + '" />';
73-
//
74-
// var svg = "";
75-
// switch (options.container) {
76-
// //Wrapped in SVG document
77-
// case "svg":
78-
// svg += '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="' + width + '" height="' + height + '">';
79-
// svg += bgrect + modrect;
80-
// svg += '</svg>';
81-
// break;
82-
//
83-
// //Viewbox for responsive use in a browser, thanks to @danioso
84-
// case "svg-viewbox":
85-
// svg += '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ' + width + ' ' + height + '">';
86-
// svg += bgrect + modrect;
87-
// svg += '</svg>';
88-
// break;
89-
//
90-
//
91-
// //Wrapped in group element
92-
// case "g":
93-
// svg += '<g width="' + width + '" height="' + height + '">';
94-
// svg += bgrect + modrect;
95-
// svg += '</g>';
96-
// break;
97-
//
98-
// //Without a container
99-
// case "none":
100-
// svg += (bgrect + modrect).replace(/^\s+/, ""); //Clear indents on each line
101-
// break;
102-
// }
103-
//
104-
// return svg;
31+
return qrcodeGenerator.createSvgPath({
32+
// Round to two decimals
33+
cellSize: Math.round(options.width / (qrcodeGenerator.getModuleCount() + 2 * options.padding) * 100) / 100,
34+
background: null,
35+
fill: options.fill,
36+
scalable: true,
37+
padding: options.padding
38+
})
10539
}

src/settings/EditSecondFactorsForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class EditSecondFactorsForm {
195195
let qrCode = getQRCodeSvg({
196196
typeNumber: 0,
197197
background: "#fff",
198-
color: "#000",
198+
fill: "#000",
199199
container: "svg",
200200
ecl: "M",
201201
padding: 10,

src/subscription/giftcards/GiftCardUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function renderGiftCardSvg(price: number, country: Country, link: ?string
281281
width: qrCodeSize,
282282
content: link,
283283
background: theme.content_accent,
284-
color: theme.content_bg,
284+
fill: theme.content_bg,
285285
container: "none",
286286
padding: 4,
287287
ecl: "M",

0 commit comments

Comments
 (0)