SHA256
Добавить выбор namespace при регистрации
This commit is contained in:
@@ -1528,6 +1528,16 @@
|
||||
"text_039": "Fixed"
|
||||
},
|
||||
"register_view": {
|
||||
"access_server_title": "Access server",
|
||||
"access_server_intro": "You access SHiNE through this server.",
|
||||
"access_server_migration": "Your account is not permanently tied to the access server. In the future, you can change it while keeping your login, social connections and accessibility to other users.",
|
||||
"access_server_free_migration": "Your account is not permanently tied to the access server. In the future, after securing your account on Solana, you can change it while keeping your login, social connections and accessibility to other users.",
|
||||
"namespace_choose": "Choose namespace",
|
||||
"namespace_full_login": "Your full login",
|
||||
"namespace_free": "Free registration",
|
||||
"namespace_price": "Registration price: {value1}",
|
||||
"namespace_limits": "Name length: {value1}–{value2} characters.",
|
||||
"namespace_loading": "Loading namespaces…",
|
||||
"text_001": "Sign up",
|
||||
"text_002": "Sign up for SHiNE",
|
||||
"text_003": "Your username",
|
||||
@@ -3783,12 +3793,15 @@
|
||||
"text_018": "Hide the key"
|
||||
},
|
||||
"registration_choice_view": {
|
||||
"price_loading": "Loading price…",
|
||||
"price_unavailable": "Price shown when choosing a name",
|
||||
"price_from": "From {value1} · one-time payment",
|
||||
"text_004": "Sign up for SHiNE",
|
||||
"text_001": "Account type",
|
||||
"text_002": "Select the account type",
|
||||
"text_006": "Sign up for free",
|
||||
"text_018": "Sign up for free",
|
||||
"text_007": "≈ 0.02 SOL · one-time payment",
|
||||
"text_007": "Price shown when choosing a name",
|
||||
"text_012": "Choose full account",
|
||||
"text_013": "0 SOL · Free",
|
||||
"text_003": "Choose the method of registration. A full account is independent of a single server.",
|
||||
|
||||
@@ -1528,6 +1528,16 @@
|
||||
"text_039": "Закреплён"
|
||||
},
|
||||
"register_view": {
|
||||
"access_server_title": "Сервер доступа",
|
||||
"access_server_intro": "Через этот сервер вы входите в Сияние.",
|
||||
"access_server_migration": "Ваш аккаунт не привязан навсегда к серверу доступа. В будущем вы можете сменить его, сохранив свой логин, социальные связи и доступность для других пользователей.",
|
||||
"access_server_free_migration": "Ваш аккаунт не привязан навсегда к серверу доступа. В будущем, после закрепления аккаунта в Solana, вы сможете сменить его, сохранив свой логин, социальные связи и доступность для других пользователей.",
|
||||
"namespace_choose": "Выберите namespace",
|
||||
"namespace_full_login": "Ваш итоговый логин",
|
||||
"namespace_free": "Регистрация бесплатная",
|
||||
"namespace_price": "Стоимость регистрации: {value1}",
|
||||
"namespace_limits": "Длина имени: от {value1} до {value2} символов.",
|
||||
"namespace_loading": "Загружаем пространства имён…",
|
||||
"text_001": "Регистрация",
|
||||
"text_002": "Регистрация в Сиянии",
|
||||
"text_003": "Ваш логин",
|
||||
@@ -4101,13 +4111,16 @@
|
||||
"text_013": "Очистить"
|
||||
},
|
||||
"registration_choice_view": {
|
||||
"price_loading": "Загружаем стоимость…",
|
||||
"price_unavailable": "Стоимость уточняется при выборе имени",
|
||||
"price_from": "От {value1} · разовая оплата",
|
||||
"text_001": "Тип аккаунта",
|
||||
"text_002": "Выберите тип аккаунта",
|
||||
"text_003": "Выберите способ регистрации. Полноценный аккаунт независим от одного сервера.",
|
||||
"text_004": "Регистрация в Сиянии",
|
||||
"text_005": "Зарегистрировать полноценный аккаунт",
|
||||
"text_006": "Зарегистрироваться бесплатно",
|
||||
"text_007": "≈ 0,02 SOL · разовая оплата",
|
||||
"text_007": "Стоимость уточняется при выборе имени",
|
||||
"text_008": "Оплата создания личной записи (PDA) в блокчейне Solana. Точная сумма рассчитывается перед оплатой.",
|
||||
"text_009": "Аккаунт не привязан к одному серверу Сияния.",
|
||||
"text_010": "Можно переходить между серверами или запустить собственный.",
|
||||
|
||||
@@ -8,6 +8,7 @@ import { authService, clearAuthMessages, clearRegistrationDraft, state } from '.
|
||||
import { PASSWORD_MAX_LENGTH } from '../services/password-words.js';
|
||||
import { getRegistrationNamespaces, checkRegistrationLogin } from '../services/registration-v2-api.js';
|
||||
import { savePendingHeaderIdentity } from '../services/pending-header-identity.js';
|
||||
import { registrationNamespaceOptions, chooseRegistrationNamespace, formatRegistrationFee } from '../services/registration-namespace-options.js';
|
||||
import { normalizeFullLogin } from '../services/shine-namespace-service.js';
|
||||
|
||||
export const pageMeta = { id: 'register-view', get title() { return t('screens.register_view.text_001'); }, showAppChrome: false };
|
||||
@@ -30,6 +31,10 @@ export function render({ navigate }) {
|
||||
let requestId = 0;
|
||||
let localDraft = String(draft.login || '').split('@')[0];
|
||||
const flowType = draft.flowType;
|
||||
let preferredNamespace = String(draft.login || '').split('@')[1] || '';
|
||||
let refreshLoginNamespaces = null;
|
||||
let disposed = false;
|
||||
screen.cleanup = () => { disposed = true; requestId++; };
|
||||
|
||||
function confirmFundedWalletChange() {
|
||||
const balance = Number(state.registrationPayment?.balanceSOL || 0);
|
||||
@@ -50,7 +55,7 @@ export function render({ navigate }) {
|
||||
showLogin();
|
||||
return;
|
||||
}
|
||||
navigate('registration-choice-view');
|
||||
if (confirmFundedWalletChange()) { requestId++; navigate('registration-choice-view'); }
|
||||
}
|
||||
// Кнопка назад TopBar создана один раз, переход между шагами — внутри страницы.
|
||||
function statusLine() {
|
||||
@@ -69,8 +74,7 @@ export function render({ navigate }) {
|
||||
return [heading, subtitle];
|
||||
}
|
||||
function selectedNamespace() {
|
||||
const candidates = namespaces.filter(n => Number(n.type) === (flowType === 'free' ? 2 : 1));
|
||||
return candidates.find(n => String(n.name).toLowerCase() === (flowType === 'free' ? 'free' : 'shine')) || candidates[0];
|
||||
return chooseRegistrationNamespace(registrationNamespaceOptions(namespaces, flowType), preferredNamespace);
|
||||
}
|
||||
function showLogin() {
|
||||
draft.uiStep = 1;
|
||||
@@ -81,16 +85,55 @@ export function render({ navigate }) {
|
||||
const labelText = document.createElement('span');
|
||||
labelText.className = 'field-label';
|
||||
labelText.textContent = t('screens.register_view.text_003');
|
||||
const field = document.createElement('span');
|
||||
field.className = 'input signup-login-field';
|
||||
const input = document.createElement('input');
|
||||
input.className = 'input';
|
||||
input.className = 'signup-login-field__name';
|
||||
input.placeholder = t('screens.register_view.text_004');
|
||||
input.autocomplete = 'off';
|
||||
input.autocapitalize = 'off';
|
||||
input.spellcheck = false;
|
||||
input.value = localDraft;
|
||||
label.append(labelText, input);
|
||||
const suffix = document.createElement('span');
|
||||
suffix.className = 'signup-login-field__suffix';
|
||||
field.append(input, suffix);
|
||||
label.append(labelText, field);
|
||||
const namespaceLabel = document.createElement('label');
|
||||
namespaceLabel.className = 'stack signup-namespace-choice';
|
||||
const namespaceTitle = document.createElement('span');
|
||||
namespaceTitle.className = 'field-label';
|
||||
namespaceTitle.textContent = t('screens.register_view.namespace_choose');
|
||||
const select = document.createElement('select');
|
||||
select.className = 'select';
|
||||
namespaceLabel.append(namespaceTitle, select);
|
||||
const preview = document.createElement('div');
|
||||
preview.className = 'stack signup-login-preview';
|
||||
const previewTitle = document.createElement('span');
|
||||
previewTitle.className = 'field-label';
|
||||
previewTitle.textContent = t('screens.register_view.namespace_full_login');
|
||||
const fullLogin = document.createElement('p');
|
||||
fullLogin.className = 'signup-full-login';
|
||||
fullLogin.setAttribute('aria-live', 'polite');
|
||||
preview.append(previewTitle, fullLogin);
|
||||
const accessServer = document.createElement('div');
|
||||
accessServer.className = 'stack signup-access-server';
|
||||
const accessTitle = document.createElement('span');
|
||||
accessTitle.className = 'field-label';
|
||||
accessTitle.textContent = t('screens.register_view.access_server_title');
|
||||
const accessAddress = document.createElement('strong');
|
||||
accessAddress.className = 'signup-access-server__address';
|
||||
accessAddress.textContent = window.location.host || window.location.hostname || 'shineup.me';
|
||||
const accessIntro = document.createElement('p');
|
||||
accessIntro.textContent = t('screens.register_view.access_server_intro');
|
||||
const accessExplanation = document.createElement('p');
|
||||
accessExplanation.textContent = t(flowType === 'free'
|
||||
? 'screens.register_view.access_server_free_migration'
|
||||
: 'screens.register_view.access_server_migration');
|
||||
accessServer.append(accessTitle, accessAddress, accessIntro, accessExplanation);
|
||||
const fee = document.createElement('p');
|
||||
fee.className = 'meta-muted';
|
||||
const limits = document.createElement('p');
|
||||
limits.className = 'meta-muted';
|
||||
const caseInfo = document.createElement('p');
|
||||
caseInfo.className = 'meta-muted';
|
||||
caseInfo.textContent = t('screens.register_view.text_005');
|
||||
@@ -99,15 +142,40 @@ export function render({ navigate }) {
|
||||
next.className = 'primary-btn signup-next';
|
||||
next.textContent = t('screens.register_view.text_006');
|
||||
next.type = 'button';
|
||||
next.disabled = isLoading;
|
||||
function updateFull() {
|
||||
const ns = selectedNamespace();
|
||||
const price = formatRegistrationFee(ns);
|
||||
suffix.textContent = ns ? `@${ns.name}` : '';
|
||||
fullLogin.textContent = ns ? `${input.value.trim() || t('screens.register_view.text_021')}@${ns.name}` : t('screens.register_view.text_018');
|
||||
status.textContent = fetchError;
|
||||
next.disabled = isLoading || !ns;
|
||||
fee.hidden = !ns;
|
||||
fee.textContent = flowType === 'free' ? t('screens.register_view.namespace_free') : t('screens.register_view.namespace_price', { value1: price ?? t('screens.register_view.text_025') });
|
||||
limits.hidden = !ns;
|
||||
limits.textContent = ns ? t('screens.register_view.namespace_limits', { value1: ns.minLocalLength, value2: 29 - ns.name.length }) : '';
|
||||
status.textContent = fetchError || (isLoading ? t('screens.register_view.namespace_loading') : ns && price === null && flowType === 'paid' ? t('screens.register_view.text_025') : '');
|
||||
next.disabled = isLoading || !ns || (flowType === 'paid' && price === null);
|
||||
}
|
||||
input.addEventListener('input', () => { inputRevision++; localDraft = input.value; updateFull(); });
|
||||
refreshLoginNamespaces = () => {
|
||||
const options = registrationNamespaceOptions(namespaces, flowType);
|
||||
const ns = selectedNamespace();
|
||||
preferredNamespace = ns?.name || preferredNamespace;
|
||||
select.replaceChildren();
|
||||
for (const candidate of options) {
|
||||
const option = document.createElement('option');
|
||||
option.value = candidate.name;
|
||||
option.textContent = `@${candidate.name} · ${formatRegistrationFee(candidate) ?? t('screens.register_view.text_025')}`;
|
||||
select.append(option);
|
||||
}
|
||||
select.value = ns?.name || '';
|
||||
namespaceLabel.hidden = flowType !== 'paid' || options.length < 2;
|
||||
select.disabled = namespaceLabel.hidden;
|
||||
updateFull();
|
||||
};
|
||||
function invalidateCheck() { inputRevision++; requestId++; updateFull(); }
|
||||
input.addEventListener('input', () => { localDraft = input.value; invalidateCheck(); });
|
||||
select.addEventListener('change', () => { preferredNamespace = select.value; invalidateCheck(); });
|
||||
input.addEventListener('keydown', event => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); next.click(); } });
|
||||
next.addEventListener('click', async () => {
|
||||
if (next.disabled || disposed) return;
|
||||
const ns = selectedNamespace();
|
||||
if (!ns) { status.textContent = t('screens.register_view.text_007'); return; }
|
||||
let login;
|
||||
@@ -122,11 +190,11 @@ export function render({ navigate }) {
|
||||
status.textContent = t('screens.register_view.text_008');
|
||||
try {
|
||||
const available = await checkRegistrationLogin(login);
|
||||
if (!screen.isConnected || thisRequest !== requestId) return;
|
||||
if (revision !== inputRevision) throw new Error(t('screens.register_view.text_022'));
|
||||
if (disposed || !screen.isConnected || thisRequest !== requestId || revision !== inputRevision || draft.uiStep !== 1) return;
|
||||
if (!available.loginAvailable) throw new Error(t('screens.register_view.text_023'));
|
||||
if (Number(available.namespaceType) !== Number(ns.type)) throw new Error(t('screens.register_view.text_024'));
|
||||
if (Number(available.currencyCode ?? 1) !== 1 || Number(ns.currencyCode ?? 1) !== 1) throw new Error(t('screens.register_view.text_025'));
|
||||
if (input.value.trim().length < Number(available.minLocalLength ?? ns.minLocalLength)) throw new Error(t('screens.register_view.text_030', { value1: available.minLocalLength ?? ns.minLocalLength }));
|
||||
if (draft.login !== login) {
|
||||
if (!confirmFundedWalletChange()) return;
|
||||
clearRegistrationDraft({ preserveFlowType: true });
|
||||
@@ -137,13 +205,13 @@ export function render({ navigate }) {
|
||||
draft.uiStep = 2;
|
||||
showPassword();
|
||||
} catch (error) {
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || t('screens.register_view.text_026');
|
||||
if (!disposed && screen.isConnected && thisRequest === requestId) status.textContent = error.message || t('screens.register_view.text_026');
|
||||
} finally {
|
||||
if (screen.isConnected && thisRequest === requestId) next.disabled = false;
|
||||
if (!disposed && screen.isConnected && thisRequest === requestId) next.disabled = false;
|
||||
}
|
||||
});
|
||||
body.append(heading, description, label, fullLogin, caseInfo, status, next);
|
||||
updateFull();
|
||||
body.append(heading, description, label, namespaceLabel, preview, fee, limits, caseInfo, accessServer, status, next);
|
||||
refreshLoginNamespaces();
|
||||
}
|
||||
function showPassword() {
|
||||
draft.uiStep = 2;
|
||||
@@ -346,11 +414,11 @@ export function render({ navigate }) {
|
||||
namespaces = Array.isArray(data.namespaces) ? data.namespaces : [];
|
||||
isLoading = false;
|
||||
if (!selectedNamespace()) fetchError = t('screens.register_view.text_029');
|
||||
if (screen.isConnected && Number(draft.uiStep) === 1) showLogin();
|
||||
if (!disposed && screen.isConnected && Number(draft.uiStep) === 1) refreshLoginNamespaces?.();
|
||||
}).catch(error => {
|
||||
isLoading = false;
|
||||
fetchError = t('screens.register_view.text_033', { value1: error.message });
|
||||
if (screen.isConnected && Number(draft.uiStep) === 1) showLogin();
|
||||
if (!disposed && screen.isConnected && Number(draft.uiStep) === 1) refreshLoginNamespaces?.();
|
||||
});
|
||||
return screen;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { resetRegistrationFlow, state } from '../state.js';
|
||||
import { registrationNamespaceOptions, formatRegistrationFee } from '../services/registration-namespace-options.js';
|
||||
import { getRegistrationNamespaces } from '../services/registration-v2-api.js';
|
||||
|
||||
export const pageMeta = { id: 'registration-choice-view', get title() { return t('screens.registration_choice_view.text_001'); }, showAppChrome: false };
|
||||
@@ -61,7 +62,7 @@ export function render({ navigate }) {
|
||||
plans.className = 'stack';
|
||||
const paidCard = card({
|
||||
type: 'paid', icon: '◇', heading: t('screens.registration_choice_view.text_005'),
|
||||
price: t('screens.registration_choice_view.text_007'),
|
||||
price: t('screens.registration_choice_view.price_loading'),
|
||||
lead: t('screens.registration_choice_view.text_008'),
|
||||
perks: [t('screens.registration_choice_view.text_009'), t('screens.registration_choice_view.text_010'), t('screens.registration_choice_view.text_011')],
|
||||
button: t('screens.registration_choice_view.text_012'),
|
||||
@@ -72,8 +73,13 @@ export function render({ navigate }) {
|
||||
// Бесплатная регистрация доступна только если текущий сервер сам объявил
|
||||
// привязанный к нему type-2 namespace. При ошибке запроса безопасно оставляем
|
||||
// только платный сценарий.
|
||||
const paidPrice = paidCard.querySelector('.signup-plan__price');
|
||||
void getRegistrationNamespaces().then(({ namespaces }) => {
|
||||
if (!screen.isConnected || !Array.isArray(namespaces) || !namespaces.some(n => Number(n.type) === 2)) return;
|
||||
if (!screen.isConnected) return;
|
||||
const paid = registrationNamespaceOptions(namespaces, 'paid');
|
||||
const price = formatRegistrationFee(paid[0]);
|
||||
paidPrice.textContent = price === null ? t('screens.registration_choice_view.price_unavailable') : t('screens.registration_choice_view.price_from', { value1: price });
|
||||
if (!Array.isArray(namespaces) || !namespaces.some(n => Number(n.type) === 2)) return;
|
||||
plans.append(card({
|
||||
type: 'free', icon: '♧', heading: t('screens.registration_choice_view.text_006'),
|
||||
price: t('screens.registration_choice_view.text_013'),
|
||||
@@ -81,6 +87,8 @@ export function render({ navigate }) {
|
||||
perks: [t('screens.registration_choice_view.text_015'), t('screens.registration_choice_view.text_016'), t('screens.registration_choice_view.text_017')],
|
||||
button: t('screens.registration_choice_view.text_018'),
|
||||
}));
|
||||
}).catch(() => {
|
||||
if (screen.isConnected) paidPrice.textContent = t('screens.registration_choice_view.price_unavailable');
|
||||
});
|
||||
return screen;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// GetNamespaces already scopes free namespaces to the current access server.
|
||||
// Compare integer lamports, never floating-point SOL prices.
|
||||
import { getIntlLocale } from '../i18n/format.js';
|
||||
|
||||
export function registrationNamespaceOptions(namespaces, flowType) {
|
||||
const type = flowType === 'free' ? 2 : flowType === 'paid' ? 1 : 0;
|
||||
if (!type || !Array.isArray(namespaces)) return [];
|
||||
return namespaces.filter(ns => Number(ns?.type) === type && /^[a-z0-9_]+$/.test(ns.name))
|
||||
.sort((a, b) => {
|
||||
if (type === 1) {
|
||||
const pa = registrationFee(a), pb = registrationFee(b);
|
||||
if (pa === null && pb !== null) return 1;
|
||||
if (pb === null && pa !== null) return -1;
|
||||
if (pa !== null && pb !== null && pa !== pb) return pa < pb ? -1 : 1;
|
||||
}
|
||||
return a.name.localeCompare(b.name, 'en');
|
||||
});
|
||||
}
|
||||
|
||||
export function registrationFee(ns) {
|
||||
if (!ns || Number(ns.currencyCode ?? 1) !== 1) return null;
|
||||
const value = ns.registrationFeeLamports;
|
||||
if (typeof value === 'number' && !Number.isSafeInteger(value)) return null;
|
||||
if (!/^\d+$/.test(String(value ?? ''))) return null;
|
||||
return BigInt(value);
|
||||
}
|
||||
|
||||
export function chooseRegistrationNamespace(options, preferredName) {
|
||||
return options.find(ns => ns.name === preferredName) || options[0];
|
||||
}
|
||||
|
||||
// Exact 9-decimal SOL formatting; never round a nonzero fee to zero.
|
||||
export function formatRegistrationFee(ns, locale = getIntlLocale()) {
|
||||
const fee = registrationFee(ns);
|
||||
if (fee === null) return null;
|
||||
const scale = 1_000_000_000n;
|
||||
const integer = new Intl.NumberFormat(locale).format(fee / scale);
|
||||
const fractional = String(fee % scale).padStart(9, '0').replace(/0+$/, '');
|
||||
const decimal = new Intl.NumberFormat(locale).formatToParts(1.1).find(p => p.type === 'decimal').value;
|
||||
return `${integer}${fractional ? decimal + fractional : ''} SOL`;
|
||||
}
|
||||
Reference in New Issue
Block a user