refactor: align frontend ownership boundaries
Close audit gaps across API drift, query policy, UI, and tests.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { formatMoney } from "@/shared/lib";
|
||||
import type { BrokerageOperation } from "../api/useBrokerageOperations";
|
||||
|
||||
type PaymentPresentation = {
|
||||
amount: string;
|
||||
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}`;
|
||||
}
|
||||
|
||||
function paymentPresentation(
|
||||
operation: BrokerageOperation,
|
||||
): PaymentPresentation {
|
||||
if (!operation.payment)
|
||||
return {
|
||||
amount: "—",
|
||||
label: "ledger.noMoney",
|
||||
tone: "neutral",
|
||||
};
|
||||
if (isZeroDecimal(operation.payment.value))
|
||||
return {
|
||||
amount: formatMoney(operation.payment),
|
||||
label: "ledger.noMoney",
|
||||
tone: "neutral",
|
||||
};
|
||||
if (operation.payment.value.startsWith("-"))
|
||||
return {
|
||||
amount: `−${formatMoney({
|
||||
...operation.payment,
|
||||
value: operation.payment.value.slice(1),
|
||||
})}`,
|
||||
label: entryLabelKey(operation),
|
||||
tone: "negative",
|
||||
};
|
||||
return {
|
||||
amount: `+${formatMoney(operation.payment)}`,
|
||||
label: entryLabelKey(operation),
|
||||
tone: "positive",
|
||||
};
|
||||
}
|
||||
|
||||
function isZeroDecimal(value: string): boolean {
|
||||
return /^-?0(?:\.0+)?$/.test(value);
|
||||
}
|
||||
|
||||
export { paymentPresentation };
|
||||
Reference in New Issue
Block a user