Skip to content

Commit ea48e6c

Browse files
committed
fix(sdk): use SiteLink and SiteEmbed with smart wallets
1 parent ef99d0f commit ea48e6c

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

packages/thirdweb/src/react/web/ui/SiteEmbed.test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { render } from "../../../../test/src/react-render.js";
2+
import { render, waitFor } from "../../../../test/src/react-render.js";
33
import { TEST_CLIENT } from "../../../../test/src/test-clients.js";
44
import { SiteEmbed } from "./SiteEmbed.js";
55

@@ -21,4 +21,19 @@ describe("SiteEmbed", () => {
2121
render(<SiteEmbed src={testUrl} client={{} as any} />),
2222
).toThrow("The SiteEmbed client must have a clientId");
2323
});
24+
25+
it("uses inApp wallet when wallet is a smart wallet", async () => {
26+
const testUrl = "https://thirdweb.com/";
27+
const { container } = render(
28+
<SiteEmbed src={testUrl} client={TEST_CLIENT} />,
29+
{
30+
setConnectedWallet: true,
31+
walletId: "smart",
32+
},
33+
);
34+
35+
const iframe = container.querySelector("iframe");
36+
expect(iframe).toBeTruthy();
37+
await waitFor(() => expect(iframe?.src).toContain("walletId=inApp"));
38+
});
2439
});

packages/thirdweb/src/react/web/ui/SiteEmbed.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function SiteEmbed({
5353
} = useQuery({
5454
queryKey: ["site-embed", walletId, src, client.clientId, ecosystem],
5555
enabled:
56-
activeWallet && (isEcosystemWallet(activeWallet) || walletId === "inApp"),
56+
activeWallet &&
57+
(isEcosystemWallet(activeWallet) ||
58+
walletId === "inApp" ||
59+
walletId === "smart"),
5760
queryFn: async () => {
5861
const storage = new ClientScopedStorage({
5962
storage: webLocalStorage,
@@ -70,7 +73,7 @@ export function SiteEmbed({
7073

7174
const url = new URL(src);
7275
if (walletId) {
73-
url.searchParams.set("walletId", walletId);
76+
url.searchParams.set("walletId", walletId === "smart" ? "inApp" : walletId);
7477
}
7578
if (authProvider) {
7679
url.searchParams.set("authProvider", authProvider);

packages/thirdweb/src/react/web/ui/SiteLink.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ describe("SiteLink", () => {
4545
expect(anchor).toBeTruthy();
4646
await waitFor(() => expect(anchor?.href).toContain("walletId="));
4747
});
48+
49+
it("uses inApp wallet when wallet is a smart wallet", async () => {
50+
const testUrl = "https://example.com/";
51+
const { container } = render(
52+
<SiteLink href={testUrl} client={TEST_CLIENT}>
53+
Test Link
54+
</SiteLink>,
55+
{
56+
setConnectedWallet: true,
57+
walletId: "smart",
58+
},
59+
);
60+
61+
const anchor = container.querySelector("a");
62+
expect(anchor).toBeTruthy();
63+
await waitFor(() => expect(anchor?.href).toContain("walletId=inApp"));
64+
});
4865
});

packages/thirdweb/src/react/web/ui/SiteLink.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function SiteLink({
5353
} = useQuery({
5454
queryKey: ["site-link", walletId, href, client.clientId, ecosystem],
5555
enabled:
56-
activeWallet && (isEcosystemWallet(activeWallet) || walletId === "inApp"),
56+
activeWallet &&
57+
(isEcosystemWallet(activeWallet) ||
58+
walletId === "inApp" ||
59+
walletId === "smart"),
5760
queryFn: async () => {
5861
const storage = new ClientScopedStorage({
5962
storage: webLocalStorage,
@@ -70,7 +73,7 @@ export function SiteLink({
7073

7174
const url = new URL(href);
7275
if (walletId) {
73-
url.searchParams.set("walletId", walletId);
76+
url.searchParams.set("walletId", walletId === "smart" ? "inApp" : walletId);
7477
}
7578
if (authProvider) {
7679
url.searchParams.set("authProvider", authProvider);

packages/thirdweb/test/src/SetConnectedWallet.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { useEffect, useRef } from "react";
22
import { createWalletAdapter } from "../../src/adapters/wallet-adapter.js";
33
import { ethereum } from "../../src/chains/chain-definitions/ethereum.js";
44
import { useConnect } from "../../src/react/core/hooks/wallets/useConnect.js";
5+
import type { WalletId } from "../../src/wallets/wallet-types.js";
6+
import type { Wallet } from "../../src/wallets/interfaces/wallet.js";
57
import { TEST_CLIENT } from "./test-clients.js";
68
import { TEST_ACCOUNT_A } from "./test-wallets.js";
79

8-
export const SetConnectedWallet = () => {
10+
export const SetConnectedWallet = (props: { id?: WalletId }) => {
11+
const { id } = props;
912
const connectStarted = useRef(false);
1013
const { connect } = useConnect();
1114

@@ -21,9 +24,13 @@ export const SetConnectedWallet = () => {
2124
adaptedAccount: TEST_ACCOUNT_A,
2225
client: TEST_CLIENT,
2326
chain: ethereum,
24-
onDisconnect: () => {},
25-
switchChain: () => {},
26-
});
27+
onDisconnect: () => { },
28+
switchChain: () => { },
29+
}) as Wallet;
30+
31+
if (id) {
32+
wallet.id = id;
33+
}
2734

2835
connect(wallet);
2936
}, []);

packages/thirdweb/test/src/react-render.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { RenderOptions } from "@testing-library/react";
44
import type { ReactElement } from "react";
55
import { ThirdwebProvider } from "../../src/react/web/providers/thirdweb-provider.js";
66
import { SetConnectedWallet } from "./SetConnectedWallet.js";
7+
import type { WalletId } from "src/wallets/wallet-types.js";
78

89
const Providers = ({ children }: { children: React.ReactNode }) => {
910
return <ThirdwebProvider>{children}</ThirdwebProvider>;
@@ -13,11 +14,14 @@ const customRender = (
1314
ui: ReactElement,
1415
options?: Omit<RenderOptions, "wrapper"> & {
1516
setConnectedWallet?: boolean;
17+
walletId?: WalletId;
1618
},
1719
) => {
1820
return render(
1921
<div>
20-
{options?.setConnectedWallet ? <SetConnectedWallet /> : null}
22+
{options?.setConnectedWallet ? (
23+
<SetConnectedWallet id={options.walletId} />
24+
) : null}
2125
{ui}
2226
</div>,
2327
{ wrapper: Providers, ...options },

0 commit comments

Comments
 (0)