Skip to content

Commit

Permalink
fix: add timeout to BIP-353 DNS lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Oct 21, 2024
1 parent e1991a6 commit ca22a34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/components/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const CreateButton = () => {
(() => {
return new Promise<string>(async (resolve, reject) => {
const timeout = setTimeout(
() => reject("timeout"),
() => reject(t("timeout")),
5_000,
);

Expand All @@ -169,32 +169,39 @@ export const CreateButton = () => {
lnurl(),
Number(receiveAmount()),
);
clearTimeout(timeout);
resolve(res);
} catch (e) {
log.warn(
"Fetching invoice for LNURL failed:",
e,
);
reject(e);
} finally {
clearTimeout(timeout);
}
});
})(),
(() => {
return new Promise<string>(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);
}
});
})(),
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const dict = {
block: "block",
logs_scan_progress: "Scan progress {{ value }}%",
accept: "Accept",
timeout: "Timeout",
},
de: {
language: "Deutsch",
Expand Down Expand Up @@ -433,6 +434,7 @@ const dict = {
block: "Block",
logs_scan_progress: "Scan-Fortschritt {{ value }}%",
accept: "Akzeptieren",
timeout: "Timeout",
},
es: {
language: "Español",
Expand Down Expand Up @@ -654,6 +656,7 @@ const dict = {
block: "bloque",
logs_scan_progress: "Progreso del escaneo {{ value }}%",
accept: "Aceptar",
timeout: "timeout",
},
zh: {
language: "中文",
Expand Down Expand Up @@ -848,6 +851,7 @@ const dict = {
block: "块",
logs_scan_progress: "扫描进度{{ value }}%",
accept: "接受",
timeout: "逾时",
},
};

Expand Down

0 comments on commit ca22a34

Please sign in to comment.