// 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 = `
${escapeAttr(p.address)}