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

This commit is contained in:
2026-07-13 23:08:56 +02:00
parent 554664737a
commit 328a40eedc
4 changed files with 296 additions and 32 deletions

View File

@@ -1016,7 +1016,21 @@
? `Verwendet den letzten Upload von ${fmtDate(latest.measured_at)} mit ${fmtNumber(fullTransferCoins, 6)} ${currentMiningCurrency}.`
: `Verwendet den letzten Upload von ${fmtDate(latest.measured_at)} mit ${fmtNumber(fullTransferCoins, 6)} ${currentMiningCurrency}. Backend erlaubt den Kompletttransfer nur, wenn dieser Upload hoechstens 3 Minuten alt ist.`;
const latestWalletSnapshot = currentWalletSnapshots.length ? currentWalletSnapshots[0] : null;
const currentWalletMiningBalance = walletAssetBalance(latestWalletSnapshot, currentMiningCurrency);
const currentWalletPrimaryCurrency = (() => {
const snapshotCurrency = String((latestWalletSnapshot && latestWalletSnapshot.wallet_currency) || '').toUpperCase();
if (snapshotCurrency) {
return snapshotCurrency;
}
const latestWithdrawal = currentWalletWithdrawals.length ? currentWalletWithdrawals[currentWalletWithdrawals.length - 1] : null;
const latestWalletTransfer = currentPayouts.length ? currentPayouts[currentPayouts.length - 1] : null;
const ledgerCurrency = String(
(latestWithdrawal && latestWithdrawal.withdrawal_currency)
|| (latestWalletTransfer && latestWalletTransfer.payout_currency)
|| ''
).toUpperCase();
return ledgerCurrency || currentMiningCurrency || currentSettings.crypto_currency || 'DOGE';
})();
const currentWalletMiningBalance = walletPurchasingPower(latestWalletSnapshot, currentMiningCurrency);
const preferredCurrencyCodes = Array.isArray(currentSettings.preferred_currencies)
? currentSettings.preferred_currencies.map((code) => String(code || '').toUpperCase()).filter(Boolean)
: [];
@@ -1053,7 +1067,7 @@
return false;
}
if (selectedOfferType === 'crypto' && !isOfferAvailableForWallet(offer, currentMiningCurrency, currentWalletMiningBalance)) {
if (selectedOfferType === 'crypto' && !isOfferAvailableForWallet(offer, latestWalletSnapshot)) {
return false;
}
@@ -1075,7 +1089,7 @@
return true;
});
const scenarioMinerOffers = filteredMinerOffers.filter((offer) => isOfferAvailableForWallet(offer, currentMiningCurrency, currentWalletMiningBalance));
const scenarioMinerOffers = filteredMinerOffers.filter((offer) => isOfferAvailableForWallet(offer, latestWalletSnapshot));
const speedUnits = ['kH/s', 'MH/s'];
const fiatCurrencies = currencies.filter((currency) => !currency.is_crypto);
const cryptoCurrencies = currencies.filter((currency) => !!currency.is_crypto);
@@ -1342,7 +1356,56 @@
return Number.isFinite(balance) ? balance : null;
}
function isOfferAvailableForWallet(offer, miningCurrency, walletBalance) {
function walletPurchasingPower(snapshot, targetCurrency) {
const target = String(targetCurrency || '').toUpperCase();
if (!snapshot || !target) {
return null;
}
const directBalance = walletAssetBalance(snapshot, target);
if (Number.isFinite(directBalance)) {
return directBalance;
}
const totalValueAmount = Number(snapshot.total_value_amount);
const totalValueCurrency = String(snapshot.total_value_currency || '').toUpperCase();
if (Number.isFinite(totalValueAmount) && totalValueCurrency) {
const convertedTotal = convertCurrencyValue(totalValueAmount, totalValueCurrency, target);
if (Number.isFinite(convertedTotal)) {
return convertedTotal;
}
}
const assets = snapshot.balances_json && typeof snapshot.balances_json === 'object' ? snapshot.balances_json : {};
let total = 0;
let matched = false;
for (const [assetCode, assetValue] of Object.entries(assets)) {
const normalizedCode = String(assetCode || '').toUpperCase();
const balance = Number(assetValue && typeof assetValue === 'object' ? assetValue.balance : assetValue);
const priceAmount = Number(assetValue && typeof assetValue === 'object' ? assetValue.price_amount : null);
const priceCurrency = String(assetValue && typeof assetValue === 'object' ? assetValue.price_currency : '').toUpperCase();
if (!normalizedCode || !Number.isFinite(balance) || balance <= 0) {
continue;
}
if (normalizedCode === target) {
total += balance;
matched = true;
continue;
}
if (Number.isFinite(priceAmount) && priceAmount > 0 && priceCurrency) {
const assetValueInPriceCurrency = balance * priceAmount;
const converted = convertCurrencyValue(assetValueInPriceCurrency, priceCurrency, target);
if (Number.isFinite(converted)) {
total += converted;
matched = true;
}
}
}
return matched ? total : null;
}
function isOfferAvailableForWallet(offer, walletSnapshot) {
if (!offer || !offer.is_active) {
return false;
}
@@ -1352,11 +1415,10 @@
}
const currency = String(offer.effective_price_currency || offer.price_currency || '').toUpperCase();
const expectedCurrency = String(miningCurrency || '').toUpperCase();
const price = Number(offer.effective_price_amount);
const balance = Number(walletBalance);
const balance = Number(walletPurchasingPower(walletSnapshot, currency));
if (!currency || !expectedCurrency || currency !== expectedCurrency || !Number.isFinite(price) || !Number.isFinite(balance)) {
if (!currency || !Number.isFinite(price) || !Number.isFinite(balance)) {
return true;
}
@@ -1676,11 +1738,15 @@
const preview = normalizeOcrPreview(ocrPreview);
const raw = fromPreview ? {
...preview.suggested,
coin_currency: currentMiningCurrency,
image_path: preview.image_path,
ocr_raw_text: preview.raw_text,
ocr_confidence: preview.confidence,
ocr_flags: preview.flags,
} : measurementForm;
} : {
...measurementForm,
coin_currency: currentMiningCurrency,
};
setSaving(true);
setError('');
@@ -1819,7 +1885,8 @@
body.append('image', nextForm.image);
body.append('date_context', nextForm.date_context);
body.append('ocr_hint_text', nextForm.ocr_hint_text);
body.append('wallet_currency_hint', currentSettings.crypto_currency || 'DOGE');
body.append('wallet_currency_hint', currentWalletPrimaryCurrency);
body.append('mining_currency_hint', currentMiningCurrency);
const data = await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/ocr-preview`, {
method: 'POST',
body,
@@ -2037,7 +2104,7 @@
applySavedPayout(savedPayout);
setWalletTransferRows((previous) => previous.filter((row) => String(row.id) !== String(savedPayout.id)).concat(savedPayout).sort((left, right) => String(left?.payout_at || '').localeCompare(String(right?.payout_at || ''))));
invalidateProjectBootstrapCache(projectKey);
setPayoutForm({ payout_at: '', coins_amount: '', payout_currency: currentSettings.crypto_currency || 'DOGE', note: '' });
setPayoutForm({ payout_at: '', coins_amount: '', payout_currency: currentMiningCurrency, note: '' });
setPayoutModalOpen(false);
await reloadBootstrapAfterMutation('Wallet-Transfer gespeichert.');
} catch (err) {
@@ -2131,7 +2198,7 @@
setWalletWithdrawalForm({
withdrawal_at: '',
coins_amount: '',
withdrawal_currency: currentSettings.crypto_currency || 'DOGE',
withdrawal_currency: currentWalletPrimaryCurrency,
note: '',
});
setWalletWithdrawalModalOpen(false);
@@ -2480,7 +2547,7 @@
isWalletPreview
? h('div', { key: 'wallet-form', className: 'mc-two-col' }, [
displayField('Erkannter Typ', 'Wallet-Snapshot'),
displayField('Mining-Waehrung im Wallet', `${fmtNumber(preview.suggested_wallet.wallet_balance, 8)} ${preview.suggested_wallet.wallet_currency || currentSettings.crypto_currency || 'DOGE'}`),
displayField('Wallet-Bestand', `${fmtNumber(preview.suggested_wallet.wallet_balance, 8)} ${preview.suggested_wallet.wallet_currency || currentWalletPrimaryCurrency}`),
displayField('Gesamtwert', preview.suggested_wallet.total_value_amount !== '' && preview.suggested_wallet.total_value_amount !== null
? `${fmtNumber(preview.suggested_wallet.total_value_amount, 4)} ${preview.suggested_wallet.total_value_currency || ''}`.trim()
: 'n/a'),
@@ -2629,6 +2696,7 @@
const breakEvenReached = breakEvenRemainingAmount !== null && breakEvenRemainingAmount <= 0;
const breakEvenEta = latest && latest.break_even_eta_at ? fmtDate(latest.break_even_eta_at) : null;
const walletBalanceCurrentAsset = payload?.summary?.payouts?.wallet_balance_current_asset;
const walletBalanceCurrentAssetDirect = payload?.summary?.payouts?.wallet_balance_current_asset_direct;
const holdingsCurrentAsset = payload?.summary?.payouts?.holdings_current_asset;
return h('div', { className: 'mc-stack' }, [
@@ -2660,7 +2728,7 @@
label: `Theoretischer Bestand ${currentCoinCurrency}`,
value: payload?.summary?.payouts ? fmtNumber(holdingsCurrentAsset, 6) : 'n/a',
sub: payload?.summary?.payouts
? `Wallet ${fmtNumber(walletBalanceCurrentAsset, 6)} ${currentCoinCurrency} · Miner ${fmtNumber(latest?.coins_total_visible ?? latest?.coins_total, 6)} ${currentCoinCurrency}`
? `Wallet-Gegenwert ${fmtNumber(walletBalanceCurrentAsset, 6)} ${currentCoinCurrency}${currentWalletPrimaryCurrency !== currentCoinCurrency ? ` · direkt ${fmtNumber(walletBalanceCurrentAssetDirect, 6)} ${currentCoinCurrency}` : ''} · Miner ${fmtNumber(latest?.coins_total_visible ?? latest?.coins_total, 6)} ${currentCoinCurrency}`
: '',
}),
h(StatCard, {
@@ -2944,7 +3012,7 @@
setWalletWithdrawalForm((previous) => ({
withdrawal_at: previous.withdrawal_at || nowDateTimeLocalValue(),
coins_amount: previous.coins_amount || '',
withdrawal_currency: currentMiningCurrency,
withdrawal_currency: currentWalletPrimaryCurrency,
note: previous.note || '',
}));
setWalletWithdrawalModalOpen(true);
@@ -3117,7 +3185,7 @@
]),
panel('Miner-Angebote', selectedOfferType === 'crypto'
? (currentWalletMiningBalance !== null
? `Crypto-Angebote sind aktiv. Angezeigt werden nur Angebote, die dein NC-Wallet aktuell tragen kann (${fmtNumber(currentWalletMiningBalance, 8)} ${currentMiningCurrency}).`
? `Crypto-Angebote sind aktiv. Angezeigt werden nur Angebote, die dein NC-Wallet aktuell tragen kann (${fmtNumber(currentWalletMiningBalance, 8)} ${currentMiningCurrency} Gegenwert).`
: 'Crypto-Angebote sind aktiv. Solange kein Wallet-Bestand erkannt wird, bleiben die Krypto-Angebote sichtbar.')
: 'Fiat-Angebote sind aktiv. Die Berechnung startet erst, wenn du eine Geschwindigkeit eingibst.',
[
@@ -3224,7 +3292,7 @@
? h('div', { key: 'rec-ref', className: 'mc-kicker' }, `Basis ${fmtNumber(offer.base_price_amount, 6)} ${offer.base_price_currency}`)
: null,
offer.payment_type ? h('div', { key: 'paytype', className: 'mc-kicker' }, offer.payment_type === 'crypto' ? `Zahlung in Krypto (${currentSettings.crypto_currency || 'DOGE'})` : `Zahlung in FIAT (${offer.base_price_currency || 'EUR'})`) : null,
h('div', { key: 'availability', className: 'mc-kicker' }, isOfferAvailableForWallet(offer, currentMiningCurrency, currentWalletMiningBalance) ? 'Im NC Wallet verfuegbar' : 'Nicht genug NC Wallet Bestand'),
h('div', { key: 'availability', className: 'mc-kicker' }, isOfferAvailableForWallet(offer, latestWalletSnapshot) ? 'Im NC Wallet verfuegbar' : 'Nicht genug NC Wallet Bestand'),
h('div', { key: 'renew', className: 'mc-kicker' }, offer.auto_renew ? 'Automatische Verlängerung' : 'Laeuft aus'),
]),
h('td', { key: 'action' }, [
@@ -3272,7 +3340,7 @@
});
setPurchaseMinerModalOpen(true);
},
disabled: !isOfferAvailableForWallet(offer, currentMiningCurrency, currentWalletMiningBalance),
disabled: !isOfferAvailableForWallet(offer, latestWalletSnapshot),
}, 'Mieten'),
]),
]))
@@ -3434,7 +3502,7 @@
h('form', { key: 'form', className: 'mc-form', onSubmit: submitWalletWithdrawal }, [
inputField('Auszahlungszeitpunkt', 'datetime-local', walletWithdrawalForm.withdrawal_at, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_at: value })),
inputField('Coins', 'number', walletWithdrawalForm.coins_amount, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, coins_amount: value }), '0.000001'),
selectField('Waehrung', walletWithdrawalForm.withdrawal_currency, [currentMiningCurrency].concat(selectableCurrencies.map((currency) => currency.code).filter((code) => code !== currentMiningCurrency)), (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_currency: value })),
selectField('Waehrung', walletWithdrawalForm.withdrawal_currency, [currentWalletPrimaryCurrency].concat(selectableCurrencies.map((currency) => currency.code).filter((code) => code !== currentWalletPrimaryCurrency)), (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_currency: value })),
textareaField('Notiz', walletWithdrawalForm.note, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, note: value })),
h('div', { className: 'mc-inline-row' }, [
h('button', { type: 'button', className: 'mc-button mc-button--ghost', onClick: () => setWalletWithdrawalModalOpen(false) }, 'Abbrechen'),
@@ -3656,7 +3724,7 @@
h('form', { key: 'form', className: 'mc-form', onSubmit: submitWalletWithdrawal }, [
inputField('Auszahlungszeitpunkt', 'datetime-local', walletWithdrawalForm.withdrawal_at, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_at: value })),
inputField('Coins', 'number', walletWithdrawalForm.coins_amount, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, coins_amount: value }), '0.000001'),
selectField('Waehrung', walletWithdrawalForm.withdrawal_currency, [currentMiningCurrency].concat(selectableCurrencies.map((currency) => currency.code).filter((code) => code !== currentMiningCurrency)), (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_currency: value })),
selectField('Waehrung', walletWithdrawalForm.withdrawal_currency, [currentWalletPrimaryCurrency].concat(selectableCurrencies.map((currency) => currency.code).filter((code) => code !== currentWalletPrimaryCurrency)), (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, withdrawal_currency: value })),
textareaField('Notiz', walletWithdrawalForm.note, (value) => setWalletWithdrawalForm({ ...walletWithdrawalForm, note: value })),
h('div', { className: 'mc-inline-row' }, [
h('button', { type: 'button', className: 'mc-button mc-button--ghost', onClick: () => setWalletWithdrawalModalOpen(false) }, 'Abbrechen'),