Обновить учёт поддержки, лайки и профиль перед MVP

This commit is contained in:
AidarKC
2026-12-02 00:01:51 +03:00
parent d05d9db8a2
commit af0beccb4a
21 changed files with 109 additions and 57 deletions
+10 -4
View File
@@ -19,10 +19,10 @@ export function hexHash32(value) {
return Uint8Array.from({ length: 32 }, (_, i) => parseInt(hex.slice(i * 2, i * 2 + 2), 16));
}
/** Integer Star cents: 0.10 minimum, exactly two decimal places maximum. */
/** Сумма поддержки: минимум и шаг 0,1 звезды. */
export function parseStarCents(input) {
const value = String(input ?? '').trim().replace(',', '.');
if (!/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/.test(value)) throw new Error('Введите сумму ⭐ с точностью до 0,01');
if (!/^(?:0|[1-9]\d*)(?:\.\d{1})?$/.test(value)) throw new Error('Введите сумму ⭐ с точностью до 0,1');
const [whole, frac = ''] = value.split('.');
const cents = BigInt(whole) * 100n + BigInt(frac.padEnd(2, '0') || '0');
if (cents < 10n || cents > 0xffff_ffff_ffff_ffffn) throw new Error('Минимальная поддержка — 0,10 ⭐');
@@ -31,10 +31,16 @@ export function parseStarCents(input) {
/** Только число («0.10»): для вёрстки, где единица показана отдельной SVG-иконкой. */
export function formatStarAmount(value) {
const cents = BigInt(value);
return `${cents / 100n}.${String(cents % 100n).padStart(2, '0')}`;
const tenths = (cents + 5n) / 10n;
return tenths === 0n ? '' : `${tenths / 10n}.${tenths % 10n}`;
}
export function formatStars(value) {
return `${formatStarAmount(value)} ⭐`;
const amount = formatStarAmount(value);
return amount ? `${amount} ⭐` : '⭐';
}
export function formatExactStars(value) {
const cents = BigInt(value);
return `${cents / 100n}.${String(cents % 100n).padStart(2, '0')} ⭐`;
}
export function splitStarCents(value) {
const cents = BigInt(value);
@@ -1,4 +1,5 @@
import { authService } from '../state.js';
import { formatStars } from './shine-support-amount.js';
// Один запрос на канал; только сервер проверяет привязку транзакции к блоку.
const cache = new Map();
@@ -26,9 +27,6 @@ export function loadVerifiedSupportTotals(selector) {
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} ⭐`;
return formatStars(n);
} catch { return null; }
}