Skip to content

Commit 7003766

Browse files
committed
feat(sdk): allows hiding the link profiles button
1 parent 59ec04d commit 7003766

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed

.changeset/four-ducks-try.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Feature: Allows hiding the "Linked Profiles" button in the `ConnectButton` Details Modal
6+
7+
```tsx
8+
<ConnectButton detailsModal={{ manageWallet: { allowLinkingProfiles: false } }} />
9+
```

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ export type ConnectButton_detailsModalOptions = {
327327
* Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
328328
*/
329329
showBalanceInFiat?: SupportedFiatCurrency;
330+
331+
/**
332+
* Configure options for managing the connected wallet.
333+
*/
334+
manageWallet?: {
335+
/**
336+
* Allow linking other profiles to the connected wallet.
337+
*
338+
* By default it is `true`.
339+
*/
340+
allowLinkingProfiles?: boolean;
341+
};
330342
};
331343

332344
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { render, screen } from "../../../../../../test/src/react-render.js";
3+
import { TEST_CLIENT } from "../../../../../../test/src/test-clients.js";
4+
import { createWallet } from "../../../../../wallets/create-wallet.js";
5+
import { useAdminWallet } from "../../../../core/hooks/wallets/useAdminWallet.js";
6+
import en from "../locale/en.js";
7+
import { ManageWalletScreen } from "./ManageWalletScreen.js";
8+
9+
vi.mock("../../../../core/hooks/wallets/useAdminWallet");
10+
11+
describe("ManageWalletScreen", () => {
12+
const mockProps = {
13+
onBack: vi.fn(),
14+
setScreen: vi.fn(),
15+
closeModal: vi.fn(),
16+
locale: en,
17+
client: TEST_CLIENT,
18+
};
19+
20+
beforeEach(() => {
21+
vi.mocked(useAdminWallet).mockReturnValue(createWallet("inApp"));
22+
});
23+
24+
it("should render the modal header with the correct title", () => {
25+
render(<ManageWalletScreen {...mockProps} />);
26+
expect(screen.getByText(en.manageWallet.title)).toBeInTheDocument();
27+
});
28+
29+
it("should render the linked profiles button if allowLinkingProfiles is true", () => {
30+
render(
31+
<ManageWalletScreen
32+
{...mockProps}
33+
manageWallet={{ allowLinkingProfiles: true }}
34+
/>,
35+
);
36+
expect(
37+
screen.getByText(en.manageWallet.linkedProfiles),
38+
).toBeInTheDocument();
39+
});
40+
41+
it("should not render the linked profiles button if allowLinkingProfiles is false", () => {
42+
render(
43+
<ManageWalletScreen
44+
{...mockProps}
45+
manageWallet={{ allowLinkingProfiles: false }}
46+
/>,
47+
);
48+
expect(
49+
screen.queryByText(en.manageWallet.linkedProfiles),
50+
).not.toBeInTheDocument();
51+
});
52+
53+
it("should default to showing linked profiles button", () => {
54+
render(<ManageWalletScreen {...mockProps} />);
55+
expect(
56+
screen.getByText(en.manageWallet.linkedProfiles),
57+
).toBeInTheDocument();
58+
});
59+
60+
it("should render the wallet connect receiver button", () => {
61+
render(<ManageWalletScreen {...mockProps} />);
62+
expect(screen.getByText(en.manageWallet.connectAnApp)).toBeInTheDocument();
63+
});
64+
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use client";
22
import { ShuffleIcon } from "@radix-ui/react-icons";
33
import type { ThirdwebClient } from "../../../../../client/client.js";
4-
import { isEcosystemWallet } from "../../../../../wallets/ecosystem/is-ecosystem-wallet.js";
54
import { isInAppWallet } from "../../../../../wallets/in-app/core/wallet/index.js";
65
import { injectedProvider } from "../../../../../wallets/injected/mipdStore.js";
76
import { fontSize, iconSize } from "../../../../core/design-system/index.js";
7+
import type { ConnectButton_detailsModalOptions } from "../../../../core/hooks/connection/ConnectButtonProps.js";
88
import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js";
99
import { useAdminWallet } from "../../../../core/hooks/wallets/useAdminWallet.js";
1010
import { Spacer } from "../../components/Spacer.js";
@@ -26,6 +26,7 @@ export function ManageWalletScreen(props: {
2626
closeModal: () => void;
2727
locale: ConnectLocale;
2828
client: ThirdwebClient;
29+
manageWallet?: ConnectButton_detailsModalOptions["manageWallet"];
2930
}) {
3031
const activeWallet = useAdminWallet();
3132

@@ -57,10 +58,9 @@ export function ManageWalletScreen(props: {
5758
connectLocale={props.locale}
5859
/>
5960

60-
{/* Multi-auth */}
61-
{activeWallet &&
62-
(activeWallet?.id === "inApp" ||
63-
isEcosystemWallet(activeWallet)) && (
61+
{/* Unified Identity */}
62+
{typeof activeWallet !== "undefined" &&
63+
props.manageWallet?.allowLinkingProfiles !== false && (
6464
<MenuButton
6565
onClick={() => {
6666
props.setScreen("linked-profiles");

0 commit comments

Comments
 (0)