SHA256
Регистрация V2: не проверено end-to-end
This commit is contained in:
@@ -13,10 +13,8 @@ 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 {
|
||||
@@ -33,7 +31,6 @@ 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;
|
||||
@@ -83,7 +80,7 @@ function clamp(value, min, max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
async function completeRegistrationLogin({ navigate, keyBundle }) {
|
||||
export async function completeRegistrationLogin({ navigate, keyBundle }) {
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
const result = await authService.createSessionForExistingUser(
|
||||
state.registrationDraft.login,
|
||||
@@ -252,35 +249,13 @@ export function render({ navigate }) {
|
||||
topupButton.className = 'ghost-btn';
|
||||
topupButton.type = 'button';
|
||||
topupButton.textContent = 'Тестовое пополнение (пока доступно в тестовом режиме)';
|
||||
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;
|
||||
}
|
||||
// Браузерная раздача 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 = '';
|
||||
});
|
||||
|
||||
const submitButton = document.createElement('button');
|
||||
@@ -305,14 +280,16 @@ export function render({ navigate }) {
|
||||
const walletAddress = await deriveUserWalletAddress();
|
||||
const currentBalance = await refreshBalance({ showError: true, addressOverride: walletAddress });
|
||||
if (currentBalance == null) return;
|
||||
if (currentBalance < MIN_REQUIRED_SOL) {
|
||||
const namespaceFeeSol = Number(state.registrationDraft.namespaceFeeLamports || 0) / 1e9;
|
||||
const requiredSol = Math.max(MIN_REQUIRED_SOL, namespaceFeeSol + 0.004);
|
||||
if (currentBalance < requiredSol) {
|
||||
status.className = 'status-line is-unavailable';
|
||||
status.textContent = isTestContour
|
||||
? `Для регистрации нужно минимум ${MIN_REQUIRED_SOL} SOL. Рекомендуем пополнить кошелёк примерно на ${RECOMMENDED_TOPUP_SOL} SOL. Сейчас на кошельке ${formatSol(currentBalance, 6)} SOL.`
|
||||
: `Для регистрации пополните этот кошелёк соланами примерно на ${RECOMMENDED_TOPUP_SOL} SOL. Сейчас на кошельке ${formatSol(currentBalance, 6)} SOL. Минимум для продолжения: ${MIN_REQUIRED_SOL} SOL.`;
|
||||
? `Для регистрации нужно минимум ${requiredSol.toFixed(6)} SOL. Рекомендуем пополнить кошелёк примерно на ${RECOMMENDED_TOPUP_SOL} SOL. Сейчас на кошельке ${formatSol(currentBalance, 6)} SOL.`
|
||||
: `Для регистрации пополните этот кошелёк соланами примерно на ${RECOMMENDED_TOPUP_SOL} SOL. Сейчас на кошельке ${formatSol(currentBalance, 6)} SOL. Минимум для продолжения: ${requiredSol.toFixed(6)} SOL.`;
|
||||
status.style.display = '';
|
||||
if (isTestContour) {
|
||||
status.textContent += ` Нажмите «Тестовое пополнение», чтобы сразу добавить ${TEST_TOPUP_AMOUNT_SOL} SOL без перехода на другой экран.`;
|
||||
status.textContent += ' Для тестового пополнения используйте внешний devnet faucet.';
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -339,7 +316,6 @@ export function render({ navigate }) {
|
||||
keyBundle,
|
||||
solanaEndpoint: state.entrySettings.solanaServer,
|
||||
accessServers: [state.entrySettings.shineServerLogin || defaultServerLogin],
|
||||
promoCode: '',
|
||||
});
|
||||
registrationTxId = String(registrationResult?.signature || '').trim();
|
||||
} catch (solanaError) {
|
||||
|
||||
Reference in New Issue
Block a user