import { authService } from '../state.js'; // Один запрос на канал; только сервер проверяет привязку транзакции к блоку. const cache = new Map(); export function loadVerifiedSupportTotals(selector) { const number = Number(selector?.channelRootBlockNumber); const hash = String(selector?.channelRootBlockHash || '').toLowerCase(); if (!Number.isSafeInteger(number) || !/^[0-9a-f]{64}$/.test(hash)) return Promise.resolve(null); const key = `${number}:${hash}`; if (!cache.has(key)) { const promise = authService.getSupportTotals({ channelRootBlockNumber: number, channelRootBlockHash: hash }) .then((response) => { const messages = new Map(); for (const row of response?.messages || []) { const id = `${String(row.blockNumber)}:${String(row.blockHash).toLowerCase()}`; messages.set(id, String(row.receivedStarCents)); } return { channelReceivedStarCents: String(response?.channelReceivedStarCents || '0'), messages }; }) .catch(() => { cache.delete(key); return null; }); cache.set(key, promise); } return cache.get(key); } export function formatVerifiedSupportStars(value) { try { const n = BigInt(value); if (n <= 0n) return null; const whole = n / 100n; const fraction = String(n % 100n).padStart(2, '0'); return `${whole}.${fraction} ⭐`; } catch { return null; } }