import { createTopBar } from '../components/topbar.js'; import { showToast } from '../services/channels-ux.js'; import { state } from '../state.js'; import { formatSol, getBalanceSol, getTopupSiteUrl, } from '../services/solana-wallet-service.js'; import { loadSolanaWeb3 } from '../vendor/solana-web3-loader.js'; import { actionErrorText } from '../services/ui-error-texts.js'; export const pageMeta = { id: 'topup-view', title: 'Пополнение solana счета', showAppChrome: false }; const DEVNET_ENDPOINT = 'https://api.devnet.solana.com'; const REGISTRATION_TOPUP_AMOUNT_SOL = 0.02; // Канонический Solana-кошелёк пользователя = текущий blockchain key. // Тот же адрес используется как fee payer для регистрации и обычных PDA update. async function blockchainWalletAddressFromBundle() { const keyBundle = state.registrationDraft.preGeneratedKeyBundle; if (!keyBundle || !keyBundle.blockchainPair) { throw new Error('Ключи ещё не сгенерированы. Вернитесь на экран регистрации.'); } const raw = atob(keyBundle.blockchainPair.publicKeyB64); const bytes = new Uint8Array(raw.length); for (let i = 0; i < raw.length; i += 1) bytes[i] = raw.charCodeAt(i); const { PublicKey } = await loadSolanaWeb3(); return new PublicKey(bytes).toBase58(); } export function render({ navigate }) { const screen = document.createElement('section'); screen.className = 'stack'; const walletValue = document.createElement('input'); walletValue.className = 'input'; walletValue.type = 'text'; walletValue.value = state.registrationPayment.walletAddress || ''; walletValue.readOnly = true; walletValue.style.fontSize = '13px'; const status = document.createElement('p'); status.className = 'meta-muted'; status.textContent = 'Проверяем кошелек...'; status.style.whiteSpace = 'pre-wrap'; status.style.overflowWrap = 'anywhere'; status.style.wordBreak = 'break-word'; status.style.fontSize = '13px'; const copyButton = document.createElement('button'); copyButton.className = 'ghost-btn'; copyButton.type = 'button'; copyButton.textContent = 'Скопировать'; copyButton.addEventListener('click', async () => { try { await navigator.clipboard.writeText(walletValue.value); copyButton.textContent = 'Скопировано'; window.setTimeout(() => { copyButton.textContent = 'Скопировать'; }, 1500); } catch { showToast('Не удалось скопировать номер кошелька – выделите его и скопируйте вручную.', { kind: 'error' }); } }); const walletRow = document.createElement('div'); walletRow.className = 'inline-input-row'; walletRow.append(walletValue, copyButton); const card = document.createElement('div'); card.className = 'card stack'; card.innerHTML = `
Пополните счёт через доверенный devnet faucet и продолжите регистрацию.