Skip to content

Commit d0b1f54

Browse files
committed
filing stocks fix
1 parent 09949cb commit d0b1f54

File tree

3 files changed

+151
-126
lines changed

3 files changed

+151
-126
lines changed

frontend/components/Explorer/Timeline/Select/Picker/Picker.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Picker = (props) => {
2222
].join(" ")}
2323
>
2424
<div className={styles["picker-filings"]}>
25-
{filings.map((filing) => {
25+
{filings.map((filing, i) => {
2626
const accessNumber = filing.access_number;
2727
const reportDate = new Date(
2828
filing.report_date * 1000
@@ -60,7 +60,14 @@ const Picker = (props) => {
6060
];
6161
return (
6262
<div
63-
key={accessNumber}
63+
key={[
64+
i,
65+
accessNumber,
66+
selected.type,
67+
reportDate,
68+
filingDate,
69+
marketValue,
70+
].join("-")}
6471
className={[styles["picker-filing"], fontLight.className].join(
6572
" "
6673
)}

frontend/components/Hooks/useFilingStocks.jsx

Lines changed: 135 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,125 +5,141 @@ import useSWR from "swr";
55
// Advantage is that things can be translated client-side
66

77
function serializeLocalToGlobal(localStock) {
8-
const {
9-
name,
10-
cusip,
11-
ticker,
12-
sector,
13-
industry,
14-
class: rights,
15-
shares_held,
16-
shares_held_str,
17-
market_value,
18-
market_value_str,
19-
sold,
20-
update,
21-
ratios,
22-
changes,
23-
records,
24-
prices,
25-
report_time = "N/A",
26-
recent_price = "N/A",
27-
} = localStock;
28-
29-
const {
30-
portfolio_percent: portfolio_percentage,
31-
portfolio_str: portfolio_percentage_str,
32-
ownership_percent: ownership_percentage,
33-
ownership_str: ownership_percentage_str,
34-
} = ratios;
35-
36-
const { value: value_changes, shares: share_changes } = changes;
37-
38-
const { amount: value_amount, action: value_action } = value_changes;
39-
const { amount: share_amount, action: share_action } = share_changes;
40-
41-
const { buy: buy_price, sold: sold_price } = prices;
42-
43-
const {
44-
time: buy_time,
45-
time_str: buy_time_str,
46-
series: buy_series,
47-
} = buy_price;
48-
49-
const value_bought = value_action === "buy" ? Math.abs(value_amount) : 0;
50-
const value_sold = value_action === "sell" ? Math.abs(value_amount) : 0;
51-
const shares_bought = share_action === "buy" ? Math.abs(share_amount) : 0;
52-
const shares_sold = share_action === "sell" ? Math.abs(share_amount) : 0;
53-
54-
const value_bought_str = value_bought.toFixed(2);
55-
const value_sold_str = value_sold.toFixed(2);
56-
const shares_bought_str = shares_bought.toFixed(2);
57-
const shares_sold_str = shares_sold.toFixed(2);
58-
59-
const sold_time = sold_price ? sold_price.time : "N/A";
60-
const sold_time_str = sold_price ? sold_price.time_str : "N/A";
61-
const sold_series = sold_price ? sold_price.series : "N/A";
62-
63-
const report_date =
64-
report_time !== "N/A" ? new Date(report_time * 1000) : "N/A";
65-
const report_date_str =
66-
report_time !== "N/A"
67-
? `Q${
68-
Math.floor(report_date.getMonth() / 3) + 1
69-
} ${report_date.getFullYear()}`
70-
: "N/A";
71-
72-
const price_bought = buy_series !== "N/A" ? buy_series.close : "N/A";
73-
const price_bought_str = buy_series !== "N/A" ? `$${price_bought}` : "N/A";
74-
75-
const price_sold = sold_series !== "N/A" ? sold_series.close : "N/A";
76-
const price_sold_str = sold_series !== "N/A" ? `$${price_sold}` : "N/A";
77-
78-
const recent_price_str = recent_price !== "N/A" ? `$${recent_price}` : "N/A";
79-
80-
const gain_value =
81-
recent_price !== "N/A" && price_bought !== "N/A"
82-
? parseFloat(recent_price - price_bought)
83-
: "N/A";
84-
const gain_percent =
85-
gain_value !== "N/A" && price_bought !== "N/A"
86-
? parseFloat((gain_value / price_bought) * 100)
87-
: "N/A";
88-
const gain_value_str = gain_value !== "N/A" ? gain_value.toFixed(2) : "N/A";
89-
const gain_percent_str =
90-
gain_percent !== "N/A" ? gain_percent.toFixed(2) : "N/A";
91-
92-
return {
93-
name,
94-
cusip,
95-
ticker,
96-
sector,
97-
industry,
98-
class: rights,
99-
update,
100-
sold,
101-
recent_price,
102-
recent_price_str,
103-
buy_price: price_bought,
104-
buy_price_str: price_bought_str,
105-
sold_price: price_sold,
106-
sold_price_str: price_sold_str,
107-
shares_held,
108-
shares_held_str,
109-
market_value,
110-
market_value_str,
111-
112-
portfolio_percent: portfolio_percentage,
113-
portfolio_str: portfolio_percentage_str,
114-
ownership_percent: ownership_percentage,
115-
ownership_str: ownership_percentage_str,
116-
gain_value,
117-
gain_value_str,
118-
gain_percent,
119-
gain_str: gain_percent_str,
120-
report_time,
121-
report_str: report_date_str,
122-
buy_time,
123-
buy_str: buy_time_str,
124-
sold_time,
125-
sold_str: sold_time_str,
126-
};
8+
try {
9+
const {
10+
name = "N/A",
11+
cusip = "N/A",
12+
ticker = "N/A",
13+
sector = "N/A",
14+
industry = "N/A",
15+
class: rights = "N/A",
16+
shares_held = "N/A",
17+
shares_held_str = "N/A",
18+
market_value = "N/A",
19+
market_value_str = "N/A",
20+
sold = false,
21+
update = false,
22+
ratios = {
23+
portfolio_percent: "N/A",
24+
portfolio_str: "N/A",
25+
ownership_percent: "N/A",
26+
ownership_str: "N/A",
27+
},
28+
changes = {
29+
value: { amount: "N/A", action: "N/A" },
30+
shares: { amount: "N/A", action: "N/A" },
31+
},
32+
records = {},
33+
prices = {
34+
buy: { time: "N/A", time_str: "N/A", series: "N/A" },
35+
sold: { time: "N/A", time_str: "N/A", series: "N/A" },
36+
},
37+
report_time = "N/A",
38+
recent_price = "N/A",
39+
} = localStock;
40+
41+
const {
42+
portfolio_percent: portfolio_percentage,
43+
portfolio_str: portfolio_percentage_str,
44+
ownership_percent: ownership_percentage,
45+
ownership_str: ownership_percentage_str,
46+
} = ratios;
47+
48+
const { value: value_changes, shares: share_changes } = changes;
49+
50+
const { amount: value_amount, action: value_action } = value_changes;
51+
const { amount: share_amount, action: share_action } = share_changes;
52+
53+
const { buy: buy_price, sold: sold_price } = prices;
54+
55+
const {
56+
time: buy_time,
57+
time_str: buy_time_str,
58+
series: buy_series,
59+
} = buy_price;
60+
61+
const value_bought = value_action === "buy" ? Math.abs(value_amount) : 0;
62+
const value_sold = value_action === "sell" ? Math.abs(value_amount) : 0;
63+
const shares_bought = share_action === "buy" ? Math.abs(share_amount) : 0;
64+
const shares_sold = share_action === "sell" ? Math.abs(share_amount) : 0;
65+
66+
const value_bought_str = value_bought.toFixed(2);
67+
const value_sold_str = value_sold.toFixed(2);
68+
const shares_bought_str = shares_bought.toFixed(2);
69+
const shares_sold_str = shares_sold.toFixed(2);
70+
71+
const sold_time = sold_price ? sold_price.time : "N/A";
72+
const sold_time_str = sold_price ? sold_price.time_str : "N/A";
73+
const sold_series = sold_price ? sold_price.series : "N/A";
74+
75+
const report_date =
76+
report_time !== "N/A" ? new Date(report_time * 1000) : "N/A";
77+
const report_date_str =
78+
report_time !== "N/A"
79+
? `Q${
80+
Math.floor(report_date.getMonth() / 3) + 1
81+
} ${report_date.getFullYear()}`
82+
: "N/A";
83+
84+
const price_bought = buy_series !== "N/A" ? buy_series.close : "N/A";
85+
const price_bought_str = buy_series !== "N/A" ? `$${price_bought}` : "N/A";
86+
87+
const price_sold = sold_series !== "N/A" ? sold_series.close : "N/A";
88+
const price_sold_str = sold_series !== "N/A" ? `$${price_sold}` : "N/A";
89+
90+
const recent_price_str =
91+
recent_price !== "N/A" ? `$${recent_price}` : "N/A";
92+
93+
const gain_value =
94+
recent_price !== "N/A" && price_bought !== "N/A"
95+
? parseFloat(recent_price - price_bought)
96+
: "N/A";
97+
const gain_percent =
98+
gain_value !== "N/A" && price_bought !== "N/A"
99+
? parseFloat((gain_value / price_bought) * 100)
100+
: "N/A";
101+
const gain_value_str = gain_value !== "N/A" ? gain_value.toFixed(2) : "N/A";
102+
const gain_percent_str =
103+
gain_percent !== "N/A" ? gain_percent.toFixed(2) : "N/A";
104+
105+
return {
106+
name,
107+
cusip,
108+
ticker,
109+
sector,
110+
industry,
111+
class: rights,
112+
update,
113+
sold,
114+
recent_price,
115+
recent_price_str,
116+
buy_price: price_bought,
117+
buy_price_str: price_bought_str,
118+
sold_price: price_sold,
119+
sold_price_str: price_sold_str,
120+
shares_held,
121+
shares_held_str,
122+
market_value,
123+
market_value_str,
124+
portfolio_percent: portfolio_percentage,
125+
portfolio_str: portfolio_percentage_str,
126+
ownership_percent: ownership_percentage,
127+
ownership_str: ownership_percentage_str,
128+
gain_value,
129+
gain_value_str,
130+
gain_percent,
131+
gain_str: gain_percent_str,
132+
report_time,
133+
report_str: report_date_str,
134+
buy_time,
135+
buy_str: buy_time_str,
136+
sold_time,
137+
sold_str: sold_time_str,
138+
};
139+
} catch (e) {
140+
console.error(e);
141+
return localStock;
142+
}
127143
}
128144

129145
const server = process.env.NEXT_PUBLIC_SERVER;

frontend/components/Index/Filing/Explorer/Index.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ import { cn } from "components/ui/utils";
55
import { useDispatch, useSelector } from "react-redux";
66
import {
77
selectCik,
8-
selectBuy,
9-
selectSell,
8+
selectPrimary,
9+
selectSecondary,
1010
editComparison,
1111
editSort,
1212
setFilingCount,
13-
} from "@/redux/filerSlice";
13+
} from "redux/filerSlice";
1414

1515
import useFilingStocks from "components/Hooks/useFilingStocks";
1616
import Table from "components/Table/Table";
1717

1818
export default function Index(props) {
1919
const dispatch = useDispatch();
2020
const cik = useSelector(selectCik);
21-
const order = props.order || "buy";
22-
const selected = useSelector(order === "buy" ? selectBuy : selectSell);
21+
const order = props.order || "primary";
22+
const selected = useSelector(
23+
order === "secondary" ? selectSecondary : selectPrimary
24+
);
2325

2426
const {
2527
items,

0 commit comments

Comments
 (0)