Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error on camera permissions denied #635

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/components/QrScan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const QrScan = () => {
let qrScanner: QrScanner;

const { swapType, setInvoice, setOnchainAddress } = useCreateContext();
const { t, camera, setCamera } = useGlobalContext();
const { t, camera, notify, setCamera } = useGlobalContext();

const [scanning, setScanning] = createSignal(false);

Expand All @@ -26,7 +26,6 @@ const QrScan = () => {
});

const startScan = () => {
setScanning(true);
if (qrScanner === undefined) {
qrScanner = new QrScanner(
qrRef,
Expand All @@ -48,11 +47,21 @@ const QrScan = () => {
},
);
}
qrScanner.start().then();
qrScanner
.start()
.then(() => {
log.debug("qr scanner started");
setScanning(true);
})
.catch((err) => {
log.error("error starting qr scanner: ", err);
notify("error", t("error_starting_qr_scanner"));
});
};

const stopScan = () => {
if (scanning()) {
log.debug("stopping qr scanner");
qrScanner.destroy();
setScanning(false);
qrScanner = undefined;
Expand All @@ -71,14 +80,14 @@ const QrScan = () => {
{t("scan_qr_code")}
</button>
</Show>
<Show when={scanning()}>
<div id="video-wrapper">
<video id="qr-scanner" ref={qrRef}></video>
<span class="close-qr" onClick={stopScan}>
X
</span>
</div>
</Show>
<div
id="video-wrapper"
style={scanning() ? "display: block" : "display: none"}>
<video id="qr-scanner" ref={qrRef}></video>
<span class="close-qr" onClick={stopScan}>
X
</span>
</div>
<hr />
</Show>
</>
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ const dict = {
reckless_mode_setting: "Reckless Mode",
reckless_mode_setting_tooltip:
"Disables prompts to download refund file and other confirmation steps",
error_starting_qr_scanner:
"Couldn't access camera, please check permissions!",
},
de: {
language: "Deutsch",
Expand Down Expand Up @@ -414,6 +416,8 @@ const dict = {
reckless_mode_setting: "Reckless Modus",
reckless_mode_setting_tooltip:
"Deaktiviert Downloadaufforderung der Rückerstattungsdatei und andere Bestätigungsschritte",
error_starting_qr_scanner:
"Konnte nicht auf Kamera zugreifen, bitte Berechtigungen überprüfen!",
},
es: {
language: "Español",
Expand Down Expand Up @@ -626,6 +630,8 @@ const dict = {
reckless_mode_setting: "Modo Reckless",
reckless_mode_setting_tooltip:
"Desactiva los avisos para descargar el archivo de reembolso y otros pasos de confirmación",
error_starting_qr_scanner:
"No se pudo acceder a la cámara, por favor compruebe los permisos!",
},
zh: {
language: "中文",
Expand Down Expand Up @@ -812,6 +818,7 @@ const dict = {
invalid_pair: "无效交换对",
reckless_mode_setting: "鲁莽模式",
reckless_mode_setting_tooltip: "禁用下载退款文件的提示和其他确认步骤",
error_starting_qr_scanner: "无法访问摄像头, 请检查权限!",
},
};

Expand Down