ycdfdsf
This commit is contained in:
@@ -885,6 +885,9 @@
|
||||
const currentWalletSnapshots = Array.isArray(payload?.wallet_snapshots) ? payload.wallet_snapshots : [];
|
||||
const currentMinerOffers = Array.isArray(currentSettings.miner_offers) ? currentSettings.miner_offers : [];
|
||||
const currentPurchasedMiners = Array.isArray(currentSettings.purchased_miners) ? currentSettings.purchased_miners : [];
|
||||
const currentMiningCurrency = String((latest && latest.coin_currency) || currentSettings.crypto_currency || 'DOGE').toUpperCase();
|
||||
const latestWalletSnapshot = currentWalletSnapshots.length ? currentWalletSnapshots[0] : null;
|
||||
const currentWalletMiningBalance = walletAssetBalance(latestWalletSnapshot, currentMiningCurrency);
|
||||
const renewableOfferIds = new Set(
|
||||
currentMinerOffers
|
||||
.filter((offer) => !!offer.auto_renew)
|
||||
@@ -900,7 +903,7 @@
|
||||
: currencies;
|
||||
const selectableCurrencies = preferredSelectableCurrencies.length ? preferredSelectableCurrencies : currencies;
|
||||
const evaluatedMinerOffers = Array.isArray(payload?.summary?.miner_offers) ? payload.summary.miner_offers : [];
|
||||
const availableMinerOffers = evaluatedMinerOffers.filter((offer) => !!offer.is_active);
|
||||
const availableMinerOffers = evaluatedMinerOffers.filter((offer) => isOfferAvailableForWallet(offer, currentMiningCurrency, currentWalletMiningBalance));
|
||||
const filteredMinerOffers = availableMinerOffers.filter((offer) => {
|
||||
const speedMin = minerOfferFilters.speed_min === '' ? null : Number(minerOfferFilters.speed_min);
|
||||
const speedUnit = String(minerOfferFilters.speed_unit || 'auto');
|
||||
@@ -1124,6 +1127,43 @@
|
||||
return rate === null ? null : numericValue * rate;
|
||||
}
|
||||
|
||||
function walletAssetBalance(snapshot, currency) {
|
||||
const code = String(currency || '').toUpperCase();
|
||||
if (!snapshot || !code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const assets = snapshot.balances_json && typeof snapshot.balances_json === 'object' ? snapshot.balances_json : {};
|
||||
const asset = assets[code] ?? assets[code.toLowerCase()] ?? assets[code.toUpperCase()];
|
||||
const snapshotCurrency = String(snapshot.wallet_currency || '').toUpperCase();
|
||||
const rawBalance = asset && typeof asset === 'object'
|
||||
? asset.balance
|
||||
: (asset ?? (snapshotCurrency === code ? snapshot.wallet_balance : null));
|
||||
const balance = Number(rawBalance);
|
||||
return Number.isFinite(balance) ? balance : null;
|
||||
}
|
||||
|
||||
function isOfferAvailableForWallet(offer, miningCurrency, walletBalance) {
|
||||
if (!offer || !offer.is_active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (String(offer.payment_type || '').toLowerCase() !== 'crypto') {
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!currency || !expectedCurrency || currency !== expectedCurrency || !Number.isFinite(price) || !Number.isFinite(balance)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return price <= balance + 0.00000001;
|
||||
}
|
||||
|
||||
function latestFxHistoryRate(fromCurrency, toCurrency) {
|
||||
const from = String(fromCurrency || '').toUpperCase();
|
||||
const to = String(toCurrency || '').toUpperCase();
|
||||
@@ -1719,10 +1759,14 @@
|
||||
setSaving(true);
|
||||
setError('');
|
||||
try {
|
||||
const offerPayload = {
|
||||
...minerOfferForm,
|
||||
base_price_currency: minerOfferForm.payment_type === 'crypto' ? 'USD' : minerOfferForm.base_price_currency,
|
||||
};
|
||||
await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/miner-offers`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(minerOfferForm),
|
||||
body: JSON.stringify(offerPayload),
|
||||
});
|
||||
setMessage('Miner-Angebot gespeichert.');
|
||||
setMinerOfferForm({
|
||||
@@ -2090,7 +2134,7 @@
|
||||
]);
|
||||
|
||||
function renderTab() {
|
||||
const currentCoinCurrency = String((latest && latest.coin_currency) || currentSettings.crypto_currency || 'DOGE').toUpperCase();
|
||||
const currentCoinCurrency = currentMiningCurrency;
|
||||
const perDayLabel = `${currentCoinCurrency} pro Tag`;
|
||||
|
||||
if (activeTab === 'overview') {
|
||||
@@ -2534,7 +2578,10 @@
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
panel('Miner-Angebote', 'Hier werden nur Basis-Miner gepflegt. Alle vorgegebenen Geschwindigkeiten und Preise werden daraus automatisch abgeleitet.', [
|
||||
panel('Miner-Angebote', currentWalletMiningBalance !== null
|
||||
? `Hier werden nur Basis-Miner gepflegt. Krypto-Angebote werden gegen deinen aktuellen Wallet-Bestand (${fmtNumber(currentWalletMiningBalance, 8)} ${currentMiningCurrency}) gefiltert.`
|
||||
: 'Hier werden nur Basis-Miner gepflegt. Alle vorgegebenen Geschwindigkeiten und Preise werden daraus automatisch abgeleitet.',
|
||||
[
|
||||
h('div', { key: 'actions', className: 'mc-inline-row' }, [
|
||||
h('button', {
|
||||
key: 'add-offer',
|
||||
@@ -2579,7 +2626,7 @@
|
||||
h('td', { key: 'break' }, offer.break_even_days !== null ? `${fmtNumber(offer.break_even_days, 2)} Tage` : 'n/a'),
|
||||
h('td', { key: 'rec' }, [
|
||||
h('div', { key: 'rec-main' }, offer.recommendation),
|
||||
offer.base_price_amount !== null && offer.base_price_currency && offer.payment_type !== 'crypto'
|
||||
offer.base_price_amount !== null && offer.base_price_currency
|
||||
? 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,
|
||||
@@ -2784,15 +2831,17 @@
|
||||
inputField('Laufzeit in Monaten', 'number', minerOfferForm.runtime_months, (value) => setMinerOfferForm({ ...minerOfferForm, runtime_months: value })),
|
||||
displayField('Basis-Geschwindigkeit', baseOfferSpeedLabel(minerOfferForm.payment_type)),
|
||||
inputField('Bonus-Hashrate in %', 'number', minerOfferForm.bonus_percent, (value) => setMinerOfferForm({ ...minerOfferForm, bonus_percent: value }), '0.01'),
|
||||
inputField('Basispreis', 'number', minerOfferForm.base_price_amount, (value) => setMinerOfferForm({ ...minerOfferForm, base_price_amount: value }), '0.000001'),
|
||||
inputField(minerOfferForm.payment_type === 'crypto' ? 'Basispreis in USD' : 'Basispreis', 'number', minerOfferForm.base_price_amount, (value) => setMinerOfferForm({ ...minerOfferForm, base_price_amount: value }), '0.000001'),
|
||||
selectField('Zahlungsart', minerOfferForm.payment_type, [{ value: 'fiat', label: 'FIAT' }, { value: 'crypto', label: 'Krypto' }], (value) => setMinerOfferForm({
|
||||
...minerOfferForm,
|
||||
payment_type: value,
|
||||
base_price_currency: value === 'crypto'
|
||||
? (currentSettings.crypto_currency || selectableCryptoCurrencies[0]?.code || 'DOGE')
|
||||
? 'USD'
|
||||
: (selectableFiatCurrencies[0]?.code || 'USD'),
|
||||
})),
|
||||
selectField('Basiswährung', minerOfferForm.base_price_currency, (minerOfferForm.payment_type === 'crypto' ? selectableCryptoCurrencies : selectableFiatCurrencies).map((currency) => currency.code), (value) => setMinerOfferForm({ ...minerOfferForm, base_price_currency: value })),
|
||||
minerOfferForm.payment_type === 'crypto'
|
||||
? displayField('Kostenwaehrung', 'USD')
|
||||
: selectField('Basiswährung', minerOfferForm.base_price_currency, selectableFiatCurrencies.map((currency) => currency.code), (value) => setMinerOfferForm({ ...minerOfferForm, base_price_currency: value })),
|
||||
h('label', { className: 'mc-checkbox' }, [
|
||||
h('input', { type: 'checkbox', checked: !!minerOfferForm.auto_renew, onChange: (event) => setMinerOfferForm({ ...minerOfferForm, auto_renew: event.target.checked }) }),
|
||||
'Automatische Verlängerung',
|
||||
@@ -2832,8 +2881,10 @@
|
||||
});
|
||||
}),
|
||||
inputField('Mietdatum/-zeit', 'datetime-local', purchaseMinerForm.purchased_at, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, purchased_at: value })),
|
||||
displayField('Gewaehlte Geschwindigkeit', purchaseMinerForm.mining_speed_value && purchaseMinerForm.mining_speed_unit ? `${purchaseMinerForm.mining_speed_value} ${purchaseMinerForm.mining_speed_unit}` : 'n/a'),
|
||||
displayField('Bonus-Hashrate', purchaseMinerForm.bonus_percent ? `${purchaseMinerForm.bonus_percent}%` : 'kein Bonus'),
|
||||
inputField('Label', 'text', purchaseMinerForm.label, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, label: value })),
|
||||
inputField('Mining-Geschwindigkeit', 'number', purchaseMinerForm.mining_speed_value, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, mining_speed_value: value }), '0.0001'),
|
||||
selectField('Mining-Einheit', purchaseMinerForm.mining_speed_unit, speedUnits, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, mining_speed_unit: value })),
|
||||
inputField('Bonus-Hashrate in %', 'number', purchaseMinerForm.bonus_percent, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, bonus_percent: value }), '0.01'),
|
||||
inputField('Exakter Mietpreis', 'number', purchaseMinerForm.total_cost_amount, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, total_cost_amount: value }), '0.000001'),
|
||||
selectField('Mietwährung', purchaseMinerForm.currency, selectableCurrencies.map((currency) => currency.code), (value) => setPurchaseMinerForm({ ...purchaseMinerForm, currency: value })),
|
||||
inputField('Referenzpreis', 'number', purchaseMinerForm.reference_price_amount, (value) => setPurchaseMinerForm({ ...purchaseMinerForm, reference_price_amount: value }), '0.000001'),
|
||||
|
||||
Reference in New Issue
Block a user