// Transforms the "๐ Sign in" nav pill on every Sirius.X page into a wallet // dropdown. Reads siriusProfile from localStorage; when null shows the three // onboarding actions (New wallet / Import a phrase / WizardConnect), when // present shows the signed-in menu (address, My names, Admin, Sign out). // // Each onboarding action deep-links portal.html?mode=new|import|wc; portal.html // picks that up and immediately runs the matching flow โ no extra click on // arrival. Signed-in state changes flip the button label without a reload: // the storage event covers cross-tab, a custom 'siriusProfileChanged' event // covers same-tab (portal.html and tld.html both dispatch it on write/clear). (() => { const anchor = document.querySelector(".topnav a.portal"); if (!anchor) return; // Base URL for local links โ the nav's brand link is already set with the // right relative path per page (./ at root, ../ in subdirs). Reuse it so // absolute /sirius-x/... paths (which break under the BCNR route) never // slip in. const PORTAL_URL = anchor.getAttribute("href") || "./portal.html"; const BASE = PORTAL_URL.replace(/portal\.html.*$/, ""); const ADMIN_URL = BASE + "admin/"; const readProfile = () => { try { return JSON.parse(localStorage.getItem("siriusProfile") || "null"); } catch { return null; } }; // Build wrapper + button + (empty) menu around the existing pill. const wrap = document.createElement("div"); wrap.className = "profile-wrap"; const btn = document.createElement("button"); btn.type = "button"; btn.className = anchor.className; // reuse .portal (and .here if present) btn.setAttribute("aria-haspopup", "menu"); btn.setAttribute("aria-expanded", "false"); const menu = document.createElement("div"); menu.className = "profile-menu"; menu.setAttribute("role", "menu"); menu.hidden = true; // Header "Dashboard" button โ sits left of the wallet pill and is the one // way into names, TLDs, the web-builder and (for the operator) the admin // panel. Always visible: signed out it lands on the portal's sign-in. const dash = document.createElement("a"); dash.className = "dash-link" + (/\/portal\.html(?:$|[?#])/.test(location.pathname) ? " here" : ""); dash.href = PORTAL_URL; dash.innerHTML = ` Dashboard`; const readWalletInfo = () => { try { return JSON.parse(localStorage.getItem("siriusWalletInfo") || "null"); } catch { return null; } }; const fmtInt = (n) => String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ","); // ---------- render ---------- // Re-renders the button label AND the menu innerHTML from the current // profile in localStorage. Called at load, on every open(), and whenever // another tab or this tab updates the storage key. function render() { const p = readProfile(); if (p) { const dot = ``; const label = shortAddr(p.address); const sourceBadge = p.source === "wc" ? `WC` : `seed`; btn.innerHTML = `${dot}${escapeAttr(label)}${sourceBadge}`; btn.setAttribute("aria-label", `Wallet ${label}, signed in via ${p.source || "seed"}`); // Wallet-only menu: identity, balance, receive, settings, sign out. // Names/TLDs/admin live behind the Dashboard button next to this one. const info = readWalletInfo(); const bal = info?.sats != null ? (window.siriusPricing?.formatBits ? window.siriusPricing.formatBits(info.sats) : `${(Number(info.sats) / 100).toLocaleString("en-US")} bits`) : "โ"; const held = info ? `${info.names ?? 0} name${info.names === 1 ? "" : "s"} ยท ${info.tlds ?? 0} TLD${info.tlds === 1 ? "" : "s"}` : "open the dashboard to load"; menu.innerHTML = `
${escapeAttr(p.address)}