SHA256
UI: запоминать Arweave-кошелёк загрузчика
This commit is contained in:
@@ -10,6 +10,7 @@ import { addArweaveWalletSecret, getArweaveBalance, getArweaveWalletChoices } fr
|
||||
import { escapeHtml, formatBytes, normalizeAttachment } from '../services/attachment-format.js';
|
||||
|
||||
const HISTORY_KEY = 'shine-ui-arweave-attachment-history-v1';
|
||||
const LAST_WALLET_KEY_PREFIX = 'shine-ui-arweave-last-wallet-v1:';
|
||||
const MAX_HISTORY_ITEMS = 100;
|
||||
const RECENT_UPLOAD_MS = 20 * 60 * 1000;
|
||||
|
||||
@@ -135,6 +136,27 @@ function shortAddress(value) {
|
||||
return `${raw.slice(0, 8)}...${raw.slice(-6)}`;
|
||||
}
|
||||
|
||||
function lastWalletStorageKey(login) {
|
||||
return `${LAST_WALLET_KEY_PREFIX}${String(login || '').trim().toLowerCase() || 'anonymous'}`;
|
||||
}
|
||||
|
||||
function readLastWalletId(login) {
|
||||
try {
|
||||
return sessionStorage.getItem(lastWalletStorageKey(login)) || '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function writeLastWalletId(login, walletId) {
|
||||
try {
|
||||
const clean = String(walletId || '').trim();
|
||||
if (clean) sessionStorage.setItem(lastWalletStorageKey(login), clean);
|
||||
} catch {
|
||||
// Если sessionStorage недоступен, выбор сохраняется хотя бы в текущем окне менеджера.
|
||||
}
|
||||
}
|
||||
|
||||
async function resizeImageFileToAvatar(file) {
|
||||
const source = file instanceof File ? file : null;
|
||||
if (!source) throw new Error('Выберите изображение.');
|
||||
@@ -186,7 +208,7 @@ export function openArweaveAttachmentManager({
|
||||
|
||||
let closed = false;
|
||||
let wallets = [];
|
||||
let selectedWalletId = 'derived-client-key';
|
||||
let selectedWalletId = readLastWalletId(cleanLogin) || 'derived-client-key';
|
||||
let selectedFile = null;
|
||||
let selectedSha256 = '';
|
||||
let priceInfo = null;
|
||||
@@ -235,6 +257,7 @@ export function openArweaveAttachmentManager({
|
||||
if (!wallets.some((item) => String(item.id) === String(selectedWalletId))) {
|
||||
selectedWalletId = String(wallets[0]?.id || 'derived-client-key');
|
||||
}
|
||||
writeLastWalletId(cleanLogin, selectedWalletId);
|
||||
} catch (error) {
|
||||
setText(errorEl, error?.message || 'Не удалось загрузить Arweave-кошельки.');
|
||||
}
|
||||
@@ -246,7 +269,7 @@ export function openArweaveAttachmentManager({
|
||||
<div class="modal-card stack ar-attachment-manager-card">
|
||||
<h3 class="modal-title">${isAvatarMode ? 'Загрузить аватар' : (historyOnly ? 'Загрузить файл в блокчейн' : 'Добавить вложение')}</h3>
|
||||
<label class="meta-muted" for="ar-attach-wallet">Кошелёк оплаты Arweave</label>
|
||||
<select class="input" id="ar-attach-wallet"></select>
|
||||
<select class="input ar-attachment-wallet-select" id="ar-attach-wallet"></select>
|
||||
<button class="ghost-btn" type="button" data-action="add-wallet">Добавить кошелёк</button>
|
||||
${isAvatarMode ? '<p class="meta-muted">Выберите изображение. Перед загрузкой оно будет сжато до 512×512 и сохранено в истории как аватар.</p>' : (historyOnly ? '' : '<p class="meta-muted">Для надёжности лучше сначала загрузить файл в Arweave, дождаться доступности в журнале, а потом добавить его из истории загрузок.</p>')}
|
||||
<label class="meta-muted" for="ar-attach-file">Файл для загрузки</label>
|
||||
@@ -275,6 +298,7 @@ export function openArweaveAttachmentManager({
|
||||
walletEl.value = selectedWalletId;
|
||||
walletEl.addEventListener('change', () => {
|
||||
selectedWalletId = String(walletEl.value || '');
|
||||
writeLastWalletId(cleanLogin, selectedWalletId);
|
||||
uploadBtn.disabled = true;
|
||||
selectedFile = null;
|
||||
selectedSha256 = '';
|
||||
@@ -535,6 +559,7 @@ export function openArweaveAttachmentManager({
|
||||
secret: String(secretEl?.value || '').trim(),
|
||||
});
|
||||
selectedWalletId = wallet.id;
|
||||
writeLastWalletId(cleanLogin, selectedWalletId);
|
||||
await showUpload();
|
||||
} catch (error) {
|
||||
saveBtn.disabled = false;
|
||||
|
||||
Reference in New Issue
Block a user