Перевести донаты на Stars и обновить Devnet

This commit is contained in:
AidarKC
2026-11-14 00:55:02 +03:00
parent c972a975fd
commit 97db033eb8
39 changed files with 1020 additions and 198 deletions
+21 -12
View File
@@ -15,9 +15,10 @@ import { toUserMessage } from '../services/ui-error-texts.js';
import { bytesToBase58 } from '../services/crypto-utils.js';
import { loadEncryptedUserSecrets } from '../services/key-vault.js';
import { readShineUserPda, supportShineUserOnSolana } from '../services/shine-user-pda-service.js';
import { parseSolLamports, formatLamportsSol, hexHash32 } from '../services/shine-support-amount.js';
import { parseStarCents, splitStarCents, formatStars, starCentsToLamports, formatLamportsSol, hexHash32 } from '../services/shine-support-amount.js';
import { transferSolLamports } from '../services/solana-wallet-service.js';
import { loadVerifiedSupportTotals, formatVerifiedSupportLamports } from '../services/support-totals-service.js';
import { getStarsQuoteFromRpc } from '../services/shine-stars-pyth.js';
import { loadVerifiedSupportTotals, formatVerifiedSupportStars } from '../services/support-totals-service.js';
export const pageMeta = { id: 'channel-donate-view', get title() { return t('screens.channel_donate_view.text_001'); } };
@@ -189,7 +190,7 @@ export function render({ navigate, route, chrome }) {
<label class="field-label" for="channel-donate-amount">${th('screens.channel_donate_view.text_029')}</label>
<div class="channel-donate-amount-row">
<input class="input" id="channel-donate-amount" type="text" inputmode="decimal" placeholder="0.1" autocomplete="off" />
<span>SOL</span>
<span>⭐</span>
</div>
</section>
@@ -198,7 +199,7 @@ export function render({ navigate, route, chrome }) {
<p class="meta-muted inline-error channel-donate-status" id="channel-donate-status"></p>
<div class="channel-donate-result" id="channel-donate-result" hidden></div>
<button class="primary-btn channel-donate-submit" id="channel-donate-submit" type="button" ${recipientChoices.length && recipientPda ? '' : 'disabled'}>${th('screens.support_flow.donate')}</button>
<button class="secondary-btn channel-donate-submit" id="channel-donate-direct" type="button" ${recipientChoices.length ? '' : 'disabled'}>${th('screens.support_flow.direct')}</button>
`;
const recipientSelect = content.querySelector('#channel-donate-recipient-key');
@@ -289,12 +290,17 @@ export function render({ navigate, route, chrome }) {
});
refreshEl?.addEventListener('click', () => void refreshBalance());
let starsQuote = null;
const renderSplit = () => {
try {
const amount = parseSolLamports(amountEl?.value || '');
if (splitEl) splitEl.textContent = `${t('screens.support_flow.recipient')}: ${formatLamportsSol(amount * 9n / 10n)} SOL · ${t('screens.support_flow.fund')}: ${formatLamportsSol(amount / 10n)} SOL`;
} catch { if (splitEl) splitEl.textContent = ''; }
const cents = parseStarCents(amountEl?.value || '');
const parts = splitStarCents(cents);
const sol = starsQuote ? ` · ≈ ${formatLamportsSol(starCentsToLamports(cents, starsQuote.solUsdE8, starsQuote.usdtUsdE8))} SOL` : '';
if (splitEl) splitEl.textContent = `${t('screens.support_flow.recipient')}: ${formatStars(parts.author)} · ${t('screens.support_flow.fund')}: ${formatStars(parts.dao)}${sol}`;
} catch { if (splitEl) splitEl.textContent = 'Минимальная поддержка 0,10 ⭐'; }
};
void getStarsQuoteFromRpc({ solanaEndpoint: state.entrySettings.solanaServer }).then(v => { starsQuote = v; if (!disposed) renderSplit(); })
.catch(() => { if (splitEl && !disposed) splitEl.textContent = 'Курс временно недоступен'; });
if (explanationEl) explanationEl.textContent = recipientPda
? t('screens.support_flow.explanation')
: t('screens.support_flow.paid_required');
@@ -304,10 +310,10 @@ export function render({ navigate, route, chrome }) {
if (busy || disposed) return;
const recipient = selectedRecipient();
if (!recipient?.address) { setStatus(t('screens.channel_donate_view.text_007'), 'error'); return; }
let amount;
let amount, cents;
try {
amount = parseSolLamports(amountEl?.value || '');
if (!direct && amount % 10n !== 0n) throw new Error(t('screens.support_flow.divisible'));
cents = parseStarCents(amountEl?.value || '');
if (direct) throw new Error('Прямой перевод отключён в системе Stars');
} catch (error) { setStatus(error.message || t('screens.channel_donate_view.text_008'), 'error'); return; }
if (direct && !window.confirm(t('screens.support_flow.direct_warning'))) return;
@@ -315,6 +321,8 @@ export function render({ navigate, route, chrome }) {
setStatus(t('screens.channel_donate_view.text_009'));
if (resultEl) { resultEl.hidden = true; resultEl.innerHTML = ''; }
try {
starsQuote = await getStarsQuoteFromRpc({ solanaEndpoint: state.entrySettings.solanaServer });
amount = starCentsToLamports(cents, starsQuote.solUsdE8, starsQuote.usdtUsdE8);
const wallet = await resolveSenderWallet();
let result;
if (direct) {
@@ -337,6 +345,7 @@ export function render({ navigate, route, chrome }) {
if (!secrets?.blockchainKey || !secrets?.clientKey) throw new Error(t('screens.support_flow.keys_required'));
result = await supportShineUserOnSolana({
senderLogin: login, recipientLogin: ownerLogin, amountLamports: amount,
starCents: cents, oracleAccounts: { solUsd: starsQuote.solOracleAccount, usdtUsd: starsQuote.usdtOracleAccount },
target: { type: 1, channelBlockNumber: BigInt(selector.channelRootBlockNumber), channelBlockHash: hexHash32(selector.channelRootBlockHash) },
solanaEndpoint: state.entrySettings.solanaServer,
blockchainPrivatePkcs8B64: secrets.blockchainKey,
@@ -347,7 +356,7 @@ export function render({ navigate, route, chrome }) {
setStatus('');
if (resultEl) {
resultEl.hidden = false;
resultEl.innerHTML = `<strong>${th('screens.channel_donate_view.text_031')}</strong><span>${escapeHtml(formatLamportsSol(amount))} SOL → ${escapeHtml(recipient.label)}</span><code>${escapeHtml(String(result.signature || ''))}</code>`;
resultEl.innerHTML = `<strong>${th('screens.channel_donate_view.text_031')}</strong><span>${escapeHtml(formatStars(cents))} → ${escapeHtml(recipient.label)}</span><code>${escapeHtml(String(result.signature || ''))}</code>`;
}
showToast(t('screens.channel_donate_view.text_010'));
const balance = await getBalanceSol({ endpoint: state.entrySettings.solanaServer, address: wallet.address });
@@ -363,7 +372,7 @@ export function render({ navigate, route, chrome }) {
void loadVerifiedSupportTotals(selector).then((totals) => {
if (disposed) return;
const label = content.querySelector('#channel-donate-verified-total');
const total = totals && formatVerifiedSupportLamports(totals.channelReceivedLamports);
const total = totals && formatVerifiedSupportStars(totals.channelReceivedStarCents);
if (label && total) label.textContent = `${t('screens.support_phase3.channel_total')}: ${total}`;
});
updateRecipientAddress();
+2 -2
View File
@@ -1,6 +1,6 @@
import { openShineSupportDialog } from '../components/shine-support-dialog.js';
import { hexHash32 } from '../services/shine-support-amount.js';
import { loadVerifiedSupportTotals, formatVerifiedSupportLamports } from '../services/support-totals-service.js';
import { loadVerifiedSupportTotals, formatVerifiedSupportStars } from '../services/support-totals-service.js';
import { formatDateTime, getIntlLocale } from '../i18n/format.js';
import { t, th } from '../i18n/index.js';
import { appendShineMessageLinks } from '../services/shine-message-links.js';
@@ -2169,7 +2169,7 @@ function renderPostCard(post, {
const messageId = `${String(post.messageRef.blockNumber)}:${String(post.messageRef.blockHash).toLowerCase()}`;
void loadVerifiedSupportTotals(selector).then((totals) => {
if (!totals || !supportButton.isConnected) return;
const formatted = formatVerifiedSupportLamports(totals.messages.get(messageId));
const formatted = formatVerifiedSupportStars(totals.messages.get(messageId));
if (formatted) supportButton.textContent = `♥ ${formatted}`;
});
}