Skip to content

Commit

Permalink
Merge pull request #132 from KeystoneHQ/fix-animatedqr
Browse files Browse the repository at this point in the history
fix: ignore error of dimensions
  • Loading branch information
LiYanLance authored Jul 7, 2023
2 parents 7bcadaa + 02f39b8 commit f628174
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/animated-qr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keystonehq/animated-qr",
"version": "0.8.4",
"version": "0.8.5",
"description": "animated qr code and scanner",
"author": "LiYanLance <liyan1924@gmail.com>",
"homepage": "https://github.com/KeystoneHQ/keystone-airgaped-base#readme",
Expand Down
4 changes: 4 additions & 0 deletions packages/animated-qr/src/AnimatedQRScanner/getAnimatedScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export const getAnimatedScan = ({
};

const handleScanFailure = (error: string) => {
// Ignore Error of "Dimensions could be not found.".
if (error === "Dimensions could be not found.") {
return;
}
if (handleError && error) {
handleError(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,12 @@ export const useAnimatedQRScanner = (
options,
...args
}: ScannerProps): ReactElement => {
// Error 5 times in 500ms, then trigger the error handler.
const errTimes = [];
const onError = (err: string) => {
if (isScanDone.current) {
return;
}
// Error "Dimensions could be not found." is triggered too frequently.
if (!/^Dimensions/i.test(err)) {
setIsDone(true);
handleError(err);
return;
}
const i = 4;
const t = Date.now();
errTimes.unshift(t);
if (errTimes[i] && t - errTimes[i] < 500) {
errTimes.length = 0;
setIsDone(true);
handleError(err);
}
setIsDone(true);
handleError(err);
};

const onSuccess = (ur: { type: string; cbor: string }) => {
Expand Down

0 comments on commit f628174

Please sign in to comment.