Files
SHiNE-server/shine-UI/js/services/public-history-consent.js
T

40 lines
1.4 KiB
JavaScript

// Локальный выбор пользователя: каждый аккаунт подтверждает публичную историю отдельно
// на каждом устройстве. Сервер и блокчейн не хранят этот переключатель.
import { t } from '../i18n/index.js';
import { state } from '../state.js';
import { getDevicePref, setDevicePref } from './device-prefs.js';
import { confirmDialog } from '../components/confirm-dialog.js';
const PREFIX = 'showPublicHistoryWarning:';
export function getPublicHistoryRememberLabel() {
return t('dialogs.final.consent.remember_public_history');
}
function preferenceKey() {
const login = String(state.session?.login || '').trim().toLowerCase();
return login ? `${PREFIX}${login}` : null;
}
export function getShowPublicHistoryWarning() {
const key = preferenceKey();
return key ? getDevicePref(key, true) !== false : true;
}
export function setShowPublicHistoryWarning(show) {
const key = preferenceKey();
if (key) setDevicePref(key, Boolean(show));
}
export function confirmPublicHistoryAction(options = {}) {
if (!preferenceKey() || getShowPublicHistoryWarning()) {
return confirmDialog({
...options,
rememberChoice: {
label: getPublicHistoryRememberLabel(),
onConfirm: () => setShowPublicHistoryWarning(false),
},
});
}
return Promise.resolve(true);
}