Skip to content

Commit 401583e

Browse files
committed
feat(holding-detail): show current shares badge next to price
1 parent d567081 commit 401583e

2 files changed

Lines changed: 46 additions & 35 deletions

File tree

src/app/dashboard/net-worth/assets/[assetId]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default function AssetDetailPage() {
8080
tickerExchange={data?.ticker?.exchange}
8181
isPending={isPending || isPendingQuantities}
8282
holdingComputedValue={data?.computedValue}
83+
quantity={data?.latestQuantity?.quantity}
8384
holdingName={data?.name}
8485
type="asset"
8586
onQuantityEdit={handleQuantityEdit}

src/components/holdingDetail/holding-detail.tsx

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
import { Separator } from "~/components/ui/separator";
1010
import { SidebarTrigger } from "~/components/ui/sidebar";
1111
import { TableSkeleton } from "~/components/table-skeleton";
12-
import { Currency, RoundedCurrency } from "~/components/ui/number";
12+
import {
13+
Currency,
14+
RoundedCurrency,
15+
RoundedNumber,
16+
} from "~/components/ui/number";
1317
import type Decimal from "decimal.js";
1418
import { Button } from "../ui/button";
1519
import { PlusIcon } from "lucide-react";
@@ -18,6 +22,7 @@ import { holdingDetailColumn } from "./config";
1822
import { DataTable } from "../ui/data-table";
1923
import { DataTableColumns } from "../ui/data-table-columns";
2024
import { useTable } from "~/hooks/useTable";
25+
import { Badge } from "../ui/badge";
2126

2227
export type ValueHistoryRow = {
2328
timestamp: Date;
@@ -45,6 +50,7 @@ export function HoldingDetail({
4550
tickerName,
4651
valueHistory = [],
4752
type,
53+
quantity,
4854
onQuantityEdit,
4955
onQuantityDelete,
5056
onNewHolding,
@@ -60,6 +66,7 @@ export function HoldingDetail({
6066
latestStockPrice?: Decimal;
6167
valueHistory?: ValueHistoryRow[];
6268
type: "asset" | "debt";
69+
quantity?: Decimal;
6370
onQuantityEdit: (args: { id: string }) => void;
6471
onQuantityDelete: (args: { timestamp: Date }) => void;
6572
onNewHolding: () => void;
@@ -118,9 +125,17 @@ export function HoldingDetail({
118125
<div className="flex flex-col gap-2 md:flex-row">
119126
<div className="mr-auto">
120127
<p className="text-sm text-muted-foreground">{holdingName}</p>
121-
<p className="text-3xl font-semibold">
122-
<RoundedCurrency value={holdingComputedValue} />
123-
</p>
128+
<div className="flex items-center gap-2">
129+
<p className="text-3xl font-semibold">
130+
<RoundedCurrency value={holdingComputedValue} />
131+
</p>
132+
{isCategoryStock && (
133+
<Badge variant="secondary">
134+
<RoundedNumber value={quantity} />
135+
&nbsp;shares
136+
</Badge>
137+
)}
138+
</div>
124139
</div>
125140

126141
<DataTableColumns table={table} />
@@ -131,14 +146,15 @@ export function HoldingDetail({
131146
</Button>
132147
</div>
133148

134-
<Overview
135-
holdingCurrency={holdingCurrency}
136-
isCategoryStock={isCategoryStock}
137-
latestStockPrice={latestStockPrice}
138-
ticker={ticker}
139-
tickerName={tickerName}
140-
tickerExchange={tickerExchange}
141-
/>
149+
{isCategoryStock && (
150+
<Overview
151+
holdingCurrency={holdingCurrency}
152+
latestStockPrice={latestStockPrice}
153+
ticker={ticker}
154+
tickerName={tickerName}
155+
tickerExchange={tickerExchange}
156+
/>
157+
)}
142158

143159
<DataTable table={table} />
144160
</div>
@@ -152,38 +168,32 @@ export function Overview({
152168
ticker,
153169
tickerName,
154170
tickerExchange,
155-
isCategoryStock,
156171
holdingCurrency,
157172
latestStockPrice,
158173
}: {
159174
holdingCurrency?: string;
160175
tickerName?: string;
161176
ticker?: string;
162177
tickerExchange?: string;
163-
isCategoryStock?: boolean;
164178
latestStockPrice?: Decimal;
165179
}) {
166180
return (
167-
<>
168-
{isCategoryStock && (
169-
<div className="flex items-center justify-between rounded-lg border p-5 text-sm">
170-
<div>
171-
<p>{tickerName}</p>
172-
<p className="text-muted-foreground">
173-
{ticker} &middot; {tickerExchange}
174-
</p>
175-
</div>
176-
<p>
177-
<Currency
178-
value={latestStockPrice}
179-
options={{
180-
currency: holdingCurrency,
181-
maximumFractionDigits: 2,
182-
}}
183-
/>
184-
</p>
185-
</div>
186-
)}
187-
</>
181+
<div className="flex items-center justify-between rounded-lg border p-5 text-sm">
182+
<div>
183+
<p>{tickerName}</p>
184+
<p className="text-muted-foreground">
185+
{ticker} &middot; {tickerExchange}
186+
</p>
187+
</div>
188+
<p>
189+
<Currency
190+
value={latestStockPrice}
191+
options={{
192+
currency: holdingCurrency,
193+
maximumFractionDigits: 2,
194+
}}
195+
/>
196+
</p>
197+
</div>
188198
);
189199
}

0 commit comments

Comments
 (0)