diff --git a/frontend/components/AppNav.tsx b/frontend/components/AppNav.tsx index 9faf59e..d2122a6 100644 --- a/frontend/components/AppNav.tsx +++ b/frontend/components/AppNav.tsx @@ -9,6 +9,7 @@ import { useAuth, usePrivyBackend } from "@/lib/auth-context"; import { useWallets } from "@privy-io/react-auth/solana"; import { mockWallet, setWallet } from "@/lib/store"; import { getConnection } from "@/lib/solana"; +import { appNavDisplayName } from "@/lib/display-name"; import { Avatar } from "./Avatar"; import { DepositModal } from "./DepositModal"; import { WithdrawModal } from "./WithdrawModal"; @@ -35,7 +36,7 @@ export function AppNav() { if (!user) return null; const isCompany = user.role === "company"; - const displayName = isCompany ? user.name : user.username; + const displayName = appNavDisplayName(user); const walletAddress = privyMode ? privyWallet : user.wallet ?? null; const tabs = isCompany diff --git a/frontend/lib/display-name.ts b/frontend/lib/display-name.ts new file mode 100644 index 0000000..e0c39d0 --- /dev/null +++ b/frontend/lib/display-name.ts @@ -0,0 +1,10 @@ +import type { User } from "@/lib/types"; + +export function appNavDisplayName(user: User): string { + const rawName = user.role === "company" ? user.name : user.username; + const name = rawName?.trim(); + + if (name) return name; + + return user.role === "company" ? "there" : "Developer"; +} diff --git a/frontend/tests/display-name.test.ts b/frontend/tests/display-name.test.ts new file mode 100644 index 0000000..bdc526e --- /dev/null +++ b/frontend/tests/display-name.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, test } from "vitest"; +import { appNavDisplayName } from "@/lib/display-name"; +import type { User } from "@/lib/types"; + +function company(overrides: Partial = {}): User { + return { + id: "company-1", + role: "company", + email: "company@example.com", + name: "Acme", + description: "", + createdAt: 0, + ...overrides, + } as User; +} + +function dev(overrides: Partial = {}): User { + return { + id: "dev-1", + role: "dev", + email: "dev@example.com", + username: "builder", + skills: [], + createdAt: 0, + ...overrides, + } as User; +} + +describe("appNavDisplayName", () => { + test("preserves a configured company name", () => { + expect(appNavDisplayName(company({ name: "GhBounty" }))).toBe("GhBounty"); + }); + + test("falls back for missing company names", () => { + expect(appNavDisplayName(company({ name: undefined } as Partial))).toBe( + "there", + ); + }); + + test("falls back for blank company names", () => { + expect(appNavDisplayName(company({ name: " " }))).toBe("there"); + }); + + test("preserves a configured developer username", () => { + expect(appNavDisplayName(dev({ username: "opus-builder" }))).toBe( + "opus-builder", + ); + }); +});