SHA256
feat(ui): кошелек на device.key и проверки серверов (тоже пока не проверено)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { renderHeader } from '../components/header.js';
|
||||
import { renderHeader } from '../components/header.js';
|
||||
import {
|
||||
authService,
|
||||
refreshRegistrationBalance,
|
||||
setAuthError,
|
||||
setAuthInfo,
|
||||
state,
|
||||
} from '../state.js';
|
||||
import { toUserMessage } from '../services/ui-error-texts.js';
|
||||
import { deriveWalletFromPassword, formatSol, getBalanceSol } from '../services/solana-wallet-service.js';
|
||||
|
||||
export const pageMeta = { id: 'registration-payment-view', title: 'Оплата регистрации', showAppChrome: false };
|
||||
|
||||
@@ -39,7 +39,7 @@ export function render({ navigate }) {
|
||||
const walletValue = document.createElement('input');
|
||||
walletValue.className = 'input';
|
||||
walletValue.type = 'text';
|
||||
walletValue.value = state.registrationPayment.walletAddress;
|
||||
walletValue.value = state.registrationPayment.walletAddress || '';
|
||||
walletValue.addEventListener('input', () => {
|
||||
state.registrationPayment.walletAddress = walletValue.value;
|
||||
});
|
||||
@@ -71,15 +71,36 @@ export function render({ navigate }) {
|
||||
balanceRow.className = 'row wrap-row';
|
||||
|
||||
const balanceValue = document.createElement('strong');
|
||||
balanceValue.textContent = `${state.registrationPayment.balanceSOL} SOL`;
|
||||
balanceValue.textContent = `${formatSol(parseBalanceSol(state.registrationPayment.balanceSOL), 6)} SOL`;
|
||||
|
||||
const refreshButton = document.createElement('button');
|
||||
refreshButton.className = 'square-btn';
|
||||
refreshButton.type = 'button';
|
||||
refreshButton.textContent = '↻';
|
||||
refreshButton.title = 'Обновить';
|
||||
|
||||
const refreshBalance = async () => {
|
||||
const address = String(walletValue.value || '').trim();
|
||||
if (!address) return;
|
||||
refreshButton.disabled = true;
|
||||
try {
|
||||
const balance = await getBalanceSol({
|
||||
endpoint: state.entrySettings.solanaServer,
|
||||
address,
|
||||
});
|
||||
state.registrationPayment.balanceSOL = String(balance.sol);
|
||||
balanceValue.textContent = `${formatSol(balance.sol, 6)} SOL`;
|
||||
} catch (error) {
|
||||
status.className = 'status-line is-unavailable';
|
||||
status.textContent = `Не удалось обновить баланс: ${error?.message || 'unknown'}`;
|
||||
status.style.display = '';
|
||||
} finally {
|
||||
refreshButton.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
refreshButton.addEventListener('click', () => {
|
||||
balanceValue.textContent = `${refreshRegistrationBalance()} SOL`;
|
||||
void refreshBalance();
|
||||
});
|
||||
|
||||
balanceRow.append(balanceValue, refreshButton);
|
||||
@@ -100,7 +121,7 @@ export function render({ navigate }) {
|
||||
const balanceSol = parseBalanceSol(state.registrationPayment.balanceSOL);
|
||||
if (balanceSol < MIN_REGISTER_BALANCE_SOL) {
|
||||
status.className = 'status-line is-unavailable';
|
||||
status.textContent = `Недостаточный баланс для регистрации: ${state.registrationPayment.balanceSOL} SOL. Нужно минимум ${MIN_REGISTER_BALANCE_SOL.toFixed(2)} SOL.`;
|
||||
status.textContent = `Недостаточный баланс для регистрации: ${formatSol(balanceSol, 6)} SOL. Нужно минимум ${MIN_REGISTER_BALANCE_SOL.toFixed(2)} SOL.`;
|
||||
status.style.display = '';
|
||||
return;
|
||||
}
|
||||
@@ -141,9 +162,9 @@ export function render({ navigate }) {
|
||||
|
||||
card.innerHTML = `
|
||||
<p class="auth-copy">Для регистрации в Solana нужно заплатить 0,01 SOL (примерно 1 доллар).</p>
|
||||
<label class="stack"><span class="field-label">Номер кошелька</span></label>
|
||||
<label class="stack"><span class="field-label">Номер кошелька (wallet.key = device.key)</span></label>
|
||||
<div class="stack">
|
||||
<span class="field-label">Баланс</span>
|
||||
<span class="field-label">Баланс (Solana)</span>
|
||||
</div>
|
||||
`;
|
||||
card.children[1].append(walletRow);
|
||||
@@ -158,5 +179,20 @@ export function render({ navigate }) {
|
||||
card,
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const draftPassword = String(state.registrationDraft.password ?? '');
|
||||
const wallet = await deriveWalletFromPassword(draftPassword);
|
||||
state.registrationPayment.walletAddress = wallet.address;
|
||||
walletValue.value = wallet.address;
|
||||
await refreshBalance();
|
||||
} catch (error) {
|
||||
status.className = 'status-line is-unavailable';
|
||||
status.textContent = `Не удалось подготовить wallet.key: ${error?.message || 'unknown'}`;
|
||||
status.style.display = '';
|
||||
}
|
||||
})();
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user