Skip to content

Commit

Permalink
frontend: make qrscanner more resilient to re-render
Browse files Browse the repository at this point in the history
I.e. when resizing the window or rotating the screen it sometimes
crashed.
  • Loading branch information
thisconnect committed Oct 24, 2024
1 parent ff2ecb3 commit 7c0b2f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Label UTXOs that were created as change, as such, in coin control
- Remove support for deprecated the Ethereum Goerli network
- Revamp transaction history in account overview to improve legibility
- Fix qrscanner when rotating the device or resizing the window

# 4.45.0
- Bundle BitBox02 firmware version v9.21.0
Expand Down
24 changes: 12 additions & 12 deletions frontends/web/src/hooks/qrcodescanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ export const useQRScanner = (
}
);
}
});
return () => {
scanner.current?.stop();
scanner.current?.destroy();
scanner.current = null;
};
}, [onError, onResult, videoRef]);

useEffect(() => {
(async () => {
try {
await scanner.current?.start();
if (onStart) {
onStart();
await new Promise(r => setTimeout(r, 300));
if (scanner.current) {
await scanner.current.start();
if (onStart) {
onStart();
}
}
} catch (error: any) {
const stringifiedError = error.toString();
Expand All @@ -83,13 +91,5 @@ export const useQRScanner = (
})();
}, [videoRef, onStart, onResult, onError, t]);

useEffect(() => {
return () => {
scanner.current?.stop();
scanner.current?.destroy();
scanner.current = null;
};
});

return { initErrorMessage };
};

0 comments on commit 7c0b2f6

Please sign in to comment.