@pezkuwi/react-qr 3.16.7 → 3.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/package.json +237 -3
  2. package/build/Display.js +0 -91
  3. package/build/DisplayAddress.js +0 -12
  4. package/build/DisplayPayload.js +0 -12
  5. package/build/NetworkSpecs.js +0 -12
  6. package/build/README.md +0 -3
  7. package/build/Scan.js +0 -53
  8. package/build/ScanAddress.js +0 -41
  9. package/build/ScanSignature.js +0 -8
  10. package/build/bundle.js +0 -6
  11. package/build/cjs/Display.d.ts +0 -12
  12. package/build/cjs/Display.js +0 -95
  13. package/build/cjs/DisplayAddress.d.ts +0 -12
  14. package/build/cjs/DisplayAddress.js +0 -16
  15. package/build/cjs/DisplayPayload.d.ts +0 -15
  16. package/build/cjs/DisplayPayload.js +0 -16
  17. package/build/cjs/NetworkSpecs.d.ts +0 -11
  18. package/build/cjs/NetworkSpecs.js +0 -16
  19. package/build/cjs/Scan.d.ts +0 -12
  20. package/build/cjs/Scan.js +0 -57
  21. package/build/cjs/ScanAddress.d.ts +0 -19
  22. package/build/cjs/ScanAddress.js +0 -45
  23. package/build/cjs/ScanSignature.d.ts +0 -15
  24. package/build/cjs/ScanSignature.js +0 -12
  25. package/build/cjs/bundle.d.ts +0 -6
  26. package/build/cjs/bundle.js +0 -15
  27. package/build/cjs/constants.js +0 -12
  28. package/build/cjs/index.js +0 -5
  29. package/build/cjs/packageDetect.js +0 -5
  30. package/build/cjs/packageInfo.js +0 -4
  31. package/build/cjs/qrcode.js +0 -8
  32. package/build/cjs/styled.js +0 -5
  33. package/build/cjs/util.js +0 -59
  34. package/build/constants.d.ts +0 -9
  35. package/build/constants.js +0 -9
  36. package/build/index.d.ts +0 -2
  37. package/build/index.js +0 -2
  38. package/build/package.json +0 -274
  39. package/build/packageDetect.d.ts +0 -1
  40. package/build/packageDetect.js +0 -3
  41. package/build/packageInfo.d.ts +0 -6
  42. package/build/packageInfo.js +0 -1
  43. package/build/qrcode.d.ts +0 -3
  44. package/build/qrcode.js +0 -4
  45. package/build/styled.d.ts +0 -1
  46. package/build/styled.js +0 -1
  47. package/build/util.d.ts +0 -7
  48. package/build/util.js +0 -50
  49. package/src/Display.tsx +0 -153
  50. package/src/DisplayAddress.tsx +0 -40
  51. package/src/DisplayPayload.tsx +0 -42
  52. package/src/NetworkSpecs.tsx +0 -39
  53. package/src/Scan.tsx +0 -100
  54. package/src/ScanAddress.tsx +0 -82
  55. package/src/ScanSignature.tsx +0 -39
  56. package/src/bundle.ts +0 -9
  57. package/src/constants.ts +0 -12
  58. package/src/index.ts +0 -6
  59. package/src/packageDetect.ts +0 -11
  60. package/src/packageInfo.ts +0 -6
  61. package/src/qrcode.ts +0 -15
  62. package/src/styled.ts +0 -4
  63. package/src/util.spec.ts +0 -100
  64. package/src/util.ts +0 -83
  65. package/tsconfig.build.json +0 -14
  66. package/tsconfig.build.tsbuildinfo +0 -1
  67. package/tsconfig.spec.json +0 -16
  68. package/tsconfig.spec.tsbuildinfo +0 -1
  69. /package/{build-tsc/Display.d.ts → Display.d.ts} +0 -0
  70. /package/{build-tsc-esm/Display.js → Display.js} +0 -0
  71. /package/{build-tsc/DisplayAddress.d.ts → DisplayAddress.d.ts} +0 -0
  72. /package/{build-tsc-esm/DisplayAddress.js → DisplayAddress.js} +0 -0
  73. /package/{build-tsc/DisplayPayload.d.ts → DisplayPayload.d.ts} +0 -0
  74. /package/{build-tsc-esm/DisplayPayload.js → DisplayPayload.js} +0 -0
  75. /package/{build/LICENSE → LICENSE} +0 -0
  76. /package/{build-tsc/NetworkSpecs.d.ts → NetworkSpecs.d.ts} +0 -0
  77. /package/{build-tsc-esm/NetworkSpecs.js → NetworkSpecs.js} +0 -0
  78. /package/{build-tsc/Scan.d.ts → Scan.d.ts} +0 -0
  79. /package/{build-tsc-esm/Scan.js → Scan.js} +0 -0
  80. /package/{build-tsc/ScanAddress.d.ts → ScanAddress.d.ts} +0 -0
  81. /package/{build-tsc-esm/ScanAddress.js → ScanAddress.js} +0 -0
  82. /package/{build-tsc/ScanSignature.d.ts → ScanSignature.d.ts} +0 -0
  83. /package/{build-tsc-esm/ScanSignature.js → ScanSignature.js} +0 -0
  84. /package/{build/bundle-pezkuwi-react-qr.js → bundle-pezkuwi-react-qr.js} +0 -0
  85. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  86. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  87. /package/{build → cjs}/Display.d.ts +0 -0
  88. /package/{build-tsc-cjs → cjs}/Display.js +0 -0
  89. /package/{build → cjs}/DisplayAddress.d.ts +0 -0
  90. /package/{build-tsc-cjs → cjs}/DisplayAddress.js +0 -0
  91. /package/{build → cjs}/DisplayPayload.d.ts +0 -0
  92. /package/{build-tsc-cjs → cjs}/DisplayPayload.js +0 -0
  93. /package/{build → cjs}/NetworkSpecs.d.ts +0 -0
  94. /package/{build-tsc-cjs → cjs}/NetworkSpecs.js +0 -0
  95. /package/{build → cjs}/Scan.d.ts +0 -0
  96. /package/{build-tsc-cjs → cjs}/Scan.js +0 -0
  97. /package/{build → cjs}/ScanAddress.d.ts +0 -0
  98. /package/{build-tsc-cjs → cjs}/ScanAddress.js +0 -0
  99. /package/{build → cjs}/ScanSignature.d.ts +0 -0
  100. /package/{build-tsc-cjs → cjs}/ScanSignature.js +0 -0
  101. /package/{build → cjs}/bundle.d.ts +0 -0
  102. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  103. /package/{build-tsc → cjs}/constants.d.ts +0 -0
  104. /package/{build-tsc-cjs → cjs}/constants.js +0 -0
  105. /package/{build-tsc → cjs}/index.d.ts +0 -0
  106. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  107. /package/{build/cjs → cjs}/package.json +0 -0
  108. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  109. /package/{build-tsc-cjs → cjs}/packageDetect.js +0 -0
  110. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  111. /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
  112. /package/{build-tsc → cjs}/qrcode.d.ts +0 -0
  113. /package/{build-tsc-cjs → cjs}/qrcode.js +0 -0
  114. /package/{build-tsc → cjs}/styled.d.ts +0 -0
  115. /package/{build-tsc-cjs → cjs}/styled.js +0 -0
  116. /package/{build-tsc → cjs}/util.d.ts +0 -0
  117. /package/{build-tsc-cjs → cjs}/util.js +0 -0
  118. /package/{build/cjs/constants.d.ts → constants.d.ts} +0 -0
  119. /package/{build-tsc-esm/constants.js → constants.js} +0 -0
  120. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  121. /package/{build-tsc-esm/index.js → index.js} +0 -0
  122. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  123. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  124. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  125. /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
  126. /package/{build/cjs/qrcode.d.ts → qrcode.d.ts} +0 -0
  127. /package/{build-tsc-esm/qrcode.js → qrcode.js} +0 -0
  128. /package/{build/cjs/styled.d.ts → styled.d.ts} +0 -0
  129. /package/{build-tsc-esm/styled.js → styled.js} +0 -0
  130. /package/{build/cjs/util.d.ts → util.d.ts} +0 -0
  131. /package/{build-tsc-esm/util.js → util.js} +0 -0
