import { Link } from 'react-router-dom'; import { SkeletonBlock } from '@/shared/ui/SkeletonBlock'; import type { BrokerAccount, BrokerMoney, BrokerPortfolio } from '@/shared/api/responses'; import { buildBrokerAllocation } from '@/entities/broker-position'; import { BrokerAllocationBar } from '@/widgets/broker-allocation-chart'; function formatBrokerCurrencyValue(currency: string, value: number): string { return new Intl.NumberFormat('ru-RU', { style: 'currency', currency: currency || 'RUB', maximumFractionDigits: 2, }).format(value); } function formatBrokerMoney(value: BrokerMoney | null | undefined): string { if (!value) { return '—'; } return formatBrokerCurrencyValue(value.currency, value.value); } function formatBrokerSignedCurrencyValue(currency: string, value: number | null): string { if (value === null) { return '—'; } const formatted = formatBrokerCurrencyValue(currency, Math.abs(value)); if (value > 0) { return `+${formatted}`; } if (value < 0) { return `−${formatted}`; } return formatted; } function formatBrokerSignedPercent(value: number | null): string { if (value === null) { return '—'; } const formatted = `${new Intl.NumberFormat('ru-RU', { maximumFractionDigits: 2, }).format(Math.abs(value))}%`; if (value > 0) { return `+${formatted}`; } if (value < 0) { return `−${formatted}`; } return formatted; } function formatBrokerDate(value: string | null | undefined): string | null { if (!value) { return null; } return new Date(value).toLocaleDateString('ru-RU'); } function brokerAccountTypeLabel(type: 'brokerage' | 'iis'): string { return type === 'iis' ? 'ИИС' : 'Брокерский счёт'; } function BrokerAccountCardSkeleton({ name, typeLabel }: { name: string; typeLabel: string }) { return (

{typeLabel}

{name}

{[1, 2, 3, 4].map((item) => (
))}
); } function BrokerAccountCardError({ account, onRetry, }: { account: BrokerAccount; onRetry: () => void; }) { return (

{brokerAccountTypeLabel(account.type)}

{account.name}

Не удалось загрузить данные счёта

); } function BrokerAccountCardSuccess({ account, portfolio, }: { account: BrokerAccount; portfolio: BrokerPortfolio; }) { const typeLabel = brokerAccountTypeLabel(account.type); const openedAt = formatBrokerDate(account.openedAt); const allocation = buildBrokerAllocation(portfolio); return (

{typeLabel}

{account.name}

{openedAt ?

Открыт {openedAt}

: null}
Стоимость {formatBrokerMoney(portfolio.totals.portfolio)}
За день {formatBrokerSignedCurrencyValue( portfolio.totals.portfolio?.currency ?? 'RUB', portfolio.yields.daily?.value ?? null, )}
Дневная динамика {formatBrokerSignedPercent(portfolio.yields.dailyPercent)}
Ожидаемая доходность {formatBrokerSignedPercent(portfolio.yields.expectedPercent)}
); } export function BrokerAccountCard({ account, portfolio, isLoading, error, onRetry, }: { account: BrokerAccount; portfolio?: BrokerPortfolio; isLoading: boolean; error: Error | null; onRetry: () => void; }) { if (isLoading && !portfolio) { return ( ); } if (error || !portfolio) { return ; } return ; }