From 629fb5ef6cb191c6d34ede6a2574dc5a183e06d1 Mon Sep 17 00:00:00 2001 From: Ronan-Yann Lorin Date: Sun, 21 Apr 2024 10:28:01 +0200 Subject: [PATCH] Bug fix --- .husky/pre-commit | 2 +- .../Portfolio/Statement/BaseStatement.tsx | 2 +- .../Portfolio/Statement/StatementEdit.tsx | 2 +- .../Portfolio/Statement/StatementsTable.tsx | 34 +++++++++++-------- src/models/index.ts | 1 - 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af219..d2ae35e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx lint-staged +yarn lint-staged diff --git a/src/app/components/Portfolio/Statement/BaseStatement.tsx b/src/app/components/Portfolio/Statement/BaseStatement.tsx index a9c93b6..16d1133 100644 --- a/src/app/components/Portfolio/Statement/BaseStatement.tsx +++ b/src/app/components/Portfolio/Statement/BaseStatement.tsx @@ -63,7 +63,7 @@ const BaseStatement = ({ portfolioId, statement }: Props): React.ReactNode => { {statement.fxRateToBase} - {statement.underlying && ( + {"underlying" in statement && ( Underlying: diff --git a/src/app/components/Portfolio/Statement/StatementEdit.tsx b/src/app/components/Portfolio/Statement/StatementEdit.tsx index 6b1b651..51b61a6 100644 --- a/src/app/components/Portfolio/Statement/StatementEdit.tsx +++ b/src/app/components/Portfolio/Statement/StatementEdit.tsx @@ -96,7 +96,7 @@ const StatementEdit: FunctionComponent = ({ ..._rest }): React.ReactNode {theStatement.fxRateToBase} - {theStatement.underlying && ( + {"underlying" in theStatement && ( Underlying: diff --git a/src/app/components/Portfolio/Statement/StatementsTable.tsx b/src/app/components/Portfolio/Statement/StatementsTable.tsx index 4baaccb..98a03e9 100644 --- a/src/app/components/Portfolio/Statement/StatementsTable.tsx +++ b/src/app/components/Portfolio/Statement/StatementsTable.tsx @@ -22,6 +22,7 @@ import { } from "@chakra-ui/react"; import { FunctionComponent, default as React } from "react"; import { Form, Link as RouterLink, useLoaderData, useParams } from "react-router-dom"; +import { StatementTypes } from "../../../../models/types"; import { StatementEntry } from "../../../../routers/statements.types"; import Number from "../../Number/Number"; import { ContractLink } from "../Contract/links"; @@ -39,9 +40,20 @@ const StatementsTable: FunctionComponent = ({ content, currency, title, . const { portfolioId } = useParams(); const theStatements = content || (useLoaderData() as StatementEntry[]); let previousId: number; + let totalFees = 0; - const savePrevious = (value: number): undefined => { - if (value) previousId = value; + const savePrevious = (item: StatementEntry): undefined => { + if (item.trade_id) previousId = item.trade_id; + switch (item.statementType) { + case StatementTypes.FeeStatement: + totalFees += item.amount * item.fxRateToBase; + break; + case StatementTypes.EquityStatement: + case StatementTypes.OptionStatement: + case StatementTypes.BondStatement: + totalFees += item.fees * item.fxRateToBase; + break; + } return undefined; }; @@ -88,11 +100,9 @@ const StatementsTable: FunctionComponent = ({ content, currency, title, . - - - + {"fees" in item && } - {item.underlying && ( + {"underlying" in item && ( {item.underlying.symbol} @@ -115,7 +125,7 @@ const StatementsTable: FunctionComponent = ({ content, currency, title, . )} - {item.underlying && !item.trade_id && ( + {"underlying" in item && !item.trade_id && ( <>
= ({ content, currency, title, . /> - {savePrevious(item.trade_id)} + {savePrevious(item)} ))} @@ -200,13 +210,7 @@ const StatementsTable: FunctionComponent = ({ content, currency, title, . /> - - (p += (item.fees || 0) * (currency ? (currency == item.currency ? 1 : 0) : item.fxRateToBase)), - 0, - )} - /> + diff --git a/src/models/index.ts b/src/models/index.ts index 6f4e3e8..2738d98 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -26,7 +26,6 @@ export * from "./portfolio.model"; export * from "./position.model"; export * from "./setting.model"; export * from "./statement.model"; -export * from "./statement.types"; export * from "./stock_contract.model"; export * from "./tax_statement.model"; export * from "./trade.model";