Регистрация: бесплатная регистрация работает

This commit is contained in:
AidarKC
2026-10-24 16:17:34 +03:00
parent cab26bbf41
commit a520c5c5e1
14 changed files with 111 additions and 34 deletions
+41 -9
View File
@@ -13,8 +13,10 @@ import {
import { clearStoredMessages } from '../services/message-store.js';
import { toUserMessage } from '../services/ui-error-texts.js';
import {
createSolanaWalletFromPrivateBase58,
formatSol,
getBalanceSol,
transferSol,
} from '../services/solana-wallet-service.js';
import { loadSolanaWeb3 } from '../vendor/solana-web3-loader.js';
import {
@@ -25,12 +27,14 @@ import {
registerUserOnSolana,
} from '../services/solana-register-service.js';
import { defaultServerLogin } from '../deploy-config.js';
import { normalizeFullLogin } from '../services/shine-namespace-service.js';
export const pageMeta = { id: 'registration-payment-view', title: 'Оплата регистрации', showAppChrome: false };
const MIN_REQUIRED_SOL = 0.01;
const RECOMMENDED_TOPUP_SOL = 0.02;
const TEST_TOPUP_AMOUNT_SOL = 0.02;
const DEVNET_ENDPOINT = 'https://api.devnet.solana.com';
const TEST_TOPUP_SENDER_PRIVATE_32_BASE58 = '6xqAuKYvA8qrCdAkcw7Y8aMgvBnYk8JLxWLma5BzbAvu';
const AUTO_LOGIN_INITIAL_DELAY_MS = 1000;
const AUTO_LOGIN_RETRY_MS = 2000;
const REGISTRATION_PROGRESS_DURATION_MS = 12000;
@@ -68,6 +72,12 @@ function parseBalanceSol(value) {
return Number.isFinite(parsed) ? parsed : 0;
}
function registrationAccessServerLogin() {
const configured = String(state.entrySettings.shineServerLogin || defaultServerLogin || '').trim().toLowerCase();
if (!configured) return '';
return normalizeFullLogin(configured.includes('@') ? configured : `${configured}@shine`);
}
function getCryptoRuntimeState() {
const hasCrypto = Boolean(globalThis.crypto);
const hasGetRandomValues = Boolean(globalThis.crypto && typeof globalThis.crypto.getRandomValues === 'function');
@@ -249,13 +259,35 @@ export function render({ navigate }) {
topupButton.className = 'ghost-btn';
topupButton.type = 'button';
topupButton.textContent = 'Тестовое пополнение (пока доступно в тестовом режиме)';
// Браузерная раздача devnet SOL с приватным ключом отправителя опасна.
// Ссылка на публичный faucet безопаснее, чем встраивать секрет в JS.
topupButton.textContent = 'Как пополнить через devnet faucet';
topupButton.addEventListener('click', () => {
status.className = 'status-line is-unavailable';
status.textContent = 'Скопируйте адрес кошелька выше и пополните его через доверенный Solana devnet faucet. Приватный ключ отправителя не должен находиться в приложении.';
status.style.display = '';
topupButton.addEventListener('click', async () => {
status.style.display = 'none';
topupButton.disabled = true;
const defaultText = 'Тестовое пополнение (пока доступно в тестовом режиме)';
topupButton.textContent = 'Пополняем...';
try {
const address = await deriveUserWalletAddress();
const sender = await createSolanaWalletFromPrivateBase58(TEST_TOPUP_SENDER_PRIVATE_32_BASE58);
await transferSol({
endpoint: DEVNET_ENDPOINT,
fromKeypair: sender.keypair,
toAddress: address,
amountSol: TEST_TOPUP_AMOUNT_SOL,
});
const balance = await getBalanceSol({
endpoint: DEVNET_ENDPOINT,
address,
});
state.registrationPayment.balanceSOL = String(balance.sol);
balanceValue.textContent = `${formatSol(balance.sol, 6)} SOL`;
status.className = 'status-line is-available';
status.textContent = `Тестовое пополнение выполнено: +${TEST_TOPUP_AMOUNT_SOL} SOL. Баланс: ${formatSol(balance.sol, 6)} SOL.`;
status.style.display = '';
} catch (error) {
showWalletError(error, 'Не удалось выполнить тестовое пополнение. Попробуйте ещё раз.');
} finally {
topupButton.disabled = false;
topupButton.textContent = defaultText;
}
});
const submitButton = document.createElement('button');
@@ -289,7 +321,7 @@ export function render({ navigate }) {
: `Для регистрации пополните этот кошелёк соланами примерно на ${RECOMMENDED_TOPUP_SOL} SOL. Сейчас на кошельке ${formatSol(currentBalance, 6)} SOL. Минимум для продолжения: ${requiredSol.toFixed(6)} SOL.`;
status.style.display = '';
if (isTestContour) {
status.textContent += ' Для тестового пополнения используйте внешний devnet faucet.';
status.textContent += ` Нажмите «Тестовое пополнение», чтобы сразу добавить ${TEST_TOPUP_AMOUNT_SOL} SOL без перехода на другой экран.`;
}
return;
}
@@ -315,7 +347,7 @@ export function render({ navigate }) {
login: state.registrationDraft.login,
keyBundle,
solanaEndpoint: state.entrySettings.solanaServer,
accessServers: [state.entrySettings.shineServerLogin || defaultServerLogin],
accessServers: [registrationAccessServerLogin()],
});
registrationTxId = String(registrationResult?.signature || '').trim();
} catch (solanaError) {