Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Repository rules

## Before you push

The landing site in `site/` imports the real app UI and types from `src/` and `server/`
(see `.github/workflows/site.yml`). A change to a shared type, a prop, or a copy key can break
the site even when the app is green, so run both sets of checks before pushing:

```sh
# app
vp check && pnpm test && pnpm build

# site (separate lockfile, install first in a fresh worktree)
cd site && pnpm install --frozen-lockfile && pnpm typecheck && pnpm build
```

- Adding a required field to a type from `src/lib/**/*.types.ts` (for example `Dashboard`,
`ItemView`): grep `site/src/mock/` for the type and update every mock that builds it.
- Don't skip `pnpm typecheck` in `site/` because the change looks app-only. That is exactly
how the site CI fails.
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
15 changes: 15 additions & 0 deletions server/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,18 @@ test("an account that starts reporting later adds to the total from then on", ()
[10, 10, 100],
);
});

test("charm value is reported on its own and never added to the total", () => {
const charm = { name: "Charm", imageUrl: null, pattern: null, videoUrl: null };
const dash = build([
item("a", { charms: [{ ...charm, marketHashName: "Charm | A", price: 4 }] }),
item("b", {
charms: [
{ ...charm, marketHashName: "Charm | B", price: 1.5 },
{ ...charm, marketHashName: "Charm | C", price: null },
],
}),
]);
assert.equal(dash.totals.charmsValue, 5.5);
assert.equal(dash.totals.value, 20);
});
3 changes: 3 additions & 0 deletions server/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ValueChange,
} from "../src/lib/items/dashboard.types.ts";
import { itemRowKey } from "../src/lib/items/item-key.ts";
import { attachedCharmsValue } from "../src/lib/items/charm-value.ts";
import { INVENTORY_LOCATION_ID, type ItemView } from "../src/lib/items/item.types.ts";
import { DASHBOARD } from "../src/lib/storage/storage.config.ts";
import type { ValueSnapshot } from "./db/db.types.ts";
Expand Down Expand Up @@ -72,6 +73,7 @@ export function buildDashboard(args: {
const { items, history, currency, priceUpdatedAt, unitsLoaded, unitsTotal } = args;
const now = args.now ?? Date.now();
const { inventoryValue, storageValue, totalValue } = summarizeValue(items);
const charmsValue = items.reduce((sum, item) => sum + (attachedCharmsValue(item) ?? 0), 0);

const category = new Map<string, { value: number; count: number; color?: string }>();
const rarity = new Map<string, { value: number; count: number; color?: string }>();
Expand Down Expand Up @@ -153,6 +155,7 @@ export function buildDashboard(args: {
itemCount: items.length,
inventoryValue,
storageValue,
charmsValue,
unitsLoaded,
unitsTotal,
},
Expand Down
1 change: 1 addition & 0 deletions site/src/mock/data/dashboard.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const DASHBOARD_MOCK: Dashboard = {
itemCount: 1675,
inventoryValue: INVENTORY,
storageValue: STORAGE,
charmsValue: 184.3,
unitsLoaded: 4,
unitsTotal: 4,
},
Expand Down
8 changes: 8 additions & 0 deletions src/components/item-grid-card/item-grid-card.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "~/components/item-highlights/item-highlights.component";
import { splitItemName } from "~/components/item-label/item-label.utils";
import { charmTooltipDetail } from "~/lib/items/charm-tooltip";
import { attachedCharmsValue } from "~/lib/items/charm-value";
import { COPY } from "~/lib/copy/copy.config";
import { cn } from "~/utils/cn";
import { formatFloat, formatMoney } from "~/utils/format";
Expand Down Expand Up @@ -40,6 +41,7 @@ export function ItemGridCard({
const stickers = item.stickers.filter((sticker) => sticker.imageUrl !== null);
const hiddenStickers = stickers.length - maxStickers;
const hasAttachments = stickers.length > 0 || item.charms.length > 0;
const charmsValue = attachedCharmsValue(item);
const charmVideos = item.charms.filter((charm) => charm.videoUrl !== null);
const hasChips = charmVideos.length > 0 || item.videoUrl !== null;
const hasFooter = hasAttachments || hasChips || showLocation;
Expand Down Expand Up @@ -100,6 +102,12 @@ export function ItemGridCard({
<p className={classes.price}>
{item.price === null ? COPY.common.empty : formatMoney(item.price, currency)}
</p>
{charmsValue !== null && (
<p className={classes.charmsValue} title={COPY.itemGridCard.charmsValueTitle}>
{COPY.itemGridCard.charmsValuePrefix}
{formatMoney(charmsValue, currency)}
</p>
)}
{status !== null && (
<p
className={classes.status}
Expand Down
1 change: 1 addition & 0 deletions src/components/item-grid-card/item-grid-card.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ITEM_GRID_CARD = {
wear: "mt-0.5 truncate text-[11px] leading-4 text-muted-foreground",
figures: "mt-1.5 flex items-baseline justify-between gap-2",
price: "tabular text-base font-semibold leading-tight",
charmsValue: "tabular shrink-0 text-xs text-muted-foreground",
status: "tabular shrink-0 text-xs text-muted-foreground",
/** Pinned to the bottom so attachments, note and location line up across a row of cards. */
footer: "mt-auto flex min-w-0 flex-col gap-1.5 pt-2",
Expand Down
19 changes: 18 additions & 1 deletion src/components/item-table/item-table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HighlightDisclosure } from "~/components/highlight-disclosure/highlight
import { ItemCell } from "~/components/item-cell/item-cell.component";
import { ITEM_CELL } from "~/components/item-cell/item-cell.config";
import { COPY } from "~/lib/copy/copy.config";
import { attachedCharmsValue } from "~/lib/items/charm-value";
import { itemRowKey } from "~/lib/items/item-key";
import { highlightSortValue } from "~/lib/items/highlights";
import type { ItemView } from "~/lib/items/item.types";
Expand Down Expand Up @@ -39,7 +40,23 @@ export function ItemTable({
header: COPY.itemColumns.price,
align: "right",
sortValue: (r) => r.price,
cell: (r) => (r.price === null ? COPY.common.empty : formatMoney(r.price, currency)),
cell: (r) => {
const charmsValue = attachedCharmsValue(r);
return (
<>
{r.price === null ? COPY.common.empty : formatMoney(r.price, currency)}
{charmsValue !== null && (
<span
className={ITEM_TABLE.charmsValueClass}
title={COPY.itemGridCard.charmsValueTitle}
>
{COPY.itemGridCard.charmsValuePrefix}
{formatMoney(charmsValue, currency)}
</span>
)}
</>
);
},
};
const location: DataTableColumn<ItemView>[] = showLocation
? [
Expand Down
1 change: 1 addition & 0 deletions src/components/item-table/item-table.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const ITEM_TABLE = {
direction,
})) satisfies readonly DataTableSortOption[],
sortLabel: ITEM_SORT_LABEL,
charmsValueClass: "block text-xs font-normal text-muted-foreground",
initialSort: { columnId: "price", direction: "desc" } satisfies SortState,
/** Enough rows to fill a tall screen; the rest are clipped. */
skeletonRows: 16,
Expand Down
9 changes: 9 additions & 0 deletions src/components/portfolio-hero/portfolio-hero.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export function PortfolioHero({ dashboard, currency }: PortfolioHeroProps) {
detail: `${totals.unitsLoaded}/${totals.unitsTotal} units`,
},
{ label: copy.items, value: formatInteger(totals.itemCount) },
...(totals.charmsValue > 0
? [
{
label: copy.charms,
value: formatMoney(totals.charmsValue, currency),
detail: copy.charmsDetail,
},
]
: []),
];
return (
<section className="@container overflow-hidden rounded-xl border bg-card">
Expand Down
6 changes: 6 additions & 0 deletions src/lib/copy/copy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export const COPY = {
scope: (label: string) => `Covers: ${label}`,
ariaFor: (label: string) => `Refresh ${label}`,
},
itemGridCard: {
charmsValuePrefix: "+ ",
charmsValueTitle: "Market value of the attached charms, not included in the price",
},
itemColumns: {
item: "Item",
location: "Location",
Expand All @@ -185,6 +189,8 @@ export const COPY = {
inventory: "Inventory",
storage: "Storage units",
items: "Items",
charms: "Charms",
charmsDetail: "not in total",
change: { day: "24h", week: "7d", month: "30d" },
historyTitle: "Value over time",
historyEmpty:
Expand Down
45 changes: 45 additions & 0 deletions src/lib/items/charm-value.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { attachedCharmsValue } from "./charm-value.ts";
import type { CharmView } from "./item.types.ts";

const charm = (over: Partial<CharmView>): CharmView => ({
name: "Charm | Lil' Ava",
imageUrl: null,
pattern: null,
videoUrl: null,
marketHashName: "Charm | Lil' Ava",
price: null,
...over,
});

describe("attachedCharmsValue", () => {
it("is null when the weapon has no charms", () => {
assert.equal(attachedCharmsValue({ charms: [], marketHashName: "AK-47 | Redline" }), null);
});
it("is null when no charm is priced", () => {
assert.equal(
attachedCharmsValue({ charms: [charm({})], marketHashName: "AK-47 | Redline" }),
null,
);
});
it("sums priced charms and ignores unpriced ones", () => {
assert.equal(
attachedCharmsValue({
charms: [charm({ price: 12.5 }), charm({ price: null }), charm({ price: 3 })],
marketHashName: "AK-47 | Redline",
}),
15.5,
);
});
it("does not count a loose charm twice", () => {
assert.equal(
attachedCharmsValue({
charms: [charm({ price: 9 })],
marketHashName: "Charm | Lil' Ava",
}),
null,
);
});
});
18 changes: 18 additions & 0 deletions src/lib/items/charm-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ItemView } from "./item.types.ts";

/**
* Combined market value of the charms attached to a weapon, or null when none is priced.
* A loose charm lists itself in `charms`, and its own price already covers it, so it is skipped.
*/
export function attachedCharmsValue(
item: Pick<ItemView, "charms" | "marketHashName">,
): number | null {
let total = 0;
let priced = false;
for (const charm of item.charms) {
if (charm.price === null || charm.marketHashName === item.marketHashName) continue;
total += charm.price;
priced = true;
}
return priced ? total : null;
}
2 changes: 2 additions & 0 deletions src/lib/items/dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export type Dashboard = {
readonly itemCount: number;
readonly inventoryValue: number;
readonly storageValue: number;
/** Market value of charms attached to weapons; already excluded from `value`. */
readonly charmsValue: number;
readonly unitsLoaded: number;
readonly unitsTotal: number;
};
Expand Down
Loading
Loading