sfdsf
This commit is contained in:
@@ -1380,6 +1380,19 @@ final class AnalyticsService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$reportedTotal = is_numeric($snapshot['total_value_amount'] ?? null)
|
||||||
|
? (float) $snapshot['total_value_amount']
|
||||||
|
: null;
|
||||||
|
$reportedCurrency = strtoupper(trim((string) ($snapshot['total_value_currency'] ?? '')));
|
||||||
|
if ($reportedTotal !== null && $reportedTotal >= 0 && $reportedCurrency !== '') {
|
||||||
|
$convertedTotal = $reportedCurrency === $target
|
||||||
|
? $reportedTotal
|
||||||
|
: $this->convertAmount($reportedTotal, $reportedCurrency, $target, $fxContext);
|
||||||
|
if ($convertedTotal !== null) {
|
||||||
|
return $convertedTotal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$balances = is_array($snapshot['balances_json'] ?? null) ? $snapshot['balances_json'] : [];
|
$balances = is_array($snapshot['balances_json'] ?? null) ? $snapshot['balances_json'] : [];
|
||||||
if ($balances === []) {
|
if ($balances === []) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -538,7 +538,11 @@ final class OcrService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$priceAmount = $this->pickWalletUnitPrice($balanceAmount, $usdCandidates);
|
$priceAmount = $this->pickWalletUnitPrice(
|
||||||
|
$balanceAmount,
|
||||||
|
$usdCandidates,
|
||||||
|
$totalValueCurrency === 'USD' ? $totalValueAmount : null
|
||||||
|
);
|
||||||
$balances[$currency] = [
|
$balances[$currency] = [
|
||||||
'balance' => $balanceAmount,
|
'balance' => $balanceAmount,
|
||||||
'price_amount' => $priceAmount,
|
'price_amount' => $priceAmount,
|
||||||
@@ -613,7 +617,7 @@ final class OcrService
|
|||||||
/**
|
/**
|
||||||
* @param list<float|int> $candidates
|
* @param list<float|int> $candidates
|
||||||
*/
|
*/
|
||||||
private function pickWalletUnitPrice(float $balance, array $candidates): ?float
|
private function pickWalletUnitPrice(float $balance, array $candidates, ?float $walletTotal = null): ?float
|
||||||
{
|
{
|
||||||
$candidates = array_values(array_filter(array_map(
|
$candidates = array_values(array_filter(array_map(
|
||||||
static fn (mixed $value): float => round((float) $value, 8),
|
static fn (mixed $value): float => round((float) $value, 8),
|
||||||
@@ -624,7 +628,11 @@ final class OcrService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (count($candidates) === 1) {
|
if (count($candidates) === 1) {
|
||||||
return $candidates[0];
|
$candidate = $candidates[0];
|
||||||
|
if ($walletTotal !== null && $walletTotal > 0 && ($balance * $candidate) > ($walletTotal * 1.5)) {
|
||||||
|
return round($candidate / $balance, 8);
|
||||||
|
}
|
||||||
|
return $candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
$bestPrice = null;
|
$bestPrice = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user