fix: keep position card stories off the account model data imports (#112)
This commit is contained in:
@@ -93,6 +93,7 @@ describe("account position sections", () => {
|
||||
displayName: "Акция",
|
||||
logoSrc: "https://invest-brands.cdn-tinkoff.ru/akciyax160.png",
|
||||
returnPercent: null,
|
||||
returnPercentText: null,
|
||||
returnText: "+10 ₽",
|
||||
returnTone: "positive",
|
||||
shareText: "66,7 %",
|
||||
@@ -107,6 +108,7 @@ describe("account position sections", () => {
|
||||
displayName: "Облигация",
|
||||
logoSrc: null,
|
||||
returnPercent: "-11.111111",
|
||||
returnPercentText: "-11,11 %",
|
||||
returnText: "-5 ₽",
|
||||
returnTone: "negative",
|
||||
shareText: "33,3 %",
|
||||
@@ -120,6 +122,7 @@ describe("account position sections", () => {
|
||||
displayName: "Фонд",
|
||||
logoSrc: null,
|
||||
returnPercent: null,
|
||||
returnPercentText: null,
|
||||
returnText: null,
|
||||
returnTone: undefined,
|
||||
shareText: null,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { formatShare, type Portfolio } from "@/entities/portfolio";
|
||||
import { formatMoney, instrumentLogoUrl } from "@/shared/lib";
|
||||
import { formatDecimal, formatMoney, instrumentLogoUrl } from "@/shared/lib";
|
||||
|
||||
type AccountPagePosition = Portfolio["positions"][number] & {
|
||||
instrumentTo?: string;
|
||||
logoSrc: null | string;
|
||||
returnPercent: null | string;
|
||||
returnPercentText: null | string;
|
||||
returnText: null | string;
|
||||
returnTone?: AccountPageReturnTone;
|
||||
shareText: null | string;
|
||||
@@ -222,6 +223,8 @@ function toPosition(
|
||||
const returnPrefix
|
||||
= isExpanded && returnValue !== null && returnValue > 0 ? "+" : "";
|
||||
|
||||
const percent = returnPercent(position);
|
||||
|
||||
return {
|
||||
...position,
|
||||
instrumentTo:
|
||||
@@ -231,7 +234,10 @@ function toPosition(
|
||||
logoSrc: isExpanded
|
||||
? instrumentLogoUrl(position.logoName)
|
||||
: null,
|
||||
returnPercent: returnPercent(position),
|
||||
returnPercent: percent,
|
||||
returnPercentText: percent
|
||||
? `${formatDecimal(formatPositionReturnPercent(percent))} %`
|
||||
: null,
|
||||
returnText: position.absoluteReturn
|
||||
? `${returnPrefix}${formatMoney(position.absoluteReturn)}`
|
||||
: null,
|
||||
|
||||
@@ -16,6 +16,7 @@ const syntheticPosition
|
||||
logoSrc: null,
|
||||
quantity: "100",
|
||||
returnPercent: "25",
|
||||
returnPercentText: "+25,00 %",
|
||||
returnText: "+5 000 ₽",
|
||||
returnTone: "positive",
|
||||
shareText: "20%",
|
||||
@@ -75,6 +76,7 @@ export const BondLoss: Story
|
||||
isin: "DEMO-BOND-2030",
|
||||
quantity: "10",
|
||||
returnPercent: "-5",
|
||||
returnPercentText: "-5,00 %",
|
||||
returnText: "−500 ₽",
|
||||
returnTone: "negative",
|
||||
shareText: "7,6%",
|
||||
@@ -126,6 +128,7 @@ export const MissingValuation: Story
|
||||
currentValue: null,
|
||||
displayName: "Учебная позиция без текущей оценки",
|
||||
returnPercent: null,
|
||||
returnPercentText: null,
|
||||
returnText: null,
|
||||
returnTone: undefined,
|
||||
shareText: null,
|
||||
|
||||
@@ -4,13 +4,13 @@ import { Anchor, Card, Group, Stack, Text } from "@mantine/core";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { formatDecimal, formatMoney } from "@/shared/lib";
|
||||
import { formatMoney } from "@/shared/lib";
|
||||
|
||||
import {
|
||||
type AccountPagePosition,
|
||||
type AccountPagePositionSection,
|
||||
formatPositionReturnPercent,
|
||||
import type {
|
||||
AccountPagePosition,
|
||||
AccountPagePositionSection,
|
||||
} from "../../../../model/positions";
|
||||
|
||||
import classes from "../../AccountPage.module.css";
|
||||
import { PositionLogo } from "../PositionLogo.view";
|
||||
|
||||
@@ -30,8 +30,8 @@ const PositionCard: FC<PositionCardProps> = (props) => {
|
||||
|
||||
let returnText = position.returnText;
|
||||
|
||||
if (returnText && position.returnPercent) {
|
||||
returnText += ` · ${formatDecimal(formatPositionReturnPercent(position.returnPercent))} %`;
|
||||
if (returnText && position.returnPercentText) {
|
||||
returnText += ` · ${position.returnPercentText}`;
|
||||
}
|
||||
|
||||
if (returnText && !isExpanded) {
|
||||
|
||||
@@ -4,13 +4,13 @@ import { Anchor, Card, Group, Stack, Text } from "@mantine/core";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { formatDecimal, formatMoney } from "@/shared/lib";
|
||||
import { formatMoney } from "@/shared/lib";
|
||||
|
||||
import {
|
||||
type AccountPagePositionGroup,
|
||||
type AccountPagePositionSection,
|
||||
formatPositionReturnPercent,
|
||||
import type {
|
||||
AccountPagePositionGroup,
|
||||
AccountPagePositionSection,
|
||||
} from "../../../model/positions";
|
||||
|
||||
import classes from "../AccountPage.module.css";
|
||||
import { PositionLogo } from "./PositionLogo.view";
|
||||
|
||||
@@ -63,8 +63,8 @@ const PositionGroupCard: FC<PositionGroupCardProps> = (props) => {
|
||||
? classes[position.returnTone]
|
||||
: undefined;
|
||||
|
||||
const returnPercent = position.returnPercent
|
||||
? ` · ${formatDecimal(formatPositionReturnPercent(position.returnPercent))} %`
|
||||
const returnPercent = position.returnPercentText
|
||||
? ` · ${position.returnPercentText}`
|
||||
: "";
|
||||
|
||||
const returnValue = `${position.returnText ?? ""}${returnPercent}`;
|
||||
|
||||
@@ -41,6 +41,7 @@ it("keeps expanded positions vertical while other positions adapt to the viewpor
|
||||
logoSrc: null,
|
||||
quantity: "10",
|
||||
returnPercent: null,
|
||||
returnPercentText: null,
|
||||
returnText: null,
|
||||
shareText: null,
|
||||
ticker: null,
|
||||
|
||||
Reference in New Issue
Block a user