SHA256
Перевести донаты на Stars и обновить Devnet
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { authService } from '../state.js';
|
||||
import { formatLamportsSol } from '../services/shine-support-amount.js';
|
||||
import { getSolanaCluster } from '../services/solana-rpc-gateway.js';
|
||||
import { formatStars } from '../services/shine-support-amount.js';
|
||||
|
||||
export function supportStatsValues(stats = {}) {
|
||||
const sent = BigInt(stats.supportSent ?? 0);
|
||||
const received = BigInt(stats.supportReceived ?? 0);
|
||||
const daoDirect = BigInt(stats.daoDirect ?? 0);
|
||||
return [sent, received, sent / 10n + daoDirect];
|
||||
return [sent, received, daoDirect];
|
||||
}
|
||||
|
||||
/** Adds an independent asynchronous block; failure/Free accounts do not get fictitious statistics. */
|
||||
@@ -20,7 +21,87 @@ export function attachSupportStats(parent, { login, isActive = () => true }) {
|
||||
content.className = 'meta-muted';
|
||||
content.textContent = t('screens.support_phase2.loading');
|
||||
section.append(title, content);
|
||||
const history = document.createElement('details');
|
||||
history.className = 'profile-support-history';
|
||||
const historySummary = document.createElement('summary');
|
||||
historySummary.textContent = t('screens.support_phase2.history');
|
||||
const historyRows = document.createElement('div');
|
||||
historyRows.className = 'stack';
|
||||
historyRows.style.cssText = 'gap:8px;margin-top:10px;';
|
||||
history.append(historySummary, historyRows);
|
||||
section.append(history);
|
||||
parent.append(section);
|
||||
let historyOffset = 0;
|
||||
let loadingHistory = false;
|
||||
let historyLoaded = false;
|
||||
const historyLogin = String(login || '').trim().toLowerCase();
|
||||
const loadHistory = async () => {
|
||||
if (loadingHistory || !isActive() || !section.isConnected) return;
|
||||
loadingHistory = true;
|
||||
const note = document.createElement('div');
|
||||
note.className = 'meta-muted';
|
||||
note.textContent = t('screens.support_phase2.loading');
|
||||
historyRows.append(note);
|
||||
try {
|
||||
const result = await authService.getSupportHistory(login, 20, historyOffset);
|
||||
if (!isActive() || !section.isConnected) return;
|
||||
note.remove();
|
||||
if (!result.ready) {
|
||||
historyRows.textContent = t('screens.support_phase2.loading');
|
||||
return;
|
||||
}
|
||||
if (!historyOffset && !result.transfers?.length) {
|
||||
historyRows.textContent = t('screens.support_phase2.no_history');
|
||||
}
|
||||
const more = historyRows.querySelector('[data-stars-more]');
|
||||
more?.remove();
|
||||
for (const transfer of result.transfers || []) {
|
||||
const outgoing = transfer.senderLogin?.trim().toLowerCase() === historyLogin;
|
||||
const cents = transfer.kind === 'DAO' || outgoing
|
||||
? transfer.amountStarCents : transfer.recipientStarCents;
|
||||
const row = document.createElement('div');
|
||||
row.className = 'row';
|
||||
row.style.cssText = 'display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:6px;';
|
||||
const info = document.createElement('span');
|
||||
info.textContent = transfer.kind === 'DAO'
|
||||
? t('screens.support_phase2.history_dao')
|
||||
: `${outgoing ? '→' : '←'} ${outgoing ? transfer.recipientLogin : transfer.senderLogin}`;
|
||||
const value = document.createElement('strong');
|
||||
value.textContent = `${outgoing ? '−' : '+'}${formatStars(cents)}`;
|
||||
const detail = document.createElement('small');
|
||||
detail.className = 'meta-muted';
|
||||
const date = transfer.blockTime ? new Date(Number(transfer.blockTime) * 1000).toLocaleString() : '';
|
||||
const lamports = BigInt(transfer.amountLamports || '0');
|
||||
const sol = `${lamports / 1_000_000_000n}.${String(lamports % 1_000_000_000n).padStart(9, '0').replace(/0+$/, '') || '0'} SOL`;
|
||||
detail.textContent = `${date} · ${sol}`;
|
||||
const explorer = document.createElement('a');
|
||||
const sig = String(transfer.signature || '');
|
||||
if (/^[1-9A-HJ-NP-Za-km-z]{64,90}$/.test(sig)) {
|
||||
const network = getSolanaCluster();
|
||||
explorer.href = `https://explorer.solana.com/tx/${sig}${network && network !== 'mainnet-beta' ? `?cluster=${encodeURIComponent(network)}` : ''}`;
|
||||
explorer.target = '_blank'; explorer.rel = 'noopener noreferrer';
|
||||
explorer.textContent = t('screens.support_phase2.transaction');
|
||||
row.append(info, value, detail, explorer);
|
||||
} else row.append(info, value, detail);
|
||||
historyRows.append(row);
|
||||
}
|
||||
historyOffset += (result.transfers || []).length;
|
||||
if (result.hasMore) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'text-btn'; btn.type = 'button';
|
||||
btn.dataset.starsMore = '1';
|
||||
btn.textContent = t('screens.support_phase2.more');
|
||||
btn.addEventListener('click', () => void loadHistory());
|
||||
historyRows.append(btn);
|
||||
}
|
||||
historyLoaded = true;
|
||||
} catch {
|
||||
if (isActive() && section.isConnected) note.textContent = t('screens.support_phase2.history_unavailable');
|
||||
} finally { loadingHistory = false; }
|
||||
};
|
||||
history.addEventListener('toggle', () => {
|
||||
if (history.open && !historyLoaded) void loadHistory();
|
||||
});
|
||||
let pendingRefresh = null;
|
||||
const scheduleRetry = () => {
|
||||
if (pendingRefresh !== null) return;
|
||||
@@ -45,9 +126,9 @@ export function attachSupportStats(parent, { login, isActive = () => true }) {
|
||||
return;
|
||||
}
|
||||
const values = supportStatsValues({
|
||||
supportSent: stats.supportSentLamports,
|
||||
supportReceived: stats.supportReceivedLamports,
|
||||
daoDirect: stats.daoDirectLamports,
|
||||
supportSent: stats.supportSentStarCents,
|
||||
supportReceived: stats.supportReceivedStarCents,
|
||||
daoDirect: stats.daoDirectStarCents,
|
||||
});
|
||||
content.replaceChildren();
|
||||
content.className = 'stack';
|
||||
@@ -58,7 +139,7 @@ export function attachSupportStats(parent, { login, isActive = () => true }) {
|
||||
const name = document.createElement('span');
|
||||
const amount = document.createElement('strong');
|
||||
name.textContent = label;
|
||||
amount.textContent = `${formatLamportsSol(values[idx])} SOL`;
|
||||
amount.textContent = formatStars(values[idx]);
|
||||
row.append(name, amount);
|
||||
content.append(row);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user