package/package.json CHANGED
@@ -15,11 +15,245 @@
15
15
  },
16
16
  "sideEffects": [
17
17
  "./packageDetect.js",
18
- "./packageDetect.cjs"
18
+ "./cjs/packageDetect.js"
19
19
  ],
20
20
  "type": "module",
21
- "version": "3.16.7",
22
- "main": "index.js",
21
+ "version": "3.16.8",
22
+ "main": "./cjs/index.js",
23
+ "module": "./index.js",
24
+ "types": "./index.d.ts",
25
+ "exports": {
26
+ "./cjs/package.json": "./cjs/package.json",
27
+ "./cjs/*": "./cjs/*.js",
28
+ ".": {
29
+ "module": {
30
+ "types": "./index.d.ts",
31
+ "default": "./index.js"
32
+ },
33
+ "require": {
34
+ "types": "./cjs/index.d.ts",
35
+ "default": "./cjs/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./index.d.ts",
39
+ "default": "./index.js"
40
+ }
41
+ },
42
+ "./bundle": {
43
+ "module": {
44
+ "types": "./bundle.d.ts",
45
+ "default": "./bundle.js"
46
+ },
47
+ "require": {
48
+ "types": "./cjs/bundle.d.ts",
49
+ "default": "./cjs/bundle.js"
50
+ },
51
+ "default": {
52
+ "types": "./bundle.d.ts",
53
+ "default": "./bundle.js"
54
+ }
55
+ },
56
+ "./constants": {
57
+ "module": {
58
+ "types": "./constants.d.ts",
59
+ "default": "./constants.js"
60
+ },
61
+ "require": {
62
+ "types": "./cjs/constants.d.ts",
63
+ "default": "./cjs/constants.js"
64
+ },
65
+ "default": {
66
+ "types": "./constants.d.ts",
67
+ "default": "./constants.js"
68
+ }
69
+ },
70
+ "./Display": {
71
+ "module": {
72
+ "types": "./Display.d.ts",
73
+ "default": "./Display.js"
74
+ },
75
+ "require": {
76
+ "types": "./cjs/Display.d.ts",
77
+ "default": "./cjs/Display.js"
78
+ },
79
+ "default": {
80
+ "types": "./Display.d.ts",
81
+ "default": "./Display.js"
82
+ }
83
+ },
84
+ "./DisplayAddress": {
85
+ "module": {
86
+ "types": "./DisplayAddress.d.ts",
87
+ "default": "./DisplayAddress.js"
88
+ },
89
+ "require": {
90
+ "types": "./cjs/DisplayAddress.d.ts",
91
+ "default": "./cjs/DisplayAddress.js"
92
+ },
93
+ "default": {
94
+ "types": "./DisplayAddress.d.ts",
95
+ "default": "./DisplayAddress.js"
96
+ }
97
+ },
98
+ "./DisplayPayload": {
99
+ "module": {
100
+ "types": "./DisplayPayload.d.ts",
101
+ "default": "./DisplayPayload.js"
102
+ },
103
+ "require": {
104
+ "types": "./cjs/DisplayPayload.d.ts",
105
+ "default": "./cjs/DisplayPayload.js"
106
+ },
107
+ "default": {
108
+ "types": "./DisplayPayload.d.ts",
109
+ "default": "./DisplayPayload.js"
110
+ }
111
+ },
112
+ "./NetworkSpecs": {
113
+ "module": {
114
+ "types": "./NetworkSpecs.d.ts",
115
+ "default": "./NetworkSpecs.js"
116
+ },
117
+ "require": {
118
+ "types": "./cjs/NetworkSpecs.d.ts",
119
+ "default": "./cjs/NetworkSpecs.js"
120
+ },
121
+ "default": {
122
+ "types": "./NetworkSpecs.d.ts",
123
+ "default": "./NetworkSpecs.js"
124
+ }
125
+ },
126
+ "./package.json": {
127
+ "require": "./cjs/package.json",
128
+ "default": "./package.json"
129
+ },
130
+ "./packageDetect": {
131
+ "module": {
132
+ "types": "./packageDetect.d.ts",
133
+ "default": "./packageDetect.js"
134
+ },
135
+ "require": {
136
+ "types": "./cjs/packageDetect.d.ts",
137
+ "default": "./cjs/packageDetect.js"
138
+ },
139
+ "default": {
140
+ "types": "./packageDetect.d.ts",
141
+ "default": "./packageDetect.js"
142
+ }
143
+ },
144
+ "./packageInfo.js": {
145
+ "module": {
146
+ "types": "./packageInfo.d.ts",
147
+ "default": "./packageInfo.js"
148
+ },
149
+ "require": {
150
+ "types": "./cjs/packageInfo.d.ts",
151
+ "default": "./cjs/packageInfo.js"
152
+ },
153
+ "default": {
154
+ "types": "./packageInfo.d.ts",
155
+ "default": "./packageInfo.js"
156
+ }
157
+ },
158
+ "./packageInfo": {
159
+ "module": {
160
+ "types": "./packageInfo.d.ts",
161
+ "default": "./packageInfo.js"
162
+ },
163
+ "require": {
164
+ "types": "./cjs/packageInfo.d.ts",
165
+ "default": "./cjs/packageInfo.js"
166
+ },
167
+ "default": {
168
+ "types": "./packageInfo.d.ts",
169
+ "default": "./packageInfo.js"
170
+ }
171
+ },
172
+ "./qrcode": {
173
+ "module": {
174
+ "types": "./qrcode.d.ts",
175
+ "default": "./qrcode.js"
176
+ },
177
+ "require": {
178
+ "types": "./cjs/qrcode.d.ts",
179
+ "default": "./cjs/qrcode.js"
180
+ },
181
+ "default": {
182
+ "types": "./qrcode.d.ts",
183
+ "default": "./qrcode.js"
184
+ }
185
+ },
186
+ "./Scan": {
187
+ "module": {
188
+ "types": "./Scan.d.ts",
189
+ "default": "./Scan.js"
190
+ },
191
+ "require": {
192
+ "types": "./cjs/Scan.d.ts",
193
+ "default": "./cjs/Scan.js"
194
+ },
195
+ "default": {
196
+ "types": "./Scan.d.ts",
197
+ "default": "./Scan.js"
198
+ }
199
+ },
200
+ "./ScanAddress": {
201
+ "module": {
202
+ "types": "./ScanAddress.d.ts",
203
+ "default": "./ScanAddress.js"
204
+ },
205
+ "require": {
206
+ "types": "./cjs/ScanAddress.d.ts",
207
+ "default": "./cjs/ScanAddress.js"
208
+ },
209
+ "default": {
210
+ "types": "./ScanAddress.d.ts",
211
+ "default": "./ScanAddress.js"
212
+ }
213
+ },
214
+ "./ScanSignature": {
215
+ "module": {
216
+ "types": "./ScanSignature.d.ts",
217
+ "default": "./ScanSignature.js"
218
+ },
219
+ "require": {
220
+ "types": "./cjs/ScanSignature.d.ts",
221
+ "default": "./cjs/ScanSignature.js"
222
+ },
223
+ "default": {
224
+ "types": "./ScanSignature.d.ts",
225
+ "default": "./ScanSignature.js"
226
+ }
227
+ },
228
+ "./styled": {
229
+ "module": {
230
+ "types": "./styled.d.ts",
231
+ "default": "./styled.js"
232
+ },
233
+ "require": {
234
+ "types": "./cjs/styled.d.ts",
235
+ "default": "./cjs/styled.js"
236
+ },
237
+ "default": {
238
+ "types": "./styled.d.ts",
239
+ "default": "./styled.js"
240
+ }
241
+ },
242
+ "./util": {
243
+ "module": {
244
+ "types": "./util.d.ts",
245
+ "default": "./util.js"
246
+ },
247
+ "require": {
248
+ "types": "./cjs/util.d.ts",
249
+ "default": "./cjs/util.js"
250
+ },
251
+ "default": {
252
+ "types": "./util.d.ts",
253
+ "default": "./util.js"
254
+ }
255
+ }
256
+ },
23
257
  "dependencies": {
24
258
  "@pezkuwi/ui-settings": "3.16.6",
25
259
  "@pezkuwi/util": "^14.0.5",
package/build/Display.js DELETED
@@ -1,91 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useEffect, useMemo, useRef, useState } from 'react';
3
- import { objectSpread } from '@pezkuwi/util';
4
- import { xxhashAsHex } from '@pezkuwi/util-crypto';
5
- import { qrcode } from './qrcode.js';
6
- import { styled } from './styled.js';
7
- import { createFrames, createImgSize } from './util.js';
8
- const DEFAULT_FRAME_DELAY = 2750;
9
- const TIMER_INC = 500;
10
- function getDataUrl(value) {
11
- const qr = qrcode(0, 'M');
12
- // HACK See our qrcode stringToBytes override as used internally. This
13
- // will only work for the case where we actually pass `Bytes` in here
14
- qr.addData(value, 'Byte');
15
- qr.make();
16
- return qr.createDataURL(16, 0);
17
- }
18
- function Display({ className = '', size, skipEncoding, style = {}, timerDelay = DEFAULT_FRAME_DELAY, value }) {
19
- const [{ image }, setFrameState] = useState({ frameIdx: 0, frames: [], image: null, valueHash: null });
20
- const timerRef = useRef({ timerDelay, timerId: null });
21
- const containerStyle = useMemo(() => createImgSize(size), [size]);
22
- // run on initial load to setup the global timer and provide and unsubscribe
23
- useEffect(() => {
24
- const nextFrame = () => setFrameState((state) => {
25
- // when we have a single frame, we only ever fire once
26
- if (state.frames.length <= 1) {
27
- return state;
28
- }
29
- let frameIdx = state.frameIdx + 1;
30
- // when we overflow, skip to the first and slightly increase the delay between frames
31
- if (frameIdx === state.frames.length) {
32
- frameIdx = 0;
33
- timerRef.current.timerDelay = timerRef.current.timerDelay + TIMER_INC;
34
- }
35
- // only encode the frames on demand, not above as part of the
36
- // state derivation - in the case of large payloads, this should
37
- // be slightly more responsive on initial load
38
- const newState = objectSpread({}, state, {
39
- frameIdx,
40
- image: getDataUrl(state.frames[frameIdx])
41
- });
42
- // set the new timer last
43
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
44
- return newState;
45
- });
46
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
47
- return () => {
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
- timerRef.current.timerId && clearTimeout(timerRef.current.timerId);
50
- };
51
- // eslint-disable-next-line react-hooks/exhaustive-deps
52
- }, []);
53
- useEffect(() => {
54
- setFrameState((state) => {
55
- const valueHash = xxhashAsHex(value);
56
- if (valueHash === state.valueHash) {
57
- return state;
58
- }
59
- const frames = skipEncoding
60
- ? [value]
61
- : createFrames(value);
62
- // encode on demand
63
- return {
64
- frameIdx: 0,
65
- frames,
66
- image: getDataUrl(frames[0]),
67
- valueHash
68
- };
69
- });
70
- }, [skipEncoding, value]);
71
- if (!image) {
72
- return null;
73
- }
74
- return (_jsx(StyledDiv, { className: className, style: containerStyle, children: _jsx("div", { className: 'ui--qr-Display', style: style, children: _jsx("img", { src: image }) }) }));
75
- }
76
- const StyledDiv = styled.div `
77
- .ui--qr-Display {
78
- height: 100%;
79
- width: 100%;
80
-
81
- img,
82
- svg {
83
- background: white;
84
- height: auto !important;
85
- max-height: 100%;
86
- max-width: 100%;
87
- width: auto !important;
88
- }
89
- }
90
- `;
91
- export const QrDisplay = React.memo(Display);
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useMemo } from 'react';
3
- import { QrDisplay } from './Display.js';
4
- import { createAddressPayload } from './util.js';
5
- function DisplayAddress({ address, className, genesisHash, size, style, timerDelay }) {
6
- const data = useMemo(() => createAddressPayload(address, genesisHash), [address, genesisHash]);
7
- if (!data) {
8
- return null;
9
- }
10
- return (_jsx(QrDisplay, { className: className, size: size, skipEncoding: true, style: style, timerDelay: timerDelay, value: data }));
11
- }
12
- export const QrDisplayAddress = React.memo(DisplayAddress);
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useMemo } from 'react';
3
- import { QrDisplay } from './Display.js';
4
- import { createSignPayload } from './util.js';
5
- function DisplayPayload({ address, className, cmd, genesisHash, payload, size, style, timerDelay }) {
6
- const data = useMemo(() => createSignPayload(address, cmd, payload, genesisHash), [address, cmd, payload, genesisHash]);
7
- if (!data) {
8
- return null;
9
- }
10
- return (_jsx(QrDisplay, { className: className, size: size, style: style, timerDelay: timerDelay, value: data }));
11
- }
12
- export const QrDisplayPayload = React.memo(DisplayPayload);
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useMemo } from 'react';
3
- import { QrDisplay } from './Display.js';
4
- import { encodeString } from './util.js';
5
- function DisplayNetworkSpecs({ className, networkSpecs, size, style }) {
6
- const data = useMemo(() => encodeString(JSON.stringify(networkSpecs)), [networkSpecs]);
7
- if (!data) {
8
- return null;
9
- }
10
- return (_jsx(QrDisplay, { className: className, size: size, skipEncoding: true, style: style, value: data }));
11
- }
12
- export const QrNetworkSpecs = React.memo(DisplayNetworkSpecs);
package/build/README.md DELETED
@@ -1,3 +0,0 @@
1
- # @pezkuwi/react-qr
2
-
3
- A Qr-code component that allows for the transfer of addresses and transaction payloads to and from external readers. It implements the [Universal Offline Signatures](https://github.com/maciejhirsz/uos) specification to read and generated QR codes.
package/build/Scan.js DELETED
@@ -1,53 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { BrowserQRCodeReader } from '@zxing/browser';
3
- import React, { useCallback, useEffect, useMemo, useRef } from 'react';
4
- import { styled } from './styled.js';
5
- import { createImgSize } from './util.js';
6
- const DEFAULT_DELAY = 150;
7
- const DEFAULT_ERROR = (error) => {
8
- console.error('@pezkuwi/react-qr:Scan', error.message);
9
- };
10
- function Scan({ className = '', delay = DEFAULT_DELAY, onError = DEFAULT_ERROR, onScan, size, style = {} }) {
11
- const videoRef = useRef(null);
12
- const controlsRef = useRef(null);
13
- const containerStyle = useMemo(() => createImgSize(size), [size]);
14
- const _onError = useCallback((error) => onError(error), [onError]);
15
- useEffect(() => {
16
- const codeReader = new BrowserQRCodeReader();
17
- const startScanning = async () => {
18
- try {
19
- const videoInputDevices = await BrowserQRCodeReader.listVideoInputDevices();
20
- const selectedDeviceId = videoInputDevices[0].deviceId;
21
- controlsRef.current = await codeReader.decodeFromVideoDevice(selectedDeviceId, videoRef.current ?? undefined, (result, error) => {
22
- if (result) {
23
- onScan(result.getText());
24
- }
25
- if (error && !(error instanceof Error)) {
26
- _onError(new Error(error));
27
- }
28
- });
29
- }
30
- catch (error) {
31
- _onError(error instanceof Error ? error : new Error('Unknown error occurred'));
32
- }
33
- };
34
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
35
- const timeoutId = setTimeout(startScanning, delay);
36
- return () => {
37
- clearTimeout(timeoutId);
38
- if (controlsRef.current) {
39
- controlsRef.current.stop();
40
- }
41
- };
42
- }, [onScan, _onError, delay]);
43
- return (_jsx(StyledDiv, { className: className, style: containerStyle, children: _jsx("video", { className: 'ui--qr-Scan', ref: videoRef, style: style }) }));
44
- }
45
- const StyledDiv = styled.div `
46
- .ui--qr-Scan {
47
- display: inline-block;
48
- height: 100%;
49
- transform: matrix(-1, 0, 0, 1, 0, 0);
50
- width: 100%;
51
- }
52
- `;
53
- export const QrScan = React.memo(Scan);
@@ -1,41 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useCallback } from 'react';
3
- import { decodeAddress } from '@pezkuwi/util-crypto';
4
- import { ADDRESS_PREFIX, SEED_PREFIX } from './constants.js';
5
- import { QrScan } from './Scan.js';
6
- function ScanAddress({ className, isEthereum, onError, onScan, size, style }) {
7
- const _onScan = useCallback((data) => {
8
- if (data) {
9
- try {
10
- let prefix;
11
- let content;
12
- let genesisHash;
13
- let name;
14
- if (!isEthereum) {
15
- [prefix, content, genesisHash, ...name] = data.split(':');
16
- }
17
- else {
18
- [prefix, content, ...name] = data.split(':');
19
- genesisHash = null;
20
- content = content.substring(0, 42);
21
- }
22
- const expectedPrefix = (isEthereum ? 'ethereum' : ADDRESS_PREFIX);
23
- const isValidPrefix = (prefix === expectedPrefix) || (prefix === SEED_PREFIX);
24
- if (!isValidPrefix) {
25
- throw new Error(`Invalid prefix received, expected '${expectedPrefix} or ${SEED_PREFIX}' , found '${prefix}'`);
26
- }
27
- const isAddress = prefix === expectedPrefix;
28
- if (isAddress && !isEthereum) {
29
- decodeAddress(content);
30
- }
31
- onScan({ content, genesisHash: genesisHash, isAddress, name: name?.length ? name.join(':') : undefined });
32
- }
33
- catch (error) {
34
- onError && onError(error);
35
- console.error('@pezkuwi/react-qr:QrScanAddress', error.message, data);
36
- }
37
- }
38
- }, [onScan, onError, isEthereum]);
39
- return (_jsx(QrScan, { className: className, onError: onError, onScan: _onScan, size: size, style: style }));
40
- }
41
- export const QrScanAddress = React.memo(ScanAddress);
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useCallback } from 'react';
3
- import { QrScan } from './Scan.js';
4
- function ScanSignature({ className, onError, onScan, size, style }) {
5
- const _onScan = useCallback((signature) => signature && onScan({ signature: `0x${signature}` }), [onScan]);
6
- return (_jsx(QrScan, { className: className, onError: onError, onScan: _onScan, size: size, style: style }));
7
- }
8
- export const QrScanSignature = React.memo(ScanSignature);
package/build/bundle.js DELETED
@@ -1,6 +0,0 @@
1
- export { QrDisplayAddress } from './DisplayAddress.js';
2
- export { QrDisplayPayload } from './DisplayPayload.js';
3
- export { QrNetworkSpecs } from './NetworkSpecs.js';
4
- export { packageInfo } from './packageInfo.js';
5
- export { QrScanAddress } from './ScanAddress.js';
6
- export { QrScanSignature } from './ScanSignature.js';
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- interface Props {
3
- className?: string | undefined;
4
- size?: string | number | undefined;
5
- skipEncoding?: boolean;
6
- style?: React.CSSProperties | undefined;
7
- timerDelay?: number | undefined;
8
- value: Uint8Array;
9
- }
10
- declare function Display({ className, size, skipEncoding, style, timerDelay, value }: Props): React.ReactElement<Props> | null;
11
- export declare const QrDisplay: React.MemoExoticComponent<typeof Display>;
12
- export {};
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QrDisplay = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importStar(require("react"));
7
- const util_1 = require("@pezkuwi/util");
8
- const util_crypto_1 = require("@pezkuwi/util-crypto");
9
- const qrcode_js_1 = require("./qrcode.js");
10
- const styled_js_1 = require("./styled.js");
11
- const util_js_1 = require("./util.js");
12
- const DEFAULT_FRAME_DELAY = 2750;
13
- const TIMER_INC = 500;
14
- function getDataUrl(value) {
15
- const qr = (0, qrcode_js_1.qrcode)(0, 'M');
16
- // HACK See our qrcode stringToBytes override as used internally. This
17
- // will only work for the case where we actually pass `Bytes` in here
18
- qr.addData(value, 'Byte');
19
- qr.make();
20
- return qr.createDataURL(16, 0);
21
- }
22
- function Display({ className = '', size, skipEncoding, style = {}, timerDelay = DEFAULT_FRAME_DELAY, value }) {
23
- const [{ image }, setFrameState] = (0, react_1.useState)({ frameIdx: 0, frames: [], image: null, valueHash: null });
24
- const timerRef = (0, react_1.useRef)({ timerDelay, timerId: null });
25
- const containerStyle = (0, react_1.useMemo)(() => (0, util_js_1.createImgSize)(size), [size]);
26
- // run on initial load to setup the global timer and provide and unsubscribe
27
- (0, react_1.useEffect)(() => {
28
- const nextFrame = () => setFrameState((state) => {
29
- // when we have a single frame, we only ever fire once
30
- if (state.frames.length <= 1) {
31
- return state;
32
- }
33
- let frameIdx = state.frameIdx + 1;
34
- // when we overflow, skip to the first and slightly increase the delay between frames
35
- if (frameIdx === state.frames.length) {
36
- frameIdx = 0;
37
- timerRef.current.timerDelay = timerRef.current.timerDelay + TIMER_INC;
38
- }
39
- // only encode the frames on demand, not above as part of the
40
- // state derivation - in the case of large payloads, this should
41
- // be slightly more responsive on initial load
42
- const newState = (0, util_1.objectSpread)({}, state, {
43
- frameIdx,
44
- image: getDataUrl(state.frames[frameIdx])
45
- });
46
- // set the new timer last
47
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
48
- return newState;
49
- });
50
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
51
- return () => {
52
- // eslint-disable-next-line react-hooks/exhaustive-deps
53
- timerRef.current.timerId && clearTimeout(timerRef.current.timerId);
54
- };
55
- // eslint-disable-next-line react-hooks/exhaustive-deps
56
- }, []);
57
- (0, react_1.useEffect)(() => {
58
- setFrameState((state) => {
59
- const valueHash = (0, util_crypto_1.xxhashAsHex)(value);
60
- if (valueHash === state.valueHash) {
61
- return state;
62
- }
63
- const frames = skipEncoding
64
- ? [value]
65
- : (0, util_js_1.createFrames)(value);
66
- // encode on demand
67
- return {
68
- frameIdx: 0,
69
- frames,
70
- image: getDataUrl(frames[0]),
71
- valueHash
72
- };
73
- });
74
- }, [skipEncoding, value]);
75
- if (!image) {
76
- return null;
77
- }
78
- return ((0, jsx_runtime_1.jsx)(StyledDiv, { className: className, style: containerStyle, children: (0, jsx_runtime_1.jsx)("div", { className: 'ui--qr-Display', style: style, children: (0, jsx_runtime_1.jsx)("img", { src: image }) }) }));
79
- }
80
- const StyledDiv = styled_js_1.styled.div `
81
- .ui--qr-Display {
82
- height: 100%;
83
- width: 100%;
84
-
85
- img,
86
- svg {
87
- background: white;
88
- height: auto !important;
89
- max-height: 100%;
90
- max-width: 100%;
91
- width: auto !important;
92
- }
93
- }
94
- `;
95
- exports.QrDisplay = react_1.default.memo(Display);
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- interface Props {
3
- address: string;
4
- genesisHash: string;
5
- className?: string;
6
- size?: string | number;
7
- style?: React.CSSProperties;
8
- timerDelay?: number;
9
- }
10
- declare function DisplayAddress({ address, className, genesisHash, size, style, timerDelay }: Props): React.ReactElement<Props> | null;
11
- export declare const QrDisplayAddress: React.MemoExoticComponent<typeof DisplayAddress>;
12
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QrDisplayAddress = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importStar(require("react"));
7
- const Display_js_1 = require("./Display.js");
8
- const util_js_1 = require("./util.js");
9
- function DisplayAddress({ address, className, genesisHash, size, style, timerDelay }) {
10
- const data = (0, react_1.useMemo)(() => (0, util_js_1.createAddressPayload)(address, genesisHash), [address, genesisHash]);
11
- if (!data) {
12
- return null;
13
- }
14
- return ((0, jsx_runtime_1.jsx)(Display_js_1.QrDisplay, { className: className, size: size, skipEncoding: true, style: style, timerDelay: timerDelay, value: data }));
15
- }
16
- exports.QrDisplayAddress = react_1.default.memo(DisplayAddress);
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- interface Props {
3
- address: string;
4
- className?: string;
5
- cmd: number;
6
- delay?: number;
7
- genesisHash: Uint8Array | string;
8
- payload: Uint8Array;
9
- size?: string | number;
10
- style?: React.CSSProperties;
11
- timerDelay?: number;
12
- }
13
- declare function DisplayPayload({ address, className, cmd, genesisHash, payload, size, style, timerDelay }: Props): React.ReactElement<Props> | null;
14
- export declare const QrDisplayPayload: React.MemoExoticComponent<typeof DisplayPayload>;
15
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QrDisplayPayload = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importStar(require("react"));
7
- const Display_js_1 = require("./Display.js");
8
- const util_js_1 = require("./util.js");
9
- function DisplayPayload({ address, className, cmd, genesisHash, payload, size, style, timerDelay }) {
10
- const data = (0, react_1.useMemo)(() => (0, util_js_1.createSignPayload)(address, cmd, payload, genesisHash), [address, cmd, payload, genesisHash]);
11
- if (!data) {
12
- return null;
13
- }
14
- return ((0, jsx_runtime_1.jsx)(Display_js_1.QrDisplay, { className: className, size: size, style: style, timerDelay: timerDelay, value: data }));
15
- }
16
- exports.QrDisplayPayload = react_1.default.memo(DisplayPayload);