Skip to content

Commit d5a68c8

Browse files
committed
[SDK] Fix: Custom auth profile label (#5660)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on improving the display of linked profiles in the `LinkedProfilesScreen` component by correctly handling the "Custom Auth" profile type and enhancing unit tests for various profile types. ### Detailed summary - Updated the label for the "Custom Auth" profile type to "Custom Profile". - Added unit tests for various profile types including email, google, phone, wallet address, cognito, custom_auth_endpoint, and unknown types. - Ensured guest profiles are not displayed. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent dcd5822 commit d5a68c8

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

.changeset/breezy-birds-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix: Correctly cleans the "Custom Auth" profile type label
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { render, screen } from "../../../../../../test/src/react-render.js";
3+
import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js";
4+
import { useProfiles } from "../../../hooks/wallets/useProfiles.js";
5+
import { LinkedProfilesScreen } from "./LinkedProfilesScreen.jsx";
6+
7+
// Mock the hooks
8+
vi.mock("../../../hooks/wallets/useProfiles");
9+
vi.mock("../../../../core/social/useSocialProfiles");
10+
vi.mock("../../components/Img", () => ({
11+
Img: () => <div data-testid="mock-img">Mock Image</div>,
12+
}));
13+
14+
describe("LinkedProfilesScreen", () => {
15+
const mockClient = {
16+
clientId: "test-client-id",
17+
secretKey: undefined,
18+
};
19+
20+
const mockProps = {
21+
onBack: vi.fn(),
22+
setScreen: vi.fn(),
23+
locale: {
24+
manageWallet: {
25+
linkedProfiles: "Linked Profiles",
26+
linkProfile: "Link Profile",
27+
},
28+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
29+
} as any,
30+
client: mockClient,
31+
};
32+
33+
beforeEach(() => {
34+
vi.mocked(useSocialProfiles).mockReturnValue({
35+
data: undefined,
36+
isLoading: false,
37+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
38+
} as any);
39+
});
40+
41+
describe("getProfileDisplayName", () => {
42+
it("should display email for email profile type", () => {
43+
vi.mocked(useProfiles).mockReturnValue({
44+
data: [{ type: "email", details: { email: "test@example.com" } }],
45+
isLoading: false,
46+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
47+
} as any);
48+
49+
render(<LinkedProfilesScreen {...mockProps} />);
50+
expect(screen.getByText("test@example.com")).toBeInTheDocument();
51+
});
52+
53+
it("should display email for google profile type", () => {
54+
vi.mocked(useProfiles).mockReturnValue({
55+
data: [{ type: "google", details: { email: "google@example.com" } }],
56+
isLoading: false,
57+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
58+
} as any);
59+
60+
render(<LinkedProfilesScreen {...mockProps} />);
61+
expect(screen.getByText("google@example.com")).toBeInTheDocument();
62+
});
63+
64+
it("should display phone number for phone profile type", () => {
65+
vi.mocked(useProfiles).mockReturnValue({
66+
data: [{ type: "phone", details: { phone: "+1234567890" } }],
67+
isLoading: false,
68+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
69+
} as any);
70+
71+
render(<LinkedProfilesScreen {...mockProps} />);
72+
expect(screen.getByText("+1234567890")).toBeInTheDocument();
73+
});
74+
75+
it("should display shortened address when address is present", () => {
76+
vi.mocked(useProfiles).mockReturnValue({
77+
data: [
78+
{
79+
type: "wallet",
80+
details: { address: "0x1234567890abcdef1234567890abcdef12345678" },
81+
},
82+
],
83+
isLoading: false,
84+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
85+
} as any);
86+
87+
render(<LinkedProfilesScreen {...mockProps} />);
88+
expect(screen.getByText("0x123456...345678")).toBeInTheDocument();
89+
});
90+
91+
it("should display email for cognito profile type", () => {
92+
vi.mocked(useProfiles).mockReturnValue({
93+
data: [{ type: "cognito", details: { email: "cognito@example.com" } }],
94+
isLoading: false,
95+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
96+
} as any);
97+
98+
render(<LinkedProfilesScreen {...mockProps} />);
99+
expect(screen.getByText("cognito@example.com")).toBeInTheDocument();
100+
});
101+
102+
it("should display Custom Profile for custom_auth_endpoint", () => {
103+
vi.mocked(useProfiles).mockReturnValue({
104+
data: [{ type: "Custom_auth_endpoint", details: {} }],
105+
isLoading: false,
106+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
107+
} as any);
108+
109+
render(<LinkedProfilesScreen {...mockProps} />);
110+
expect(screen.getByText("Custom Profile")).toBeInTheDocument();
111+
});
112+
113+
it("should capitalize unknown profile types", () => {
114+
vi.mocked(useProfiles).mockReturnValue({
115+
data: [{ type: "unknown", details: {} }],
116+
isLoading: false,
117+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
118+
} as any);
119+
120+
render(<LinkedProfilesScreen {...mockProps} />);
121+
expect(screen.getByText("Unknown")).toBeInTheDocument();
122+
});
123+
124+
it("should not display guest profiles", () => {
125+
vi.mocked(useProfiles).mockReturnValue({
126+
data: [{ type: "guest", details: {} }],
127+
isLoading: false,
128+
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
129+
} as any);
130+
131+
render(<LinkedProfilesScreen {...mockProps} />);
132+
expect(screen.queryByText("Guest")).not.toBeInTheDocument();
133+
});
134+
});
135+
});

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function getProfileDisplayName(profile: Profile) {
3333
case (profile.type as string) === "cognito" &&
3434
profile.details.email !== undefined:
3535
return profile.details.email;
36+
case (profile.type as string).toLowerCase() === "custom_auth_endpoint":
37+
return "Custom Profile";
3638
default:
3739
return profile.type.slice(0, 1).toUpperCase() + profile.type.slice(1);
3840
}

0 commit comments

Comments
 (0)