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.receivedLamports)); } return { channelReceivedLamports: String(response?.channelReceivedLamports || '0'), messages }; }) .catch(() => { cache.delete(key); return null; }); cache.set(key, promise); } return cache.get(key); } export function formatVerifiedSupportLamports(value) { try { const n = BigInt(value); if (n <= 0n) return null; const whole = n / 1_000_000_000n; const fraction = String(n % 1_000_000_000n).padStart(9, '0').replace(/0+$/, ''); return `${whole}${fraction ? '.' + fraction : ''} SOL`; } catch { return null; } }