mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-03-13 14:29:07 +00:00
Merge pull request #125 from PR0M3TH3AN/codex/add-lightning-button-visibility-check
Hide Zap buttons for profiles without lightning addresses
This commit is contained in:
29
js/app.js
29
js/app.js
@@ -930,6 +930,7 @@ class bitvidApp {
|
||||
this.copyMagnetBtn = document.getElementById("copyMagnetBtn") || null;
|
||||
this.shareBtn = document.getElementById("shareBtn") || null;
|
||||
this.modalZapBtn = document.getElementById("modalZapBtn") || null;
|
||||
this.setModalZapVisibility(false);
|
||||
|
||||
// Attach existing event listeners for copy/share
|
||||
if (this.copyMagnetBtn) {
|
||||
@@ -2842,6 +2843,22 @@ class bitvidApp {
|
||||
this.shareBtn.classList.toggle("cursor-not-allowed", !enabled);
|
||||
}
|
||||
|
||||
setModalZapVisibility(visible) {
|
||||
if (!this.modalZapBtn) {
|
||||
return;
|
||||
}
|
||||
const shouldShow = !!visible;
|
||||
this.modalZapBtn.classList.toggle("hidden", !shouldShow);
|
||||
this.modalZapBtn.disabled = !shouldShow;
|
||||
this.modalZapBtn.setAttribute("aria-disabled", (!shouldShow).toString());
|
||||
this.modalZapBtn.setAttribute("aria-hidden", (!shouldShow).toString());
|
||||
if (shouldShow) {
|
||||
this.modalZapBtn.removeAttribute("tabindex");
|
||||
} else {
|
||||
this.modalZapBtn.setAttribute("tabindex", "-1");
|
||||
}
|
||||
}
|
||||
|
||||
getShareUrlBase() {
|
||||
try {
|
||||
const current = new URL(window.location.href);
|
||||
@@ -5218,6 +5235,7 @@ class bitvidApp {
|
||||
originalMagnet: magnetCandidate,
|
||||
torrentSupported: magnetSupported,
|
||||
legacyInfoHash: video.legacyInfoHash || legacyInfoHash,
|
||||
lightningAddress: null,
|
||||
};
|
||||
|
||||
this.currentMagnetUri = sanitizedMagnet || null;
|
||||
@@ -5233,6 +5251,8 @@ class bitvidApp {
|
||||
)}`;
|
||||
window.history.pushState({}, "", pushUrl);
|
||||
|
||||
this.setModalZapVisibility(false);
|
||||
let lightningAddress = "";
|
||||
let creatorProfile = {
|
||||
name: "Unknown",
|
||||
picture: `https://robohash.org/${video.pubkey}`,
|
||||
@@ -5243,6 +5263,7 @@ class bitvidApp {
|
||||
]);
|
||||
if (userEvents.length > 0 && userEvents[0]?.content) {
|
||||
const data = JSON.parse(userEvents[0].content);
|
||||
lightningAddress = (data.lud16 || data.lud06 || "").trim();
|
||||
creatorProfile = {
|
||||
name: data.name || data.display_name || "Unknown",
|
||||
picture: data.picture || `https://robohash.org/${video.pubkey}`,
|
||||
@@ -5252,6 +5273,11 @@ class bitvidApp {
|
||||
this.log("Error fetching creator profile:", error);
|
||||
}
|
||||
|
||||
this.setModalZapVisibility(!!lightningAddress);
|
||||
if (this.currentVideo) {
|
||||
this.currentVideo.lightningAddress = lightningAddress || null;
|
||||
}
|
||||
|
||||
const creatorNpub = this.safeEncodeNpub(video.pubkey) || video.pubkey;
|
||||
if (this.videoTitle) {
|
||||
this.videoTitle.textContent = video.title || "Untitled";
|
||||
@@ -5295,6 +5321,8 @@ class bitvidApp {
|
||||
const magnetSupported = isValidMagnetUri(usableMagnet);
|
||||
const sanitizedMagnet = magnetSupported ? usableMagnet : "";
|
||||
|
||||
this.setModalZapVisibility(false);
|
||||
|
||||
trackVideoView({
|
||||
videoId:
|
||||
typeof title === "string" && title.trim().length > 0
|
||||
@@ -5322,6 +5350,7 @@ class bitvidApp {
|
||||
magnet: sanitizedMagnet,
|
||||
originalMagnet: trimmedMagnet,
|
||||
torrentSupported: magnetSupported,
|
||||
lightningAddress: null,
|
||||
};
|
||||
|
||||
this.currentMagnetUri = sanitizedMagnet || null;
|
||||
|
||||
@@ -11,6 +11,35 @@ import { attachUrlHealthBadges } from "./urlHealthObserver.js";
|
||||
import { initialBlacklist, initialWhitelist } from "./lists.js";
|
||||
import { isWhitelistEnabled } from "./config.js";
|
||||
|
||||
let cachedZapButton = null;
|
||||
|
||||
function getChannelZapButton() {
|
||||
if (cachedZapButton && !document.body.contains(cachedZapButton)) {
|
||||
cachedZapButton = null;
|
||||
}
|
||||
if (!cachedZapButton) {
|
||||
cachedZapButton = document.getElementById("zapButton");
|
||||
}
|
||||
return cachedZapButton;
|
||||
}
|
||||
|
||||
function setChannelZapVisibility(visible) {
|
||||
const zapButton = getChannelZapButton();
|
||||
if (!zapButton) {
|
||||
return;
|
||||
}
|
||||
const shouldShow = !!visible;
|
||||
zapButton.classList.toggle("hidden", !shouldShow);
|
||||
zapButton.disabled = !shouldShow;
|
||||
zapButton.setAttribute("aria-disabled", (!shouldShow).toString());
|
||||
zapButton.setAttribute("aria-hidden", (!shouldShow).toString());
|
||||
if (shouldShow) {
|
||||
zapButton.removeAttribute("tabindex");
|
||||
} else {
|
||||
zapButton.setAttribute("tabindex", "-1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the channel profile view.
|
||||
* Called when #view=channel-profile&npub=...
|
||||
@@ -59,11 +88,13 @@ export async function initChannelProfileView() {
|
||||
}
|
||||
|
||||
function setupZapButton() {
|
||||
const zapButton = document.getElementById("zapButton");
|
||||
const zapButton = getChannelZapButton();
|
||||
if (!zapButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
setChannelZapVisibility(false);
|
||||
|
||||
if (zapButton.dataset.initialized === "true") {
|
||||
return;
|
||||
}
|
||||
@@ -182,15 +213,27 @@ async function loadUserProfile(pubkey) {
|
||||
|
||||
// Lightning Address
|
||||
const lnEl = document.getElementById("channelLightning");
|
||||
const lightningAddress = (meta.lud16 || meta.lud06 || "").trim();
|
||||
if (lnEl) {
|
||||
lnEl.textContent =
|
||||
meta.lud16 || meta.lud06 || "No lightning address found.";
|
||||
lightningAddress || "No lightning address found.";
|
||||
}
|
||||
setChannelZapVisibility(!!lightningAddress);
|
||||
} else {
|
||||
console.warn("No metadata found for this user.");
|
||||
setChannelZapVisibility(false);
|
||||
const lnEl = document.getElementById("channelLightning");
|
||||
if (lnEl) {
|
||||
lnEl.textContent = "No lightning address found.";
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch user profile data:", err);
|
||||
setChannelZapVisibility(false);
|
||||
const lnEl = document.getElementById("channelLightning");
|
||||
if (lnEl) {
|
||||
lnEl.textContent = "No lightning address found.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user