Add relay metadata to zap requests

This commit is contained in:
thePR0M3TH3AN committed 2025-10-29 14:06:02 -04:00
1 parent 991d1cc7fb
commit c8a3bff57d
2 files changed
+65

No files matched your search

+40
View File
@@ -10,6 +10,7 @@ import {
} from "./lnurl.js";
import { ensureWallet, sendPayment } from "./nwcClient.js";
import { getPlatformLightningAddress } from "./platformAddress.js";
import { RELAY_URLS } from "../nostr/toolkit.js";
import { userLogger } from "../utils/logger.js";
import {
clampPercent,
@@ -271,6 +272,40 @@ function derivePointerTag(videoEvent) {
return ["a", value];
}
function resolveRelayUrls(wallet) {
const normalized = [];
const seen = new Set();
const addCandidate = (candidate) => {
if (!candidate) {
return;
}
if (Array.isArray(candidate)) {
candidate.forEach(addCandidate);
return;
}
if (typeof candidate === "string") {
const trimmed = candidate.trim();
if (trimmed && !seen.has(trimmed)) {
seen.add(trimmed);
normalized.push(trimmed);
}
}
};
if (wallet && typeof wallet === "object") {
addCandidate(wallet.relayUrls);
addCandidate(wallet.relays);
addCandidate(wallet.relayUrl);
}
if (!normalized.length) {
addCandidate(Array.isArray(RELAY_URLS) ? RELAY_URLS : []);
}
return normalized;
}
function buildZapRequest({
wallet,
recipientPubkey,
@@ -302,6 +337,11 @@ function buildZapRequest({
tags.push(["amount", String(Math.max(0, Math.round(amountSats)) * 1000)]);
}
const relayUrls = resolveRelayUrls(wallet);
if (relayUrls.length) {
tags.push(["relays", ...relayUrls]);
}
const event = {
kind: ZAP_KIND,
content: comment || "",