Skip to content

Commit 02ed949

Browse files
authored
refactor: replace qr-code-styling with smaller library (#1129)
* chore: replace qrcode lib * chore: clean up * chore: style css + fixed loader * chore: remove references of qrcode-terminal-nooctal * fix: tests * chore: lint
1 parent 09eaf4a commit 02ed949

File tree

15 files changed

+48
-117
lines changed

15 files changed

+48
-117
lines changed

packages/examples/nodejs/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"allow-scripts": "echo 'n/a'"
1616
},
1717
"dependencies": {
18-
"@metamask/sdk": "^0.30.0",
19-
"qrcode-terminal": "^0.12.0"
18+
"@metamask/sdk": "^0.30.0"
2019
},
2120
"devDependencies": {
2221
"@types/node": "^20.4.1",

packages/examples/nodejs/src/index.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
import { MetaMaskSDK, MetaMaskSDKOptions, SDKProvider } from '@metamask/sdk';
2-
import * as fs from 'fs';
3-
4-
const qrcode = require('qrcode-terminal');
52

63
const options: MetaMaskSDKOptions = {
74
shouldShimWeb3: false,
8-
communicationServerUrl: 'http://192.168.50.10:4000',
95
dappMetadata: {
106
name: 'NodeJS example',
11-
},
12-
logging: {
13-
sdk: false,
14-
},
15-
checkInstallationImmediately: false,
16-
// Optional: customize modal text
17-
modals: {
18-
install: ({ link }) => {
19-
qrcode.generate(link, { small: true }, (qr) => console.log(qr));
20-
return {};
21-
},
22-
otp: () => {
23-
return {
24-
mount() {},
25-
updateOTPValue: (otpValue) => {
26-
if (otpValue !== '') {
27-
console.debug(
28-
`[CUSTOMIZE TEXT] Choose the following value on your metamask mobile wallet: ${otpValue}`,
29-
);
30-
}
31-
},
32-
};
33-
},
7+
url: 'http://localhost',
348
},
359
};
3610

packages/examples/nodejs/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,4 +2554,4 @@ __metadata:
25542554
resolution: "yn@npm:3.1.1"
25552555
checksum: 2c487b0e149e746ef48cda9f8bad10fc83693cd69d7f9dcd8be4214e985de33a29c9e24f3c0d6bcf2288427040a8947406ab27f7af67ee9456e6b84854f02dd6
25562556
languageName: node
2557-
linkType: hard
2557+
linkType: hard

packages/sdk-install-modal-web/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
"preversion": "yarn test",
4848
"postversion": "git push --tags && yarn publish . --tag $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
4949
},
50-
"dependencies": {
51-
"qr-code-styling": "^1.8.4"
52-
},
5350
"devDependencies": {
5451
"@lavamoat/allow-scripts": "^2.3.1",
5552
"@metamask/auto-changelog": "3.1.0",
@@ -113,5 +110,8 @@
113110
"webpack-dev-server>ws>bufferutil": false,
114111
"webpack-dev-server>ws>utf-8-validate": false
115112
}
113+
},
114+
"dependencies": {
115+
"@paulmillr/qr": "^0.2.1"
116116
}
117117
}

packages/sdk-install-modal-web/src/InstallModal.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import InstallIcon from './components/InstallIcon';
88
import WalletIcon from './components/LockIcon';
99
import Logo from './components/Logo';
1010
import LockIcon from './components/WalletIcon';
11-
import { FOX_IMAGE } from './constants';
1211
import styles from './styles';
1312
import SDKVersion from './components/SDKVersion';
13+
import encodeQR from '@paulmillr/qr';
1414

