Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Apr 21, 2024
1 parent 5ed05b5 commit 629fb5e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
yarn lint-staged
2 changes: 1 addition & 1 deletion src/app/components/Portfolio/Statement/BaseStatement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const BaseStatement = ({ portfolioId, statement }: Props): React.ReactNode => {
{statement.fxRateToBase}
</Text>
</Flex>
{statement.underlying && (
{"underlying" in statement && (
<Flex justifyContent="center" gap="2">
<Text w="110px" as="b" textAlign="right">
Underlying:
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Portfolio/Statement/StatementEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const StatementEdit: FunctionComponent<Props> = ({ ..._rest }): React.ReactNode
{theStatement.fxRateToBase}
</Text>
</Flex>
{theStatement.underlying && (
{"underlying" in theStatement && (
<Flex justifyContent="center" gap="2">
<Text w="90px" as="b" textAlign="right">
Underlying:
Expand Down
34 changes: 19 additions & 15 deletions src/app/components/Portfolio/Statement/StatementsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -39,9 +40,20 @@ const StatementsTable: FunctionComponent<Props> = ({ 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;
};

Expand Down Expand Up @@ -88,11 +100,9 @@ const StatementsTable: FunctionComponent<Props> = ({ content, currency, title, .
<Td isNumeric>
<Number value={"pnl" in item ? item.pnl : 0} decimals={2} />
</Td>
<Td isNumeric>
<Number value={item.fees} decimals={2} />
</Td>
<Td isNumeric>{"fees" in item && <Number value={item.fees} decimals={2} />}</Td>
<Td>
{item.underlying && (
{"underlying" in item && (
<Link to={ContractLink.toItem(portfolioId, item.underlying.id)} as={RouterLink}>
{item.underlying.symbol}
</Link>
Expand All @@ -115,7 +125,7 @@ const StatementsTable: FunctionComponent<Props> = ({ content, currency, title, .
</Form>
</>
)}
{item.underlying && !item.trade_id && (
{"underlying" in item && !item.trade_id && (
<>
<Form method="post" action={`StatementCreateTrade/${item.id}`} className="inline">
<IconButton
Expand Down Expand Up @@ -171,7 +181,7 @@ const StatementsTable: FunctionComponent<Props> = ({ content, currency, title, .
/>
</Form>
</Td>
{savePrevious(item.trade_id)}
{savePrevious(item)}
</Tr>
))}
</Tbody>
Expand Down Expand Up @@ -200,13 +210,7 @@ const StatementsTable: FunctionComponent<Props> = ({ content, currency, title, .
/>
</Td>
<Td isNumeric>
<Number
value={theStatements.reduce(
(p: number, item) =>
(p += (item.fees || 0) * (currency ? (currency == item.currency ? 1 : 0) : item.fxRateToBase)),
0,
)}
/>
<Number value={totalFees} />
</Td>
<Td></Td>
<Td></Td>
Expand Down
1 change: 0 additions & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 629fb5e

Please sign in to comment.