miner
This commit is contained in:
@@ -30,8 +30,8 @@ final class Router
|
||||
private const OVERVIEW_WINDOW_DAYS = 15;
|
||||
private const FX_FETCH_MAX_AGE_HOURS = 3.0;
|
||||
private const BASE_OFFER_SPEEDS = [
|
||||
'fiat' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 75.0, 'unit' => 'kH/s'],
|
||||
'fiat' => ['value' => 100.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
];
|
||||
|
||||
private string $moduleBasePath;
|
||||
@@ -1907,18 +1907,23 @@ final class Router
|
||||
{
|
||||
$paymentType = $this->enumValue($input['payment_type'] ?? 'fiat', ['fiat', 'crypto'], 'payment_type');
|
||||
$baseSpeed = self::BASE_OFFER_SPEEDS[$paymentType] ?? self::BASE_OFFER_SPEEDS['fiat'];
|
||||
$bonusPercent = $this->optionalDecimal($input['bonus_percent'] ?? null);
|
||||
$basePriceCurrency = $paymentType === 'crypto'
|
||||
? 'USD'
|
||||
: $this->requiredCurrency($input['base_price_currency'] ?? ($input['reference_price_currency'] ?? $input['price_currency'] ?? null), 'base_price_currency');
|
||||
$projectCryptoCurrency = $this->requiredCurrency($this->settings($projectKey, [
|
||||
'cost_plans' => false,
|
||||
'currencies' => false,
|
||||
'payouts' => false,
|
||||
'wallet_withdrawals' => false,
|
||||
'miner_offers' => false,
|
||||
'purchased_miners' => false,
|
||||
])['crypto_currency'] ?? 'DOGE', 'crypto_currency');
|
||||
$basePriceCurrency = $this->requiredCurrency($input['base_price_currency'] ?? ($input['reference_price_currency'] ?? $input['price_currency'] ?? null), 'base_price_currency');
|
||||
$payload = [
|
||||
'label' => $this->requiredString($input['label'] ?? null, 'label', 120),
|
||||
'runtime_months' => $this->optionalPositiveInt($input['runtime_months'] ?? null),
|
||||
'runtime_months' => 3,
|
||||
'mining_speed_value' => $baseSpeed['value'],
|
||||
'mining_speed_unit' => $baseSpeed['unit'],
|
||||
'bonus_speed_value' => $this->bonusSpeedFromPercent((float) $baseSpeed['value'], (string) $baseSpeed['unit'], $bonusPercent),
|
||||
'bonus_speed_unit' => $bonusPercent !== null ? (string) $baseSpeed['unit'] : null,
|
||||
'bonus_percent' => $bonusPercent,
|
||||
'bonus_speed_value' => null,
|
||||
'bonus_speed_unit' => null,
|
||||
'bonus_percent' => null,
|
||||
'base_price_amount' => $this->requiredDecimal($input['base_price_amount'] ?? ($input['reference_price_amount'] ?? $input['price_amount'] ?? null), 'base_price_amount'),
|
||||
'base_price_currency' => $basePriceCurrency,
|
||||
'payment_type' => $paymentType,
|
||||
@@ -1927,12 +1932,23 @@ final class Router
|
||||
'is_active' => !empty($input['is_active']) ? 1 : 0,
|
||||
];
|
||||
|
||||
if ($bonusPercent !== null && $bonusPercent < 0) {
|
||||
throw new ApiException('Bonus-Prozent darf nicht negativ sein.', 422);
|
||||
if ($paymentType === 'crypto') {
|
||||
$allowedCryptoCurrencies = array_values(array_unique(['USD', $projectCryptoCurrency]));
|
||||
if (!in_array($payload['base_price_currency'], $allowedCryptoCurrencies, true)) {
|
||||
throw new ApiException('Bei Krypto-Angeboten sind nur USD oder die Projekt-Kryptowaehrung erlaubt.', 422, [
|
||||
'field' => 'base_price_currency',
|
||||
'allowed' => $allowedCryptoCurrencies,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if ($payload['base_price_currency'] !== 'EUR') {
|
||||
throw new ApiException('Bei FIAT-Angeboten ist aktuell nur EUR als Basiswaehrung erlaubt.', 422, [
|
||||
'field' => 'base_price_currency',
|
||||
'allowed' => ['EUR'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertCurrencyType($payload['base_price_currency'], false, 'base_price_currency');
|
||||
|
||||
return $this->repository()->saveMinerOffer($projectKey, $payload);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user