ycdfdsf
This commit is contained in:
@@ -634,6 +634,11 @@ final class AnalyticsService
|
||||
return $amount;
|
||||
}
|
||||
|
||||
$measurementConverted = $this->convertAmountFromMeasurementPrice($amount, $from, $to, $fxContext);
|
||||
if ($measurementConverted !== null) {
|
||||
return $measurementConverted;
|
||||
}
|
||||
|
||||
if ($this->fx === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -646,6 +651,62 @@ final class AnalyticsService
|
||||
return $this->fx->convertAt($amount, $from, $to, $at, null, $fetchId);
|
||||
}
|
||||
|
||||
private function convertAmountFromMeasurementPrice(float $amount, string $from, string $to, ?array $fxContext = null): ?float
|
||||
{
|
||||
if (!is_array($fxContext)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$coinCurrency = strtoupper(trim((string) ($fxContext['coin_currency'] ?? '')));
|
||||
$priceCurrency = strtoupper(trim((string) ($fxContext['effective_price_currency'] ?? $fxContext['price_currency'] ?? '')));
|
||||
$pricePerCoin = is_numeric($fxContext['effective_price_per_coin'] ?? null)
|
||||
? (float) $fxContext['effective_price_per_coin']
|
||||
: (is_numeric($fxContext['price_per_coin'] ?? null) ? (float) $fxContext['price_per_coin'] : null);
|
||||
|
||||
if ($coinCurrency === '' || $priceCurrency === '' || $pricePerCoin === null || $pricePerCoin <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($from === $coinCurrency && $to === $priceCurrency) {
|
||||
return $amount * $pricePerCoin;
|
||||
}
|
||||
|
||||
if ($from === $priceCurrency && $to === $coinCurrency) {
|
||||
return $amount / $pricePerCoin;
|
||||
}
|
||||
|
||||
if ($to === $coinCurrency && $this->fx !== null) {
|
||||
$convertedFiat = $this->fx->convertAt(
|
||||
$amount,
|
||||
$from,
|
||||
$priceCurrency,
|
||||
is_string($fxContext['measured_at'] ?? null) ? (string) $fxContext['measured_at'] : null,
|
||||
null,
|
||||
isset($fxContext['fx_fetch_id']) && is_numeric($fxContext['fx_fetch_id']) ? (int) $fxContext['fx_fetch_id'] : null
|
||||
);
|
||||
if (is_numeric($convertedFiat) && (float) $convertedFiat > 0) {
|
||||
return (float) $convertedFiat / $pricePerCoin;
|
||||
}
|
||||
}
|
||||
|
||||
if ($from === $coinCurrency && $this->fx !== null) {
|
||||
$convertedFiat = $amount * $pricePerCoin;
|
||||
$convertedTarget = $this->fx->convertAt(
|
||||
$convertedFiat,
|
||||
$priceCurrency,
|
||||
$to,
|
||||
is_string($fxContext['measured_at'] ?? null) ? (string) $fxContext['measured_at'] : null,
|
||||
null,
|
||||
isset($fxContext['fx_fetch_id']) && is_numeric($fxContext['fx_fetch_id']) ? (int) $fxContext['fx_fetch_id'] : null
|
||||
);
|
||||
if (is_numeric($convertedTarget)) {
|
||||
return (float) $convertedTarget;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function totalHashrateMh(array $entries): float
|
||||
{
|
||||
$total = 0.0;
|
||||
@@ -956,6 +1017,8 @@ final class AnalyticsService
|
||||
$convertedReference = $this->convertAmount($basePriceAmount, $basePriceCurrency, $effectivePriceCurrency, $latest);
|
||||
if ($convertedReference !== null && $convertedReference > 0) {
|
||||
$effectivePriceAmount = $convertedReference;
|
||||
} else {
|
||||
$effectivePriceAmount = null;
|
||||
}
|
||||
}
|
||||
$referencePriceAmount = $basePriceAmount;
|
||||
|
||||
Reference in New Issue
Block a user