import { createTopBar } from '../components/topbar.js'; import { authService, state } from '../state.js'; import { navigateBack } from '../router.js'; import { makeShineChannelRootRoute, makeShineChannelShortRoute } from '../services/shine-routes.js'; import { showToast } from '../services/channels-ux.js'; import { toUserMessage } from '../services/ui-error-texts.js'; export const pageMeta = { id: 'channel-about-view', title: 'О канале' }; function escapeHtml(text) { return String(text || '') .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } function normalizeHash(hash) { const normalized = String(hash || '').trim().toLowerCase(); return normalized || '0'; } function toSafeInt(value) { const parsed = Number(value); return Number.isFinite(parsed) ? parsed : null; } function findCachedChannel(ownerBlockchainName, channelRootBlockNumber, channelRootBlockHash) { const ownerBch = String(ownerBlockchainName || '').trim().toLowerCase(); const rootNo = Number(channelRootBlockNumber); const rootHash = normalizeHash(channelRootBlockHash); const rows = Object.values(state.channelsIndex || {}); return rows.find((row) => ( String(row?.channel?.ownerBlockchainName || '').trim().toLowerCase() === ownerBch && Number(row?.channel?.channelRoot?.blockNumber) === rootNo && normalizeHash(row?.channel?.channelRoot?.blockHash) === rootHash )) || null; } function buildChannelLink(route) { if (!route) return ''; const url = new URL(window.location.href); url.pathname = `/${String(route).replace(/^\/+/, '')}`; url.hash = ''; return url.toString(); } function statsText(value) { return Number.isFinite(Number(value)) ? String(Math.max(0, Number(value))) : '0'; } export function render({ navigate, route, chrome }) { const ownerBlockchainName = String(route?.params?.ownerBlockchainName || '').trim(); const channelRootBlockNumber = toSafeInt(route?.params?.channelRootBlockNumber); const channelRootBlockHash = normalizeHash(route?.params?.channelRootBlockHash); const channelRoute = makeShineChannelRootRoute({ ownerBlockchainName, channelRootBlockNumber, channelRootBlockHash, }); const screen = document.createElement('section'); screen.className = 'stack channels-screen channels-screen--channel-about'; const topbar = createTopBar({ title: 'О канале', back: { label: '←', onClick: () => { if (window.history.length > 1) { navigateBack(); return; } if (channelRoute) navigate(channelRoute); }, ariaLabel: 'Назад', title: 'Назад', }, }); chrome?.setTopbar(topbar); const card = document.createElement('div'); card.className = 'card stack channel-about-card'; card.innerHTML = `