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
54 changes: 54 additions & 0 deletions apps/mobile/src/features/chats/widgets/KinMoneyInCheckCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { memo, useState } from "react";
import { View } from "react-native";

import { AppText as Text } from "../../../components/ui/AppText";
import { Button } from "../../../components/ui/Button";
import {
KIN_MONEY_IN_COPY,
kinMoneyInShown,
type KinMoneyInCheckView,
} from "@t3tools/client-runtime/kin/kinMoneyInCheck";

/** A check of money in against the bank: read-only, so a newer check only quiets it. */
export const KinMoneyInCheckCard = memo(function KinMoneyInCheckCard(props: {
readonly check: KinMoneyInCheckView;
}) {
const { check } = props;
const [open, setOpen] = useState(false);
const shown = kinMoneyInShown(check, open);
const tone = check.superseded ? "text-foreground-muted" : "text-foreground";
return (
<View className="gap-2.5 rounded-[20px] border border-border bg-card-alt p-4">
{check.superseded ? (
<Text textRole="caption" className="font-t3-medium text-foreground-muted">
{KIN_MONEY_IN_COPY.superseded}
</Text>
) : null}
<Text textRole="body" className={`font-t3-bold ${tone}`}>
{check.title}
</Text>
{check.changes === null ? null : (
<Text textRole="footnote" className="text-foreground-muted">
{check.changes}
</Text>
)}
{shown.rows.map((row) => (
<View key={row.key} className="gap-0.5">
{row.heading === null ? null : (
<Text textRole="footnote" className="pt-1 font-t3-medium text-foreground-secondary">
{row.heading}
</Text>
)}
<Text textRole="footnote" className={tone}>
{row.text}
</Text>
</View>
))}
{shown.toggle === null ? null : (
<View className="flex-row">
<Button tone="text" size="compact" label={shown.toggle} onPress={() => setOpen(!open)} />
</View>
)}
</View>
);
});
3 changes: 3 additions & 0 deletions apps/mobile/src/features/chats/widgets/KinWidgetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { KinDocCard } from "./KinDocCard";
import { KinHostTroubleCard } from "./KinHostTroubleCard";
import { KinMailRuleCard } from "./KinMailRuleCard";
import { KinMemoryChangesCard } from "./KinMemoryChangesCard";
import { KinMoneyInCheckCard } from "./KinMoneyInCheckCard";
import { KinSocialPackCard, KinSocialWeekCard } from "./KinSocialCards";
import { KinStatementPasswordCard, KinStatementReviewCard } from "./KinStatementCards";
import { KinTaskCard } from "./KinTaskCard";
Expand Down Expand Up @@ -140,6 +141,8 @@ export const KinWidgetView = memo(function KinWidgetView(props: {
ownerLevel={access === null || kinOwnerLevel(access)}
/>
);
case "money_in_check":
return <KinMoneyInCheckCard check={view.check} />;
case "social_week":
return <KinSocialWeekCard week={view.week} environmentId={props.environmentId} />;
case "social_pack":
Expand Down
43 changes: 43 additions & 0 deletions apps/web/src/kin/KinCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
type KinTaskTone,
KIN_CARD_COPY,
} from "@t3tools/client-runtime/kin/kinCardPresentation";
import {
KIN_MONEY_IN_COPY,
kinMoneyInShown,
type KinMoneyInCheckView,
} from "@t3tools/client-runtime/kin/kinMoneyInCheck";
import {
kinAddressPieces,
kinChoiceCardActions,
Expand Down Expand Up @@ -302,6 +307,8 @@ export const KinCard = memo(function KinCard(props: {
ownerLevel={ownerLevel !== false}
/>
);
case "money_in_check":
return <KinMoneyInCheckCard check={view.check} />;
case "social_week":
return <KinSocialWeekCard week={view.week} environmentId={props.environmentId} />;
case "social_pack":
Expand Down Expand Up @@ -653,6 +660,42 @@ function KinDigestCard(props: { readonly digest: KinDigestCardView }) {
);
}

/** A check of money in against the bank: read-only, so a newer check only quiets it. */
function KinMoneyInCheckCard(props: { readonly check: KinMoneyInCheckView }) {
const { check } = props;
const [open, setOpen] = useState(false);
const shown = kinMoneyInShown(check, open);
const tone = check.superseded ? "text-muted-foreground" : "text-foreground";
return (
<CardFrame label={check.accessibilityLabel}>
{check.superseded ? (
<p className="text-xs font-medium text-muted-foreground">{KIN_MONEY_IN_COPY.superseded}</p>
) : null}
<p className={cn("font-medium", tone)}>{check.title}</p>
{check.changes === null ? null : <p className="text-muted-foreground">{check.changes}</p>}
{shown.rows.length === 0 ? null : (
<ul className="flex flex-col gap-1.5">
{shown.rows.map((row) => (
<li key={row.key} className="flex flex-col gap-0.5">
{row.heading === null ? null : (
<p className="pt-1 text-xs font-medium text-muted-foreground">{row.heading}</p>
)}
<p className={cn("break-words", tone)}>{row.text}</p>
</li>
))}
</ul>
)}
{shown.toggle === null ? null : (
<div>
<Button size="xs" variant="ghost" onClick={() => setOpen(!open)}>
{shown.toggle}
</Button>
</div>
)}
</CardFrame>
);
}

function KinChoiceCard(props: {
readonly choice: KinChoiceCardView;
readonly environmentId: EnvironmentId;
Expand Down
7 changes: 7 additions & 0 deletions packages/client-runtime/src/kin/kinCardPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
KIN_HOST_TROUBLE_CARD,
KIN_MAIL_RULE_CARD_TYPE,
KIN_MEMORY_CHANGES_CARD,
KIN_MONEY_IN_CHECK_CARD,
KIN_SOCIAL_PACK_CARD,
KIN_SOCIAL_WEEK_CARD,
KIN_STATEMENT_PASSWORD_CARD,
Expand Down Expand Up @@ -33,6 +34,7 @@ import { kinDocCardView, type KinDocCardView } from "./kinDocs.ts";
import { kinHostTroubleCardView } from "./kinHostCare.ts";
import { kinLinkLabel, kinSafeWebUrl } from "./kinLinks.ts";
import { kinMailRuleCardView } from "./kinMailRules.ts";
import { kinMoneyInCheckView, type KinMoneyInCheckView } from "./kinMoneyInCheck.ts";
import { kinSentences } from "./kinScreenState.ts";
import { kinZoneLabel } from "./kinTimeZone.ts";
import {
Expand Down Expand Up @@ -100,6 +102,7 @@ export type KinCardView =
| { readonly kind: "statement_review"; readonly review: KinStatementReviewView }
| { readonly kind: "statement_password"; readonly password: KinStatementPasswordView }
| { readonly kind: "bill_batch"; readonly bills: KinBillBatchCardView }
| { readonly kind: "money_in_check"; readonly check: KinMoneyInCheckView }
| { readonly kind: "social_week"; readonly week: KinSocialWeekView }
| { readonly kind: "social_pack"; readonly pack: KinSocialPackView }
/** Drawn with the reader's clock (`kinHostTroubleCardView`), so it carries the widget. */
Expand Down Expand Up @@ -646,6 +649,10 @@ function kinLiveCardView(
const bills = kinBillBatchCardView(widget);
return bills === null ? unknown(widget) : { kind: "bill_batch", bills };
}
case KIN_MONEY_IN_CHECK_CARD: {
const check = kinMoneyInCheckView(widget);
return check === null ? unknown(widget) : { kind: "money_in_check", check };
}
case KIN_MEMORY_CHANGES_CARD: {
const changes = kinMemoryChangesView(widget);
return changes === null ? unknown(widget) : { kind: "memory_changes", changes };
Expand Down
131 changes: 131 additions & 0 deletions packages/client-runtime/src/kin/kinMoneyInCheck.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import {
KIN_MONEY_IN_CHECK_CARD,
type EnvironmentId,
type KinMoneyInCheckCard,
type KinWidget,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { kinCardView } from "./kinCardPresentation.ts";
import { kinMoneyInShown, type KinMoneyInCheckView } from "./kinMoneyInCheck.ts";

const TITLE = "Money in, 1 Nov to 28 Nov, against the bank";
const MATCHED = "BNK-2, ₹47,200.00 received 10 Nov; INV-1: ₹47,200.00 recorded as received 10 Nov.";
const BANK_ONLY = "BNK-3, ₹18,500.00 received 17 Nov: Kin can't tell what it is.";

const line = (
id: string,
group: KinMoneyInCheckCard["lines"][number]["group"],
text: string,
): KinMoneyInCheckCard["lines"][number] => ({
id,
group,
day: "2026-11-10",
payments: [],
text,
printed: "NEFT CR TIDEWATER FREIGHT HDFC0001234",
});

const card = (overrides: Partial<KinMoneyInCheckCard> = {}): KinMoneyInCheckCard => ({
from: "2026-11-01",
through: "2026-11-28",
checkedOn: "2026-11-28",
title: TITLE,
counts: { matched: 1, bankOnly: 1, kinOnly: 0, notSeenYet: 0, differs: 0 },
explained: 0,
covered: [],
// The host puts bank-only lines after matches; the card shows matches first either way.
lines: [line("bank:BNK-3", "bankOnly", BANK_ONLY), line("bank:BNK-2", "matched", MATCHED)],
text: `${TITLE}\n1 matches.\n${MATCHED}\n1 is at the bank and not in Kin.\n${BANK_ONLY}`,
...overrides,
});

const HOST = "env-home" as EnvironmentId;
const view = (state: unknown): KinMoneyInCheckView => {
const widget = {
orgId: "org",
chatId: "chat",
widgetId: "w1",
messageId: "m1",
widgetClass: "native",
type: KIN_MONEY_IN_CHECK_CARD,
revision: 1,
state,
awaiting: [],
} as unknown as KinWidget;
const drawn = kinCardView(widget, HOST, () => true);
if (drawn.kind !== "money_in_check") throw new Error(`expected money in, got ${drawn.kind}`);
return drawn.check;
};

describe("kinMoneyInCheckView", () => {
it("draws a first check: its title and each line under its group, never the bank's words", () => {
const check = view(card());
expect(check).toMatchObject({ title: TITLE, changes: null, superseded: false });
expect(check.rows).toEqual([
{ key: "bank:BNK-2", heading: "Matches", text: MATCHED },
{ key: "bank:BNK-3", heading: "At the bank, not in Kin", text: BANK_ONLY },
]);
expect(check.accessibilityLabel).toContain(BANK_ONLY);
expect(JSON.stringify(check)).not.toContain("NEFT");
expect(kinMoneyInShown(check, false)).toEqual({ rows: check.rows, toggle: null });
});

it("says what changed since the last check, and quiets a check a newer one replaced", () => {
const again = view(card({ changes: "Nothing changed since the check on 28 Nov." }));
expect(again.changes).toBe("Nothing changed since the check on 28 Nov.");
expect(again.superseded).toBe(false);

const old = view(card({ superseded: true, text: `A newer check is below.\n${TITLE}` }));
expect(old.superseded).toBe(true);
expect(old.rows).toHaveLength(2);
expect(old.accessibilityLabel.startsWith("A newer check is below. ")).toBe(true);
});

it("folds a long check to its first ten lines under Show all, and opens it whole", () => {
const lines = Array.from({ length: 100 }, (_, index) =>
line(`bank:BNK-${index + 1}`, "bankOnly", `BNK-${index + 1}, ₹100.00 received 3 Nov.`),
);
const check = view(card({ lines }));
const folded = kinMoneyInShown(check, false);
expect(folded.rows).toHaveLength(10);
expect(folded.rows[0]?.heading).toBe("At the bank, not in Kin");
expect(folded.toggle).toBe("Show all 100");
const open = kinMoneyInShown(check, true);
expect(open.rows).toHaveLength(100);
expect(open.rows[99]?.text).toBe("BNK-100, ₹100.00 received 3 Nov.");
expect(open.toggle).toBe("Show less");
});

it("shows what a card missing fields has, never a blank card", () => {
// No lines: the host's own text, without the lines the card already shows.
const { lines: _lines, ...noLines } = card({ changes: "Since the check on 20 Nov: 1 fixed." });
expect(view(noLines)).toMatchObject({
title: TITLE,
changes: "Since the check on 20 Nov: 1 fixed.",
rows: [
{ heading: null, text: "1 matches." },
{ heading: null, text: MATCHED },
{ heading: null, text: "1 is at the bank and not in Kin." },
{ heading: null, text: BANK_ONLY },
],
});
// No title, a line with no group, and a line with no words.
const { title: _title, ...noTitle } = card({
lines: [
{ ...line("", "matched", MATCHED), group: undefined } as never,
line("x", "differs", " "),
],
});
expect(view(noTitle)).toMatchObject({
title: "Money in, against the bank",
rows: [{ key: "line:0", heading: null, text: MATCHED }],
});
// Nothing at all to show falls back to the generic card.
const empty = { orgId: "org", widgetClass: "native", type: KIN_MONEY_IN_CHECK_CARD, state: {} };
expect(kinCardView(empty as unknown as KinWidget, HOST, () => true)).toEqual({
kind: "unknown",
text: null,
});
});
});
Loading
Loading