Skip to content
Closed
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
3 changes: 2 additions & 1 deletion frontend/components/AppNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions frontend/lib/display-name.ts
Original file line number Diff line number Diff line change
@@ -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";
}
49 changes: 49 additions & 0 deletions frontend/tests/display-name.test.ts
Original file line number Diff line number Diff line change
@@ -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> = {}): User {
return {
id: "company-1",
role: "company",
email: "company@example.com",
name: "Acme",
description: "",
createdAt: 0,
...overrides,
} as User;
}

function dev(overrides: Partial<User> = {}): 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<User>))).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",
);
});
});