cyxc
All checks were successful
Deploy / deploy-staging (push) Successful in 8s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-05 20:36:41 +02:00
parent fd092ef615
commit eb8b04a621
14 changed files with 39 additions and 969 deletions

View File

@@ -124,18 +124,6 @@
return `${fxBaseUrl}/latest?base=${encodeURIComponent(String(base || 'USD').toUpperCase())}`;
}
function buildExternalCurrenciesUrl() {
if (fxProvider === 'currencyapi') {
const params = new URLSearchParams({ output: 'json' });
if (fxApiKeyMask) {
params.set('key', fxApiKeyMask);
}
return `${fxCurrenciesUrl}/api/v2/currencies?${params.toString()}`;
}
return fxCurrenciesUrl;
}
async function loadLatestDebugTrace() {
try {
const response = await fetch(`${apiBase}/debug/latest`, {
@@ -667,8 +655,6 @@
});
const [fxHistory, setFxHistory] = useState([]);
const [fxSelection, setFxSelection] = useState(['DOGE', 'USD', 'EUR']);
const [fxDisplayBase, setFxDisplayBase] = useState('USD');
const [fxSearch, setFxSearch] = useState('');
const [reportCurrencyOverride, setReportCurrencyOverride] = useState(() => {
const value = String(getCookie('mining_checker_report_currency') || '').toUpperCase();
return /^[A-Z0-9]{3,10}$/.test(value) ? value : '';
@@ -1147,12 +1133,6 @@
}
}, [activeTab, projectKey]);
useEffect(() => {
if (activeTab === 'currencies') {
loadFxHistory(projectKey);
}
}, [activeTab, projectKey]);
useEffect(() => {
async function loadSavedDashboards() {
if (!payload || !currentDashboards.length) {
@@ -1854,83 +1834,6 @@
}
}
async function refreshCurrencyCatalog() {
setSaving(true);
setError('');
setMessage('');
try {
emitDebug({
type: 'external:request-plan',
label: 'Ich rufe jetzt extern den Waehrungskatalog auf',
provider: fxProvider,
url: buildExternalCurrenciesUrl(),
method: 'GET',
headers: { Accept: 'application/json' },
});
const probe = await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/currencies-probe`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
timeoutMs: 20000,
});
emitDebug({
type: 'external:response',
label: 'Hey, hier ist der Response vor dem DB-Schritt',
url: probe.url,
http_status: probe.http_status,
curl_error: probe.curl_error,
response_headers: probe.response_headers,
response_body: probe.response_body,
});
const result = await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/currencies-refresh`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
timeoutMs: 20000,
});
setPayload((current) => {
const next = normalizeBootstrap(current, projectKey);
return {
...next,
settings: {
...next.settings,
currencies: Array.isArray(result.currencies) ? result.currencies : next.settings.currencies,
},
};
});
setMessage(`Waehrungskatalog synchronisiert. ${result.synced_count || 0} Waehrungen verarbeitet.`);
} catch (err) {
setError(err.message);
} finally {
setSaving(false);
}
}
async function saveFxSelection() {
setSaving(true);
setError('');
setMessage('');
try {
await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/settings`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
baseline_measured_at: currentSettings.baseline_measured_at,
baseline_coins_total: currentSettings.baseline_coins_total,
daily_cost_amount: currentSettings.daily_cost_amount,
daily_cost_currency: currentSettings.daily_cost_currency,
report_currency: currentSettings.report_currency || 'EUR',
fx_max_age_hours: currentSettings.fx_max_age_hours || 3,
preferred_currencies: fxSelection,
}),
});
await loadBootstrap(projectKey);
setMessage('Waehrungs-Auswahl gespeichert.');
} catch (err) {
setError(err.message);
} finally {
setSaving(false);
}
}
async function copyDebugConsole() {
const content = debugEntries
.slice()
@@ -1964,80 +1867,10 @@
}
}
function addFxSelection(code) {
const normalized = String(code || '').toUpperCase().trim();
if (!normalized) {
return;
}
setFxSelection((current) => current.includes(normalized) ? current : current.concat([normalized]));
setFxSearch('');
}
function removeFxSelection(code) {
const normalized = String(code || '').toUpperCase().trim();
setFxSelection((current) => current.filter((item) => item !== normalized));
}
function resetReportCurrencyOverride() {
setReportCurrencyOverride('');
setCookie('mining_checker_report_currency', '', 0);
}
const selectedFxCodes = fxSelection.length ? fxSelection.map((code) => String(code || '').toUpperCase()) : ['DOGE', 'USD', 'EUR'];
const fxDisplayBaseNormalized = String(fxDisplayBase || 'USD').toUpperCase();
const groupedFxHistoryMap = new Map();
fxHistory.forEach((row, index) => {
const fetchId = row.fetch_id || `legacy-${row.fetched_at || 'none'}-${index}`;
if (!groupedFxHistoryMap.has(fetchId)) {
groupedFxHistoryMap.set(fetchId, {
fetch_id: fetchId,
fetched_at: row.fetched_at || null,
rate_date: row.rate_date || null,
base_currency: row.base_currency || null,
provider: row.provider || null,
rates: {},
});
}
const group = groupedFxHistoryMap.get(fetchId);
group.rates[String(row.target_currency || '').toUpperCase()] = row.rate;
});
function computeDisplayedFxRate(group, targetCode, displayBaseCode) {
const normalizedTarget = String(targetCode || '').toUpperCase();
const normalizedDisplayBase = String(displayBaseCode || '').toUpperCase();
const fetchBase = String(group.base_currency || '').toUpperCase();
if (!normalizedTarget || !normalizedDisplayBase) {
return null;
}
if (normalizedTarget === normalizedDisplayBase) {
return 1;
}
const targetRateRaw = normalizedTarget === fetchBase ? 1 : group.rates[normalizedTarget];
const displayBaseRateRaw = normalizedDisplayBase === fetchBase ? 1 : group.rates[normalizedDisplayBase];
const targetRate = targetRateRaw === null || targetRateRaw === undefined ? null : Number(targetRateRaw);
const displayBaseRate = displayBaseRateRaw === null || displayBaseRateRaw === undefined ? null : Number(displayBaseRateRaw);
if (!Number.isFinite(targetRate) || !Number.isFinite(displayBaseRate) || displayBaseRate === 0) {
return null;
}
return targetRate / displayBaseRate;
}
const groupedFxHistory = Array.from(groupedFxHistoryMap.values())
.map((group) => ({
...group,
selected_rates: selectedFxCodes.map((code) => ({
code,
rate: computeDisplayedFxRate(group, code, fxDisplayBaseNormalized),
})),
}))
.filter((group) => group.selected_rates.some((item) => item.rate !== null))
.slice(0, 30);
const debugConsoleText = debugEntries
.map((entry) => `${entry.time} · ${entry.type}\n${JSON.stringify(entry, null, 2)}`)
.join('\n\n');
@@ -2441,137 +2274,6 @@
]);
}
if (activeTab === 'currencies') {
const selectedSet = new Set((fxSelection || []).map((code) => String(code).toUpperCase()));
const searchNeedle = fxSearch.trim().toLowerCase();
const currencySuggestions = currencies
.filter((currency) => !selectedSet.has(String(currency.code || '').toUpperCase()))
.filter((currency) => {
if (!searchNeedle) {
return false;
}
const code = String(currency.code || '').toLowerCase();
const name = String(currency.name || '').toLowerCase();
return code.includes(searchNeedle) || name.includes(searchNeedle);
})
.slice(0, 12);
return h('div', { className: 'mc-stack' }, [
h('div', { className: 'mc-stack' }, [
panel('Waehrungs-Update', 'Auswahl wird in den Mining-Checker-Settings gespeichert und steht damit auf Handy und Desktop gleich zur Verfuegung.', [
h('div', { key: 'actions', className: 'mc-inline-row' }, [
h('button', {
key: 'save-selection',
type: 'button',
className: 'mc-button mc-button--ghost',
onClick: saveFxSelection,
disabled: saving,
}, saving ? 'Speichert …' : 'Auswahl speichern'),
h('button', {
key: 'refresh-rates',
type: 'button',
className: 'mc-button mc-button--primary',
onClick: refreshSelectedFxRates,
disabled: saving,
}, saving ? 'Aktualisiert …' : 'Alle Wechselkurse aktualisieren'),
h('button', {
key: 'refresh-catalog',
type: 'button',
className: 'mc-button mc-button--ghost',
onClick: refreshCurrencyCatalog,
disabled: saving,
}, saving ? 'Synchronisiert …' : 'Waehrungskatalog sync'),
]),
h('div', { key: 'types', className: 'mc-mini-grid' }, [
h('div', { key: 'fiat', className: 'mc-mini-card' }, [
h('div', { key: 'fiat-label', className: 'mc-field-label' }, 'Fiat'),
h('div', { key: 'fiat-value' }, `${fiatCurrencies.length} Waehrungen`),
]),
h('div', { key: 'crypto', className: 'mc-mini-card' }, [
h('div', { key: 'crypto-label', className: 'mc-field-label' }, 'Krypto'),
h('div', { key: 'crypto-value' }, `${cryptoCurrencies.length} Waehrungen`),
]),
]),
h('div', { key: 'selection-title', className: 'mc-field-label' }, 'Bevorzugte Waehrungen fuer Anzeige'),
h('div', { key: 'selection-row', className: 'mc-currency-selection-row' }, [
h('div', { key: 'selected', className: 'mc-token-list mc-token-list--inline' },
fxSelection.length
? fxSelection.map((code) => {
const currency = currencies.find((item) => item.code === code) || { code, name: code };
return h('button', {
key: `token-${code}`,
type: 'button',
className: 'mc-token',
onClick: () => removeFxSelection(code),
title: `${code} entfernen`,
}, [
h('span', { key: 'label' }, `${code} (${currency.name || code})`),
h('span', { key: 'close', className: 'mc-token-close' }, 'x'),
]);
})
: [h('div', { key: 'empty', className: 'mc-text' }, 'Noch keine bevorzugten Waehrungen ausgewaehlt.')]
),
h('div', { key: 'search-wrap', className: 'mc-field mc-currency-search' }, [
h('input', {
key: 'search-input',
type: 'text',
value: fxSearch,
className: 'mc-input',
placeholder: 'Waehrung hinzufuegen: EUR, USD, DOGE oder Euro',
onInput: (event) => setFxSearch(event.target.value),
}),
]),
]),
h('div', { key: 'display-base-wrap', className: 'mc-field mc-currency-search' }, [
h('label', { key: 'display-base-label', className: 'mc-field-label' }, 'Darstellung auf Basis von'),
h('select', {
key: 'display-base',
className: 'mc-select',
value: selectedFxCodes.includes(fxDisplayBaseNormalized) ? fxDisplayBaseNormalized : (selectedFxCodes[0] || 'USD'),
onChange: (event) => setFxDisplayBase(event.target.value),
}, selectedFxCodes.map((code) => h('option', { key: code, value: code }, code))),
]),
searchNeedle
? h('div', { key: 'suggestions', className: 'mc-suggestion-list' },
currencySuggestions.length
? currencySuggestions.map((currency) => h('button', {
key: `suggestion-${currency.code}`,
type: 'button',
className: 'mc-suggestion',
onClick: () => addFxSelection(currency.code),
}, [
h('strong', { key: 'code' }, currency.code),
h('span', { key: 'name' }, currency.name || currency.code),
]))
: [h('div', { key: 'no-match', className: 'mc-text' }, 'Keine passende Waehrung gefunden.')]
)
: null,
]),
]),
h('div', { className: 'mc-stack' }, [
panel('Letzte 30 Kurs-Uploads', 'Zeigt die zuletzt gespeicherten Wechselkurse aus der Datenbank.', [
h('div', { key: 'history-table', className: 'mc-table-shell' }, [
h('table', { key: 'table', className: 'mc-table' }, [
h('thead', { key: 'head' }, h('tr', null, ['Zeit', 'Stichtag', 'Fetch-Basis'].concat(selectedFxCodes).concat(['Provider']).map((label) => h('th', { key: label }, label)))),
h('tbody', { key: 'body' },
groupedFxHistory.length
? groupedFxHistory.map((row, index) => h('tr', { key: `${row.fetch_id || index}-${row.base_currency}` }, [
h('td', { key: 'fetched' }, fmtDate(row.fetched_at)),
h('td', { key: 'date' }, row.rate_date || 'n/a'),
h('td', { key: 'base' }, row.base_currency),
].concat(
row.selected_rates.map((item) => h('td', { key: `rate-${item.code}` }, item.rate === null ? 'n/a' : fmtNumber(item.rate, 8)))
).concat([
h('td', { key: 'provider' }, row.provider || 'n/a'),
])))
: [h('tr', { key: 'empty' }, h('td', { colSpan: 4 + selectedFxCodes.length }, 'Noch keine Wechselkurse fuer die ausgewaehlten Waehrungen gespeichert.'))]
),
]),
]),
]),
]),
]);
}
if (activeTab === 'mining') {
const scenarioCurrency = selectedMinerScenario?.scenario_currency || reportCurrency;
const scenarioCurrentDailyProfit = selectedMinerScenario ? convertMeasurementMoney(latest, selectedMinerScenario.scenario_current_daily_profit, reportCurrency) : null;