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

This commit is contained in:
2026-05-09 01:15:05 +02:00
parent fc95898a9d
commit 693086029d
2 changed files with 55 additions and 8 deletions

View File

@@ -491,26 +491,61 @@ final class OcrService
$flags[] = 'wallet_total_missing';
}
preg_match_all(
'/([A-Z][A-Za-z0-9]+(?:\s+[A-Z][A-Za-z0-9]+)*)\s+(\d+(?:[.,]\d+)?)\s+([A-Z]{2,10})\s+(?:\d+(?:[.,]\d+)?)\s+USD\s+(\d+(?:[.,]\d+)?)\s+USD/u',
$normalizedText,
$assetRowMatches,
PREG_SET_ORDER
);
foreach ($assetRowMatches as $match) {
$balanceAmount = round((float) str_replace(',', '.', $match[2]), 10);
$assetCurrency = strtoupper((string) $match[3]);
$priceAmount = round((float) str_replace(',', '.', $match[4]), 8);
if ($balanceAmount <= 0 || $assetCurrency === '') {
continue;
}
$balances[$assetCurrency] = [
'balance' => $balanceAmount,
'price_amount' => $priceAmount > 0 ? $priceAmount : null,
'price_currency' => $priceAmount > 0 ? 'USD' : null,
];
}
preg_match_all('/(\d+(?:[.,]\d+)?)\s*([A-Z]{2,10})\b/u', $normalizedText, $balanceMatches, PREG_SET_ORDER);
foreach ($balanceMatches as $match) {
$amount = round((float) str_replace(',', '.', $match[1]), 10);
$currency = strtoupper((string) $match[2]);
if ($amount <= 0 || $currency === '') {
if ($amount <= 0 || $currency === '' || in_array($currency, ['USD', 'EUR'], true)) {
continue;
}
if (!isset($balances[$currency]) || $amount > (float) $balances[$currency]) {
$balances[$currency] = $amount;
if (!isset($balances[$currency])) {
$balances[$currency] = [
'balance' => $amount,
'price_amount' => null,
'price_currency' => null,
];
continue;
}
$existingBalance = is_array($balances[$currency]) ? (float) ($balances[$currency]['balance'] ?? 0.0) : (float) $balances[$currency];
if ($amount > $existingBalance) {
$balances[$currency]['balance'] = $amount;
}
}
if ($walletCurrencyHint !== '' && array_key_exists($walletCurrencyHint, $balances)) {
$walletCurrency = $walletCurrencyHint;
$walletBalance = (float) $balances[$walletCurrencyHint];
$walletBalance = is_array($balances[$walletCurrencyHint])
? (float) ($balances[$walletCurrencyHint]['balance'] ?? 0.0)
: (float) $balances[$walletCurrencyHint];
} elseif ($balances !== []) {
foreach (['DOGE', 'BTC', 'ETH', 'CTC', 'HSH', 'LTC', 'USDT', 'USDC'] as $preferredCurrency) {
if (array_key_exists($preferredCurrency, $balances)) {
$walletCurrency = $preferredCurrency;
$walletBalance = (float) $balances[$preferredCurrency];
$walletBalance = is_array($balances[$preferredCurrency])
? (float) ($balances[$preferredCurrency]['balance'] ?? 0.0)
: (float) $balances[$preferredCurrency];
break;
}
}
@@ -518,7 +553,9 @@ final class OcrService
$firstCurrency = array_key_first($balances);
if (is_string($firstCurrency)) {
$walletCurrency = $firstCurrency;
$walletBalance = (float) $balances[$firstCurrency];
$walletBalance = is_array($balances[$firstCurrency])
? (float) ($balances[$firstCurrency]['balance'] ?? 0.0)
: (float) $balances[$firstCurrency];
}
}
} else {