const nodeInfoButton = document.querySelector("[data-node-info]"); const nodeModal = document.querySelector("[data-node-modal]"); const nodeCloseButton = document.querySelector("[data-node-close]"); const nftInstructionsOpenButton = document.querySelector("[data-nft-instructions-open]"); const nftInstructionsModal = document.querySelector("[data-nft-instructions-modal]"); const nftInstructionsCloseButton = document.querySelector("[data-nft-instructions-close]"); function toggleNodeModal(open) { if (!nodeModal) { return; } nodeModal.classList.toggle("hidden", !open); if (open) { startNodeInfoRefresh(); return; } stopNodeInfoRefresh(); } function toggleNftInstructionsModal(open) { nftInstructionsModal?.classList.toggle("hidden", !open); } nodeInfoButton?.addEventListener("click", () => toggleNodeModal(true)); nodeCloseButton?.addEventListener("click", () => toggleNodeModal(false)); nodeModal?.addEventListener("click", (event) => { if (event.target === nodeModal) { toggleNodeModal(false); } }); nftInstructionsOpenButton?.addEventListener("click", () => toggleNftInstructionsModal(true)); nftInstructionsCloseButton?.addEventListener("click", () => toggleNftInstructionsModal(false)); nftInstructionsModal?.addEventListener("click", (event) => { if (event.target === nftInstructionsModal) { toggleNftInstructionsModal(false); } }); document.querySelectorAll(".nft-hosting-links a").forEach((link) => { link.addEventListener("click", async (event) => { event.preventDefault(); const url = link.href; const invoke = window.__TAURI__?.core?.invoke; if (invoke) { try { await invoke("open_external_url", { url }); return; } catch (error) { console.error(error); } } window.open(url, "_blank", "noopener,noreferrer"); }); }); document.addEventListener("keydown", (event) => { if (event.key === "Escape") { toggleNodeModal(false); toggleNftInstructionsModal(false); if (!walletSwitchModal?.classList.contains("hidden")) { closeWalletSwitchModal(); } if (!historyExportModal?.classList.contains("hidden")) { toggleHistoryExportModal(false); } if (!backupKeyModal?.classList.contains("hidden")) { closeBackupKeyModal(null); } } }); topWalletListSelect?.addEventListener("change", () => { const selectedWalletPath = topWalletListSelect.value; if (!selectedWalletPath || selectedWalletPath === activeWalletPath) { restoreActiveWalletSelection(); return; } openWalletSwitchModal(selectedWalletPath); }); walletSwitchForm?.addEventListener("submit", async (event) => { event.preventDefault(); if (!pendingWalletSwitch) { closeWalletSwitchModal(); return; } const walletKey = walletSwitchKeyInput?.value || ""; if (!walletKey.trim()) { setWalletSwitchMessage("Wallet key cannot be empty.", "error"); walletSwitchKeyInput?.focus(); return; } if (walletSwitchSubmit) { walletSwitchSubmit.disabled = true; } setWalletSwitchMessage("Unlocking wallet..."); try { const wallet = await loadWalletByPath(pendingWalletSwitch.walletPath, walletKey); updateActiveWallet(wallet); document.body.classList.add("wallet-open"); closeWalletSwitchModal({ restoreSelection: false }); await populateTopWalletList(); } catch (error) { setWalletSwitchMessage(String(error), "error"); walletSwitchKeyInput?.focus(); } finally { if (walletSwitchSubmit) { walletSwitchSubmit.disabled = false; } } }); walletSwitchCloseButton?.addEventListener("click", () => closeWalletSwitchModal()); walletSwitchCancelButton?.addEventListener("click", () => closeWalletSwitchModal()); walletSwitchModal?.addEventListener("click", (event) => { if (event.target === walletSwitchModal) { closeWalletSwitchModal(); } }); broadcastNodeButton?.addEventListener("change", () => { if (!walletLoaded) { return; } if (currentView === "send" && !issueTokenForm?.classList.contains("hidden")) { refreshIssueTokenList(); } if (registrationRegistered) { resetLatestDashboardTransactionsMemory(); stopLatestDashboardTransactionsPolling(); refreshReceivePage(); startRegisteredDashboardLoadSequence({ resetTransactions: true }); stopNetworkInfoRefresh(); updateNetworkInfoRefreshState(); if (!nodeModal?.classList.contains("hidden")) { refreshNetworkInfo({ target: "node", force: true }); } return; } refreshNetworkInfo({ target: "dashboard", force: !nodeModal?.classList.contains("hidden") }); refreshReceivePage(); checkWalletRegistrationOnce(); }); populateBroadcastNodeList();