Skip to content

Commit 8fe6f57

Browse files
committed
more tests
1 parent d4dc710 commit 8fe6f57

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { beforeEach, describe, it, vi } from "vitest";
2+
import { render } from "../../../../../test/src/react-render.js";
3+
import { TEST_CLIENT } from "../../../../../test/src/test-clients.js";
4+
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
5+
import { DetailsModal } from "./Details.js";
6+
import { getConnectLocale } from "./locale/getConnectLocale.js";
7+
8+
vi.mock("../../../core/hooks/wallets/useActiveAccount.js", () => ({
9+
useActiveAccount: vi.fn(),
10+
}));
11+
12+
const mockDetailsModalOptions = {};
13+
const mockSupportedTokens = {};
14+
const mockSupportedNFTs = {};
15+
// biome-ignore lint/suspicious/noExplicitAny: Mock
16+
const mockChains: any[] = [];
17+
const mockDisplayBalanceToken = {};
18+
const mockConnectOptions = {};
19+
// biome-ignore lint/suspicious/noExplicitAny: Mock
20+
const mockAssetTabs: any[] = [];
21+
const mockOnDisconnect = vi.fn();
22+
23+
describe("Details Component", () => {
24+
beforeEach(() => {
25+
// Mock the animate method
26+
HTMLDivElement.prototype.animate = vi.fn().mockReturnValue({
27+
onfinish: vi.fn(),
28+
});
29+
});
30+
31+
it("should close the modal when activeAccount is falsy", async () => {
32+
const closeModalMock = vi.fn();
33+
const locale = await getConnectLocale("en_US");
34+
35+
vi.mocked(useActiveAccount).mockReturnValue(undefined);
36+
37+
render(
38+
<DetailsModal
39+
client={TEST_CLIENT}
40+
locale={locale}
41+
detailsModal={mockDetailsModalOptions}
42+
theme="light"
43+
supportedTokens={mockSupportedTokens}
44+
supportedNFTs={mockSupportedNFTs}
45+
closeModal={closeModalMock}
46+
onDisconnect={mockOnDisconnect}
47+
chains={mockChains}
48+
displayBalanceToken={mockDisplayBalanceToken}
49+
connectOptions={mockConnectOptions}
50+
assetTabs={mockAssetTabs}
51+
/>,
52+
);
53+
});
54+
});

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TextAlignJustifyIcon,
1010
} from "@radix-ui/react-icons";
1111
import { useQuery } from "@tanstack/react-query";
12-
import { type JSX, useContext, useEffect, useState } from "react";
12+
import { type JSX, useCallback, useContext, useEffect, useState } from "react";
1313
import { trackPayEvent } from "../../../../analytics/track/pay.js";
1414
import type { Chain } from "../../../../chains/types.js";
1515
import type { ThirdwebClient } from "../../../../client/client.js";
@@ -291,7 +291,10 @@ export const ConnectedWalletDetails: React.FC<{
291291
);
292292
};
293293

294-
function DetailsModal(props: {
294+
/**
295+
* @internal
296+
*/
297+
export function DetailsModal(props: {
295298
client: ThirdwebClient;
296299
locale: ConnectLocale;
297300
detailsModal?: ConnectButton_detailsModalOptions;
@@ -330,12 +333,12 @@ function DetailsModal(props: {
330333
wallets: activeWallet ? [activeWallet] : [],
331334
});
332335

333-
function closeModal() {
336+
const closeModal = useCallback(() => {
334337
setIsOpen(false);
335338
onModalUnmount(() => {
336339
props.closeModal();
337340
});
338-
}
341+
}, [props.closeModal]);
339342

340343
function handleDisconnect(info: { wallet: Wallet; account: Account }) {
341344
setIsOpen(false);
@@ -345,10 +348,9 @@ function DetailsModal(props: {
345348

346349
useEffect(() => {
347350
if (!activeAccount) {
348-
setIsOpen(false);
349-
props.closeModal();
351+
closeModal();
350352
}
351-
}, [activeAccount, props.closeModal]);
353+
}, [activeAccount, closeModal]);
352354

353355
const networkSwitcherButton = (
354356
<MenuButton
@@ -698,20 +700,6 @@ function DetailsModal(props: {
698700
<Text color="primaryText">{props.locale.manageWallet.title}</Text>
699701
</MenuButton>
700702

701-
{/* Switch to Personal Wallet */}
702-
{/* {personalWallet &&
703-
!props.detailsModal?.hideSwitchToPersonalWallet && (
704-
<AccountSwitcher
705-
wallet={personalWallet}
706-
name={locale.personalWallet}
707-
/>
708-
)} */}
709-
710-
{/* Switch to Smart Wallet */}
711-
{/* {smartWallet && (
712-
<AccountSwitcher name={locale.smartWallet} wallet={smartWallet} />
713-
)} */}
714-
715703
{/* Request Testnet funds */}
716704
{(props.detailsModal?.showTestnetFaucet ?? false) &&
717705
(chainFaucetsQuery.faucets.length > 0 ||

packages/thirdweb/src/wallets/manager/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function createConnectionManager(storage: AsyncStorage) {
163163
) => {
164164
const signer = eoaWallet.getAccount();
165165
if (!signer) {
166-
throw new Error("Can not set a wallet without an account as active");
166+
throw new Error("Cannot set a wallet without an account as active");
167167
}
168168

169169
const wallet = smartWallet(options);
@@ -196,7 +196,7 @@ export function createConnectionManager(storage: AsyncStorage) {
196196
const handleSetActiveWallet = (activeWallet: Wallet) => {
197197
const account = activeWallet.getAccount();
198198
if (!account) {
199-
throw new Error("Can not set a wallet without an account as active");
199+
throw new Error("Cannot set a wallet without an account as active");
200200
}
201201

202202
// also add it to connected wallets if it's not already there

0 commit comments

Comments
 (0)