Sergey Krylov 1774c7ffd6
Some checks failed
CI / ci (pull_request) Failing after 2m32s
CI / ci (push) Failing after 2m17s
refactor(frontend): bring FSD architecture into compliance
- Remove cross-entity import (broker-position -> broker-operation)
- Extract duplicated formatters to shared/lib/formatters.ts
- Flatten shared/ui/broker-allocation-bar nesting
- Clean up entities/stock/index.ts public API

All 111 tests pass, build clean.
2026-06-20 22:43:44 +03:00

47 lines
1.4 KiB
TypeScript

import type { BrokerPosition } from '@/shared/api/responses';
export type BrokerPositionGroup = 'shares' | 'bonds' | 'other';
type BrokerInstrumentLinkInput = {
ticker: string | null;
instrumentType: string | null;
classCode: string | null;
};
const STOCK_CLASS_CODES = new Set(['TQBR']);
const BOND_CLASS_CODES = new Set(['TQOB', 'TQCB', 'TQIR']);
export function getBrokerPositionGroup(
position: Pick<BrokerPosition, 'instrumentType'>,
): BrokerPositionGroup {
const instrumentType = position.instrumentType?.toLowerCase();
if (instrumentType === 'share') return 'shares';
if (instrumentType === 'bond') return 'bonds';
return 'other';
}
export function getBrokerInstrumentPath(input: BrokerInstrumentLinkInput): string | null {
const ticker = input.ticker?.trim().toUpperCase();
if (!ticker) return null;
const instrumentType = input.instrumentType?.toLowerCase();
const classCode = input.classCode?.toUpperCase() ?? null;
if (instrumentType === 'share') {
return `/stocks/${encodeURIComponent(ticker)}`;
}
if (instrumentType === 'bond') {
return `/bonds/${encodeURIComponent(ticker)}`;
}
if (instrumentType) return null;
if (classCode && STOCK_CLASS_CODES.has(classCode)) return `/stocks/${encodeURIComponent(ticker)}`;
if (classCode && BOND_CLASS_CODES.has(classCode)) return `/bonds/${encodeURIComponent(ticker)}`;
return null;
}