SHA256
Solana-first регистрация: lazy-import пользователя при входе, AddUser отключен, UI ожидание 15с
This commit is contained in:
@@ -15,6 +15,7 @@ import { registerUserOnSolana } from '../services/solana-register-service.js';
|
||||
|
||||
export const pageMeta = { id: 'registration-payment-view', title: 'Оплата регистрации', showAppChrome: false };
|
||||
const MIN_REQUIRED_SOL = 0.01;
|
||||
const SOLANA_SYNC_WAIT_SEC = 15;
|
||||
|
||||
function parseBalanceSol(value) {
|
||||
const parsed = Number.parseFloat(String(value || '').replace(',', '.'));
|
||||
@@ -198,18 +199,7 @@ export function render({ navigate }) {
|
||||
}
|
||||
}
|
||||
|
||||
// Регистрация на сервере SHiNE
|
||||
submitButton.textContent = 'Регистрация на сервере...';
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
const result = await authService.registerUserWithKeyBundle(state.registrationDraft.login, keyBundle);
|
||||
state.registrationDraft.flowType = 'registration';
|
||||
state.registrationDraft.sessionId = result.sessionId;
|
||||
state.registrationDraft.storagePwd = result.storagePwd;
|
||||
state.registrationDraft.pendingKeyBundle = result.keyBundle;
|
||||
state.registrationDraft.pendingSessionMaterial = result.sessionMaterial;
|
||||
|
||||
setAuthInfo(`Регистрация завершена. Вы вошли как @${result.login}. Далее откройте вкладку «Каналы».`);
|
||||
navigate('registration-keys-view');
|
||||
renderSolanaDoneStage({ navigate, status, keyBundle });
|
||||
} catch (error) {
|
||||
const message = toUserMessage(error, 'Не удалось завершить регистрацию.');
|
||||
setAuthError(message);
|
||||
@@ -254,3 +244,94 @@ export function render({ navigate }) {
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
function renderSolanaDoneStage({ navigate, status, keyBundle }) {
|
||||
const screen = document.querySelector('section.stack');
|
||||
if (!screen) return;
|
||||
const card = screen.querySelector('.card.stack');
|
||||
if (!card) return;
|
||||
|
||||
let remainingSec = SOLANA_SYNC_WAIT_SEC;
|
||||
let canTryLogin = false;
|
||||
let timerId = null;
|
||||
|
||||
const info = document.createElement('p');
|
||||
info.className = 'auth-copy';
|
||||
info.textContent = 'Регистрация в Solana прошла успешно.';
|
||||
|
||||
const hint = document.createElement('p');
|
||||
hint.className = 'meta-muted';
|
||||
hint.textContent = 'Подождите 10–15 секунд, пока запись обновится в блокчейне. После этого можно входить на сервер.';
|
||||
|
||||
const timer = document.createElement('p');
|
||||
timer.className = 'meta-muted';
|
||||
timer.textContent = `До попытки входа: ${remainingSec} сек`;
|
||||
|
||||
const tryLoginBtn = document.createElement('button');
|
||||
tryLoginBtn.className = 'primary-btn';
|
||||
tryLoginBtn.type = 'button';
|
||||
tryLoginBtn.textContent = `Попробовать войти (${remainingSec})`;
|
||||
tryLoginBtn.disabled = true;
|
||||
|
||||
const backBtn = document.createElement('button');
|
||||
backBtn.className = 'ghost-btn';
|
||||
backBtn.type = 'button';
|
||||
backBtn.textContent = 'Назад';
|
||||
backBtn.addEventListener('click', () => navigate('register-view'));
|
||||
|
||||
const stopTimer = () => {
|
||||
if (timerId) {
|
||||
window.clearInterval(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
};
|
||||
|
||||
const updateTimerUi = () => {
|
||||
if (remainingSec > 0) {
|
||||
timer.textContent = `До попытки входа: ${remainingSec} сек`;
|
||||
tryLoginBtn.textContent = `Попробовать войти (${remainingSec})`;
|
||||
tryLoginBtn.disabled = true;
|
||||
} else {
|
||||
canTryLogin = true;
|
||||
timer.textContent = 'Можно входить на сервер.';
|
||||
tryLoginBtn.textContent = 'Попробовать войти на сервер';
|
||||
tryLoginBtn.disabled = false;
|
||||
stopTimer();
|
||||
}
|
||||
};
|
||||
|
||||
tryLoginBtn.addEventListener('click', async () => {
|
||||
if (!canTryLogin) return;
|
||||
status.style.display = 'none';
|
||||
tryLoginBtn.disabled = true;
|
||||
tryLoginBtn.textContent = 'Вход...';
|
||||
try {
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
const result = await authService.createSessionForExistingUser(
|
||||
state.registrationDraft.login,
|
||||
state.registrationDraft.password,
|
||||
);
|
||||
state.registrationDraft.flowType = 'registration';
|
||||
state.registrationDraft.sessionId = result.sessionId;
|
||||
state.registrationDraft.storagePwd = result.storagePwd;
|
||||
state.registrationDraft.pendingKeyBundle = keyBundle;
|
||||
state.registrationDraft.pendingSessionMaterial = result.sessionMaterial;
|
||||
setAuthInfo(`Регистрация завершена. Вы вошли как @${result.login}. Далее откройте вкладку «Каналы».`);
|
||||
navigate('registration-keys-view');
|
||||
} catch (error) {
|
||||
status.className = 'status-line is-unavailable';
|
||||
status.textContent = toUserMessage(error, 'Пока не удалось войти. Попробуйте ещё раз через несколько секунд.');
|
||||
status.style.display = '';
|
||||
tryLoginBtn.disabled = false;
|
||||
tryLoginBtn.textContent = 'Попробовать войти на сервер';
|
||||
}
|
||||
});
|
||||
|
||||
card.innerHTML = '';
|
||||
card.append(info, hint, timer, tryLoginBtn, backBtn, status);
|
||||
updateTimerUi();
|
||||
timerId = window.setInterval(() => {
|
||||
remainingSec -= 1;
|
||||
updateTimerUi();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user