refactor: enforce frontend view model boundaries
This commit is contained in:
@@ -22,7 +22,9 @@ const operationTransferPrefix = "OPERATION_TYPE_TRANS_";
|
||||
type PaymentPresentation = {
|
||||
amount: string;
|
||||
label: string;
|
||||
tone: "negative" | "neutral" | "positive";
|
||||
tone: "negative"
|
||||
| "neutral"
|
||||
| "positive";
|
||||
};
|
||||
|
||||
function entryLabelKey(operation: BrokerageOperation): string {
|
||||
@@ -30,6 +32,7 @@ function entryLabelKey(operation: BrokerageOperation): string {
|
||||
return isOperationType(operation.type, OperationType.Coupon)
|
||||
? "ledger.entryLabel.income.coupon"
|
||||
: "ledger.entryLabel.income.dividend";
|
||||
|
||||
return `ledger.category.${operation.category}`;
|
||||
}
|
||||
|
||||
@@ -43,19 +46,15 @@ function isZeroDecimal(value: string): boolean {
|
||||
|
||||
function operationLabelKey(type: string): string {
|
||||
if (
|
||||
[
|
||||
OperationType.Buy,
|
||||
OperationType.BuyCard,
|
||||
OperationType.BuyMargin,
|
||||
].some(candidate => isOperationType(type, candidate))
|
||||
[OperationType.Buy, OperationType.BuyCard, OperationType.BuyMargin].some(
|
||||
candidate => isOperationType(type, candidate),
|
||||
)
|
||||
)
|
||||
return "ledger.operationType.buy";
|
||||
if (
|
||||
[
|
||||
OperationType.Sell,
|
||||
OperationType.SellCard,
|
||||
OperationType.SellMargin,
|
||||
].some(candidate => isOperationType(type, candidate))
|
||||
[OperationType.Sell, OperationType.SellCard, OperationType.SellMargin].some(
|
||||
candidate => isOperationType(type, candidate),
|
||||
)
|
||||
)
|
||||
return "ledger.operationType.sell";
|
||||
if (
|
||||
@@ -72,7 +71,10 @@ function operationLabelKey(type: string): string {
|
||||
return "ledger.operationType.input";
|
||||
if (isOperationType(type, OperationType.OutputSecurities))
|
||||
return "ledger.operationType.output";
|
||||
return type.startsWith(operationTransferPrefix) ? "ledger.operationType.transfer" : "ledger.operationType.other";
|
||||
|
||||
return type.startsWith(operationTransferPrefix)
|
||||
? "ledger.operationType.transfer"
|
||||
: "ledger.operationType.other";
|
||||
}
|
||||
|
||||
function paymentPresentation(
|
||||
@@ -99,6 +101,7 @@ function paymentPresentation(
|
||||
label: entryLabelKey(operation),
|
||||
tone: "negative",
|
||||
};
|
||||
|
||||
return {
|
||||
amount: `+${formatMoney(operation.payment)}`,
|
||||
label: entryLabelKey(operation),
|
||||
|
||||
Reference in New Issue
Block a user