fix(web): пересчитывать «Баланс API» на дашборде в базовую валюту

KPI складывал балансы аккаунтов в разных валютах как есть (46,8 EUR +
1120 RUB показывалось как 1166,80 ₽). Теперь каждый баланс переводится
в базовую валюту с учётом курса хостера.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DenozordecandClaude Opus 5.5 committed 2026-11-06 23:18:16 +07:00
1 parent d0e262c41d
commit a26647a52d
10 files changed
+16 -7

No files matched your search

+16 -7
View File
@@ -35,7 +35,7 @@ import { StatusBadge } from '@/components/status-badge'
import { computeInventoryHealth } from '@/lib/inventory-health'
import { buildAtRiskAccounts, type AtRiskAccount } from '@/lib/account-health'
import { formatInBaseCurrency, normalizeRatesPayload, vpsStatusLabel, convertVpsMonthlyBurnToBase, formatCurrency } from '@/lib/format'
import { formatInBaseCurrency, normalizeRatesPayload, vpsStatusLabel, convertVpsMonthlyBurnToBase, convertWithProviderRate, formatCurrency } from '@/lib/format'
import { providerByIdMap } from '@/lib/billmanager'
import { exportActiveVpsCsv } from '@/lib/export-csv'
import {
@@ -245,6 +245,20 @@ function DashboardPage() {
const expiringCount = stats?.expiringWithin7Days ?? 0
const issuesCount = issues.length
const providerById = providerByIdMap(snap.providers)
// Each account's balance is in its own currency — sum after converting, not raw (EUR + RUB ≠ ₽).
const balanceBase = snap.providerAccounts.reduce((sum, a) => {
if (a.balanceApi == null || !Number.isFinite(Number(a.balanceApi))) return sum
return (
sum +
convertWithProviderRate(
Number(a.balanceApi),
a.balanceCurrency || a.currency || baseCur,
providerById.get(a.providerId),
snap.settings,
ratesData,
).value
)
}, 0)
const monthlyBurnBase = activeVps.reduce(
(sum, item) =>
sum +
@@ -295,12 +309,7 @@ function DashboardPage() {
{
id: 'balance',
label: 'Баланс API',
value: formatInBaseCurrency(
stats?.totalBalanceApi ?? 0,
baseCur,
snap.settings,
ratesData,
),
value: formatCurrency(balanceBase, baseCur),
icon: <WalletIcon className="size-4" />,
iconClassName: 'text-success',
to: '/accounts',
Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB