From 7ecf7a344c5e0edbc4dfac24e0cdecd7c2a6c7d2 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Mon, 21 Oct 2024 17:26:32 +0200 Subject: [PATCH] fix: add timeout to BIP-353 DNS lookup (#704) * fix: add timeout to BIP-353 DNS lookup * chore: zh translation fix --------- Co-authored-by: Kilian <19181985+kilrau@users.noreply.github.com> --- src/components/CreateButton.tsx | 21 ++++++++++++++------- src/i18n/i18n.ts | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/CreateButton.tsx b/src/components/CreateButton.tsx index 4855fe7c..d262268c 100644 --- a/src/components/CreateButton.tsx +++ b/src/components/CreateButton.tsx @@ -160,7 +160,7 @@ export const CreateButton = () => { (() => { return new Promise(async (resolve, reject) => { const timeout = setTimeout( - () => reject("timeout"), + () => reject(t("timeout")), 5_000, ); @@ -169,7 +169,6 @@ export const CreateButton = () => { lnurl(), Number(receiveAmount()), ); - clearTimeout(timeout); resolve(res); } catch (e) { log.warn( @@ -177,24 +176,32 @@ export const CreateButton = () => { e, ); reject(e); + } finally { + clearTimeout(timeout); } }); })(), (() => { return new Promise(async (resolve, reject) => { + const timeout = setTimeout( + () => reject(t("timeout")), + 5_000, + ); + try { - resolve( - await fetchBip353( - lnurl(), - Number(receiveAmount()), - ), + const res = await fetchBip353( + lnurl(), + Number(receiveAmount()), ); + resolve(res); } catch (e) { log.warn( "Fetching invoice from BIP-353 failed:", e, ); reject(e); + } finally { + clearTimeout(timeout); } }); })(), diff --git a/src/i18n/i18n.ts b/src/i18n/i18n.ts index c49aa4b5..1a2a63cf 100644 --- a/src/i18n/i18n.ts +++ b/src/i18n/i18n.ts @@ -211,6 +211,7 @@ const dict = { block: "block", logs_scan_progress: "Scan progress {{ value }}%", accept: "Accept", + timeout: "Timeout", }, de: { language: "Deutsch", @@ -433,6 +434,7 @@ const dict = { block: "Block", logs_scan_progress: "Scan-Fortschritt {{ value }}%", accept: "Akzeptieren", + timeout: "Timeout", }, es: { language: "Español", @@ -654,6 +656,7 @@ const dict = { block: "bloque", logs_scan_progress: "Progreso del escaneo {{ value }}%", accept: "Aceptar", + timeout: "timeout", }, zh: { language: "中文", @@ -848,6 +851,7 @@ const dict = { block: "块", logs_scan_progress: "扫描进度{{ value }}%", accept: "接受", + timeout: "超时", }, };