SHA256
Доделать донаты и статистику поддержки
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { readShineUserPda } from '../services/shine-user-pda-service.js';
|
||||
import { authService } from '../state.js';
|
||||
import { formatLamportsSol } from '../services/shine-support-amount.js';
|
||||
|
||||
export function supportStatsValues(stats = {}) {
|
||||
@@ -10,7 +10,7 @@ export function supportStatsValues(stats = {}) {
|
||||
}
|
||||
|
||||
/** Adds an independent asynchronous block; failure/Free accounts do not get fictitious statistics. */
|
||||
export function attachSupportStats(parent, { login, solanaEndpoint, isActive = () => true }) {
|
||||
export function attachSupportStats(parent, { login, isActive = () => true }) {
|
||||
const section = document.createElement('section');
|
||||
section.className = 'card stack profile-support-stats';
|
||||
section.style.cssText = 'margin-top:12px;gap:8px;';
|
||||
@@ -21,11 +21,34 @@ export function attachSupportStats(parent, { login, solanaEndpoint, isActive = (
|
||||
content.textContent = t('screens.support_phase2.loading');
|
||||
section.append(title, content);
|
||||
parent.append(section);
|
||||
let pendingRefresh = null;
|
||||
const scheduleRetry = () => {
|
||||
if (pendingRefresh !== null) return;
|
||||
pendingRefresh = window.setTimeout(() => {
|
||||
pendingRefresh = null;
|
||||
if (isActive() && section.isConnected) void refresh();
|
||||
}, 10_000);
|
||||
};
|
||||
const refresh = async () => {
|
||||
try {
|
||||
const pda = await readShineUserPda({ login, solanaEndpoint });
|
||||
const stats = await authService.getSupportStats(login);
|
||||
if (!isActive() || !section.isConnected) return;
|
||||
const values = supportStatsValues(pda.supportStats ?? {});
|
||||
if (!stats.ready) {
|
||||
// Первичная индексация ещё идёт. Повторим запрос к кешу без RPC Solana.
|
||||
content.textContent = t('screens.support_phase2.loading');
|
||||
scheduleRetry();
|
||||
return;
|
||||
}
|
||||
if (!stats.available) {
|
||||
// Free-аккаунты не имеют Paid PDA, поэтому блок статистики не показываем.
|
||||
section.remove();
|
||||
return;
|
||||
}
|
||||
const values = supportStatsValues({
|
||||
supportSent: stats.supportSentLamports,
|
||||
supportReceived: stats.supportReceivedLamports,
|
||||
daoDirect: stats.daoDirectLamports,
|
||||
});
|
||||
content.replaceChildren();
|
||||
content.className = 'stack';
|
||||
[t('screens.support_phase2.sent'), t('screens.support_phase2.received'), t('screens.support_phase2.shine')].forEach((label, idx) => {
|
||||
|
||||
Reference in New Issue
Block a user