mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-08 13:52:58 +00:00
Retry NWC requests with nip04 after nip44 timeouts
This commit is contained in:
1 parent
011d69482a
commit
37bec3c5e2
2 files changed
+95
-5
No files matched your search
@@ -673,6 +673,45 @@ async function ensureEncryption(context) {
|
||||
throw new Error("No compatible wallet encryption scheme available.");
|
||||
}
|
||||
|
||||
function shouldRetryWithFallback(context, error, encryption, { hasRetried }) {
|
||||
if (!context || !encryption || hasRetried) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const code = typeof error?.code === "string" ? error.code : "";
|
||||
const message = typeof error?.message === "string" ? error.message : "";
|
||||
|
||||
if (code === "UNSUPPORTED_ENCRYPTION" || code === "unsupported_encryption") {
|
||||
return true;
|
||||
}
|
||||
|
||||
const isTimeout =
|
||||
message === "Wallet request timed out." ||
|
||||
code === "timeout" ||
|
||||
code === "TIMEOUT";
|
||||
|
||||
if (!isTimeout || encryption.scheme !== "nip44_v2") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const state = ensureEncryptionState(context);
|
||||
if (state.unsupported.has("nip04")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { schemes, explicit } = getWalletSupportedEncryption(context.infoEvent);
|
||||
if (explicit && schemes.includes("nip44_v2") && !schemes.includes("nip04")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getEncryptionCandidates(context).some((candidate) => {
|
||||
if (candidate.scheme !== "nip04") {
|
||||
return false;
|
||||
}
|
||||
return !state.unsupported.has(candidate.scheme);
|
||||
});
|
||||
}
|
||||
|
||||
function finalizePendingRequest(entry) {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return;
|
||||
@@ -1067,11 +1106,9 @@ async function sendWalletRequest(context, payload, { timeoutMs, __internalRetry
|
||||
} catch (error) {
|
||||
const encryption = context?.encryption || null;
|
||||
if (
|
||||
!__internalRetry &&
|
||||
encryption &&
|
||||
error &&
|
||||
typeof error === "object" &&
|
||||
(error.code === "UNSUPPORTED_ENCRYPTION" || error.code === "unsupported_encryption")
|
||||
shouldRetryWithFallback(context, error, encryption, {
|
||||
hasRetried: __internalRetry === true,
|
||||
})
|
||||
) {
|
||||
rememberUnsupportedEncryption(context, encryption.scheme);
|
||||
context.encryption = null;
|
||||
|
||||
Reference in new issue
Block a user