1515
export interface InstallModalProps {
1616
onClose: () => void;
@@ -32,30 +32,11 @@ export const InstallModal = (props: InstallModalProps) => {
3232

3333
useEffect(() => {
3434
if (qrCodeContainer.current) {
35-
// Prevent nextjs import issue: https://github.com/kozakdenys/qr-code-styling/issues/38
36-
// eslint-disable-next-line @typescript-eslint/no-var-requires
37-
const QRCodeStyling = require('qr-code-styling');
38-
const qrCode = new QRCodeStyling({
39-
width: 270,
40-
height: 270,
41-
type: 'svg',
42-
data: props.link,
43-
image: FOX_IMAGE,
44-
dotsOptions: {
45-
color: 'black',
46-
type: 'rounded',
47-
},
48-
imageOptions: {
49-
margin: 5,
50-
},
51-
cornersDotOptions: {
52-
color: '#f66a07',
53-
},
54-
qrOptions: {
55-
errorCorrectionLevel: 'M',
56-
},
57-
});
58-
qrCode.append(qrCodeContainer.current);
35+
const svgElement = encodeQR(props.link, "svg", {
36+
ecc: "medium",
37+
scale: 2
38+
})
39+
qrCodeContainer.current.innerHTML = svgElement
5940
}
6041
}, [qrCodeContainer]);
6142

packages/sdk-install-modal-web/src/ModalLoader.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import { FOX_IMAGE } from './constants';
43

54
import { InstallModal, InstallModalProps } from './InstallModal';
65
import { PendingModal, PendingModalProps } from './PendingModal';
76
import { SelectModal, SelectModalProps } from './SelectModal';
7+
import encodeQR from '@paulmillr/qr';
88

99
export interface InstallWidgetProps extends InstallModalProps {
1010
parentElement: Element;
@@ -131,31 +131,12 @@ export class ModalLoader {
131131
document.getElementById('sdk-qrcode-container');
132132
if (qrCodeNode) {
133133
qrCodeNode.innerHTML = '';
134-
// Prevent nextjs import issue: https://github.com/kozakdenys/qr-code-styling/issues/38
135-
// eslint-disable-next-line @typescript-eslint/no-var-requires
136-
const QRCodeStyling = require('qr-code-styling');
137-
// Prevent nextjs import issue
138-
const qrCode = new QRCodeStyling({
139-
width: 270,
140-
height: 270,
141-
type: 'svg',
142-
data: link,
143-
image: FOX_IMAGE,
144-
dotsOptions: {
145-
color: 'black',
146-
type: 'rounded',
147-
},
148-
imageOptions: {
149-
margin: 5,
150-
},
151-
cornersDotOptions: {
152-
color: '#f66a07',
153-
},
154-
qrOptions: {
155-
errorCorrectionLevel: 'M',
156-
},
157-
});
158-
qrCode.append(qrCodeNode);
134+
135+
const svgElement = encodeQR(link, "svg", {
136+
ecc: "medium",
137+
scale: 2,
138+
})
139+
qrCodeNode.innerHTML = svgElement
159140
}
160141
};
161142

packages/sdk-install-modal-web/src/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/sdk-install-modal-web/src/resetStyles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ table {
128128
border-collapse: collapse;
129129
border-spacing: 0;
130130
}
131+
132+
#sdk-mm-qrcode {
133+
svg {
134+
width: 50%;
135+
}
136+
}

packages/sdk-react-native/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const listDepForRollup = [...baseExternalDeps];
2020

2121
const rnExternalDeps = [
2222
...listDepForRollup,
23-
'qrcode-terminal-nooctal',
23+
'@paulmillr/qr',
2424
'react',
2525
'react-native',
2626
];

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@metamask/providers": "16.1.0",
6262
"@metamask/sdk-communication-layer": "workspace:*",
6363
"@metamask/sdk-install-modal-web": "workspace:*",
64+
"@paulmillr/qr": "^0.2.1",
6465
"bowser": "^2.9.0",
6566
"cross-fetch": "^4.0.0",
6667
"debug": "^4.3.4",
@@ -71,7 +72,6 @@
7172
"i18next-browser-languagedetector": "7.1.0",
7273
"obj-multiplex": "^1.0.0",
7374
"pump": "^3.0.0",
74-
"qrcode-terminal-nooctal": "^0.12.1",
7575
"react-native-webview": "^11.26.0",
7676
"readable-stream": "^3.6.2",
7777
"socket.io-client": "^4.5.1",

0 commit comments

Comments
 (0)