refactor: enforce frontend view model boundaries
Frontend verify / commits (pull_request) Successful in 28s
Frontend verify / security (pull_request) Successful in 10s
Frontend verify / verify (pull_request) Successful in 8m19s

This commit is contained in:
2026-09-28 18:48:23 +03:00
parent 5b69003516
commit ca0ad4f824
287 changed files with 8558 additions and 4538 deletions
@@ -0,0 +1,64 @@
import { useTranslation } from "react-i18next";
import { formatChartValue, formatDecimal, formatMoney } from "@/shared/lib";
import type { InstrumentChartVm } from "../../model/types";
type InstrumentChartProps = { priceUnit?: "percent"; vm: InstrumentChartVm };
function useInstrumentChartVm(props: InstrumentChartProps) {
const { vm } = props;
const { t } = useTranslation();
const priceRows = vm.priceRows.map((candle) => {
const currency = vm.candles?.currency;
const value = candle.close;
const amount = currency ? { currency, value } : undefined;
const price = props.priceUnit === "percent"
? `${formatDecimal(value)} %`
: formatMoney(amount);
return { ...candle, price };
});
const periodOptions = ["month", "halfYear", "year", "all"].map(value => ({
label: t(`stock.periods.${value}`),
value,
}));
const chartLabel = t(
props.priceUnit === "percent" ? "bond.chartLabel" : "stock.chartLabel",
{
currency:
props.priceUnit === "percent"
? t("bond.percentOfNominal")
: (vm.candles?.currency ?? ""),
},
);
const referenceLines
= vm.averageLine === null
? []
: [
{
color: "orange.7",
ifOverflow: "extendDomain" as const,
label: t("stock.averageLine"),
y: vm.averageLine,
},
];
return {
chartLabel,
formatChartValue,
periodOptions,
priceRows,
referenceLines,
t,
vm,
};
}
export { useInstrumentChartVm };