// 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; // ---------- 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"}`); menu.innerHTML = `
Signed in via ${escapeAttr(p.source === "wc" ? "WizardConnect" : "seed phrase")} ${escapeAttr(p.address)}
πŸ“‹ My namesrecords & holdings πŸ›  Admin paneloperator tools
πŸšͺ Sign outclear this browser `; } else { const dot = ``; btn.innerHTML = `${dot}Wallet`; btn.setAttribute("aria-label", "Wallet β€” not signed in"); // Each item opens the shared mint modal (js/register-flow.js) at the // matching wallet step, in sign-in-only mode. No navigation, no separate // portal page β€” everything happens inline on whatever page the user is // on. profile-menu.js loads register-flow.js on demand. menu.innerHTML = `
No wallet yet Sign in to see your names
πŸ†• New walletgenerate a fresh 12-word phrase πŸ“₯ Import a phraseseed you already have πŸ”— WizardConnectCashonize / Paytaca via QR `; } } render(); // ---------- open/close ---------- const open = () => { render(); menu.hidden = false; btn.setAttribute("aria-expanded", "true"); }; const close = () => { menu.hidden = true; btn.setAttribute("aria-expanded", "false"); }; btn.addEventListener("click", (e) => { e.stopPropagation(); menu.hidden ? open() : close(); }); document.addEventListener("click", (e) => { if (!wrap.contains(e.target)) close(); }); document.addEventListener("keydown", (e) => { if (e.key === "Escape") close(); }); // Cross-tab (storage event fires only in other tabs) + same-tab (portal.html // dispatches this after writing/clearing) β€” either wakes render(). window.addEventListener("storage", (e) => { if (e.key === "siriusProfile") render(); }); window.addEventListener("siriusProfileChanged", render); // ---------- menu actions ---------- // Sign-out clears siriusProfile; the wallet-onboarding items (new/import/wc) // open the shared mint modal inline (register-flow.js). If the page did not // ship register-flow.js in its own