feat(broker-operation): show operation type label in ledger entries

This commit is contained in:
2026-08-27 11:33:25 +03:00
parent 695cda0456
commit d53ce50e28
4 changed files with 91 additions and 20 deletions
@@ -16,10 +16,18 @@ type LedgerEntryRowProps = {
type PaymentPresentation = {
amount: string;
direction: "incoming" | "outgoing" | "neutral";
label: string;
tone: "positive" | "negative" | "neutral";
};
function entryLabelKey(operation: BrokerageOperation): string {
if (operation.category === "income")
return operation.type === "OPERATION_TYPE_COUPON"
? "ledger.entryLabel.income.coupon"
: "ledger.entryLabel.income.dividend";
return `ledger.category.${operation.category}`;
}
const LedgerEntryRow: FC<LedgerEntryRowProps> = (props) => {
const { operation } = props;
const { t } = useTranslation();
@@ -28,11 +36,9 @@ const LedgerEntryRow: FC<LedgerEntryRowProps> = (props) => {
operation.ticker ?? operation.instrumentType ?? t("ledger.noInstrument");
const logoSrc = imageFailed ? null : instrumentLogoUrl(operation.logoName);
const payment = paymentPresentation(operation);
const metadata = [
formatSnapshotTime(operation.occurredAt),
instrument,
t(`ledger.category.${operation.category}`),
].join(" · ");
const metadata = [formatSnapshotTime(operation.occurredAt), instrument].join(
" · ",
);
return (
<Paper className={classes.row} withBorder>
@@ -59,7 +65,7 @@ const LedgerEntryRow: FC<LedgerEntryRowProps> = (props) => {
{payment.amount}
</Text>
<Text className={classes[payment.tone]} size="sm">
{t(`ledger.direction.${payment.direction}`)}
{t(payment.label)}
</Text>
</Stack>
</Paper>
@@ -70,11 +76,15 @@ function paymentPresentation(
operation: BrokerageOperation,
): PaymentPresentation {
if (!operation.payment)
return { amount: "—", direction: "neutral", tone: "neutral" };
return {
amount: "—",
label: "ledger.noMoney",
tone: "neutral",
};
if (isZeroDecimal(operation.payment.value))
return {
amount: formatMoney(operation.payment),
direction: "neutral",
label: "ledger.noMoney",
tone: "neutral",
};
if (operation.payment.value.startsWith("-"))
@@ -83,12 +93,12 @@ function paymentPresentation(
...operation.payment,
value: operation.payment.value.slice(1),
})}`,
direction: "outgoing",
label: entryLabelKey(operation),
tone: "negative",
};
return {
amount: `+${formatMoney(operation.payment)}`,
direction: "incoming",
label: entryLabelKey(operation),
tone: "positive",
};
}