SHA256
Исправить подключение и подпись в браузерном кошельке
This commit is contained in:
@@ -2,7 +2,6 @@ import { formatPairingShortCode } from './js/lib/device-pairing.js';
|
||||
|
||||
const els = {
|
||||
serverLoginInfo: document.querySelector('#server-login-info'),
|
||||
serverAddress: document.querySelector('#server-address'),
|
||||
loginInput: document.querySelector('#login-input'),
|
||||
usePassword: document.querySelector('#use-password'),
|
||||
passwordField: document.querySelector('#password-field'),
|
||||
@@ -17,9 +16,6 @@ const els = {
|
||||
status: document.querySelector('#status'),
|
||||
sessionCard: document.querySelector('#session-card'),
|
||||
sessionLogin: document.querySelector('#session-login'),
|
||||
sessionId: document.querySelector('#session-id'),
|
||||
sessionType: document.querySelector('#session-type'),
|
||||
clientKeyShort: document.querySelector('#client-key-short'),
|
||||
resumeBtn: document.querySelector('#resume-btn'),
|
||||
refreshDevicesBtn: document.querySelector('#refresh-devices-btn'),
|
||||
disconnectBtn: document.querySelector('#disconnect-btn'),
|
||||
@@ -27,6 +23,10 @@ const els = {
|
||||
deviceSelect: document.querySelector('#device-select'),
|
||||
homeserverList: document.querySelector('#homeserver-list'),
|
||||
requestWalletBtn: document.querySelector('#request-wallet-btn'),
|
||||
pendingApprovalCard: document.querySelector('#pending-approval-card'),
|
||||
pendingApprovalSubtitle: document.querySelector('#pending-approval-subtitle'),
|
||||
pendingApprovalDetails: document.querySelector('#pending-approval-details'),
|
||||
cancelPendingApprovalBtn: document.querySelector('#cancel-pending-approval-btn'),
|
||||
walletResultCard: document.querySelector('#wallet-result-card'),
|
||||
walletType: document.querySelector('#wallet-type'),
|
||||
walletPubkey: document.querySelector('#wallet-pubkey'),
|
||||
@@ -52,6 +52,7 @@ let state = {
|
||||
selectedDeviceName: '',
|
||||
},
|
||||
currentWallet: null,
|
||||
pendingApproval: null,
|
||||
status: {
|
||||
text: '',
|
||||
kind: 'info',
|
||||
@@ -107,13 +108,49 @@ function renderHomeserverList(items = []) {
|
||||
});
|
||||
}
|
||||
|
||||
function renderPendingApproval(pendingApproval) {
|
||||
els.pendingApprovalDetails.innerHTML = '';
|
||||
if (!pendingApproval) return;
|
||||
const summary = pendingApproval.transactionSummary || {};
|
||||
const programs = Array.isArray(summary.programs) && summary.programs.length
|
||||
? summary.programs.join(', ')
|
||||
: 'не определены';
|
||||
const details = [
|
||||
{ label: 'Сайт', value: pendingApproval.origin || '—', mono: true },
|
||||
{ label: 'Кошелёк', value: pendingApproval.publicKeyBase58 || '—', mono: true },
|
||||
{ label: 'Комментарий', value: pendingApproval.comment || 'Транзакция запрошена сайтом' },
|
||||
{ label: 'Тип', value: summary.kind || 'legacy' },
|
||||
{ label: 'Инструкций', value: String(summary.instructionCount ?? 0) },
|
||||
{ label: 'Программы', value: programs, mono: true },
|
||||
];
|
||||
if (summary.feePayer) {
|
||||
details.push({ label: 'Fee payer', value: summary.feePayer, mono: true });
|
||||
}
|
||||
if (summary.recentBlockhash) {
|
||||
details.push({ label: 'Blockhash', value: summary.recentBlockhash, mono: true });
|
||||
}
|
||||
for (const item of details) {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'detail-row';
|
||||
const label = document.createElement('div');
|
||||
label.className = 'detail-label';
|
||||
label.textContent = item.label;
|
||||
const value = document.createElement('div');
|
||||
value.className = `detail-value${item.mono ? ' mono' : ''}`;
|
||||
value.textContent = item.value;
|
||||
row.append(label, value);
|
||||
els.pendingApprovalDetails.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
function applyState(nextState) {
|
||||
state = nextState || state;
|
||||
const loginValue = String(state?.settings?.login || '');
|
||||
const resolvedServerLogin = String(state?.settings?.serverLogin || '').trim();
|
||||
const resolvedServerAddress = String(state?.settings?.serverHttp || '').trim();
|
||||
els.serverLoginInfo.textContent = resolvedServerLogin ? `Сервер SHiNE: ${resolvedServerLogin}` : 'Сервер SHiNE: —';
|
||||
els.serverAddress.textContent = resolvedServerAddress ? `Адрес: ${resolvedServerAddress}` : 'Адрес: —';
|
||||
els.serverLoginInfo.textContent = resolvedServerLogin && resolvedServerAddress
|
||||
? `Сервер SHiNE: ${resolvedServerLogin} (${resolvedServerAddress})`
|
||||
: 'Сервер SHiNE: —';
|
||||
if (document.activeElement !== els.loginInput) {
|
||||
els.loginInput.value = loginValue;
|
||||
}
|
||||
@@ -125,16 +162,15 @@ function applyState(nextState) {
|
||||
const walletProfile = state?.walletProfile;
|
||||
const signing = state?.signing || {};
|
||||
const currentWallet = state?.currentWallet || null;
|
||||
const pendingApproval = state?.pendingApproval || null;
|
||||
|
||||
els.connectCard.classList.toggle('hidden', !!session);
|
||||
els.sessionCard.classList.toggle('hidden', !session);
|
||||
els.walletCard.classList.toggle('hidden', !session);
|
||||
els.pendingApprovalCard.classList.toggle('hidden', !pendingApproval);
|
||||
|
||||
if (session) {
|
||||
els.sessionLogin.textContent = session.login || '—';
|
||||
els.sessionId.textContent = session.sessionId || '—';
|
||||
els.sessionType.textContent = String(session.sessionType || 50) === '50' ? 'wallet' : String(session.sessionType || '—');
|
||||
els.clientKeyShort.textContent = shortKey(walletProfile?.publicKeys?.clientKeyBase58 || '');
|
||||
}
|
||||
|
||||
const homeservers = Array.isArray(walletProfile?.homeserverSessions) ? walletProfile.homeserverSessions : [];
|
||||
@@ -149,6 +185,16 @@ function applyState(nextState) {
|
||||
renderHomeserverList(homeservers);
|
||||
els.requestWalletBtn.disabled = !session || !signing.selectedDeviceName;
|
||||
|
||||
if (pendingApproval) {
|
||||
els.pendingApprovalSubtitle.textContent = pendingApproval.origin
|
||||
? `Сайт ${pendingApproval.origin} запросил подписание транзакции.`
|
||||
: 'Сайт запросил подписание транзакции.';
|
||||
renderPendingApproval(pendingApproval);
|
||||
} else {
|
||||
els.pendingApprovalSubtitle.textContent = 'Сайт запросил подписание транзакции.';
|
||||
els.pendingApprovalDetails.innerHTML = '';
|
||||
}
|
||||
|
||||
if (currentWallet?.publicKeyBase58) {
|
||||
els.walletResultCard.classList.remove('hidden');
|
||||
els.walletType.textContent = currentWallet.type || '—';
|
||||
@@ -313,6 +359,14 @@ async function copyWalletKey() {
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelPendingApproval() {
|
||||
try {
|
||||
await sendMessage('wallet:cancelPendingSiteApproval');
|
||||
} catch (error) {
|
||||
setStatus(error.message || 'Не удалось отменить ожидание подписи.', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function startUiRefreshLoop() {
|
||||
stopUiRefreshLoop();
|
||||
refreshTimer = window.setInterval(() => {
|
||||
@@ -347,6 +401,7 @@ function bindUi() {
|
||||
els.deviceSelect.addEventListener('change', () => { void updateDeviceSelection(); });
|
||||
els.requestWalletBtn.addEventListener('click', () => { void requestCurrentWallet(); });
|
||||
els.copyWalletBtn.addEventListener('click', () => { void copyWalletKey(); });
|
||||
els.cancelPendingApprovalBtn.addEventListener('click', () => { void cancelPendingApproval(); });
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
||||
Reference in New Issue
Block a user