Skip to content

Commit 1851a8c

Browse files
[thirdweb] feat: Add activeWallet prop to PayEmbed (#6335)
1 parent 6345634 commit 1851a8c

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

.changeset/fifty-pandas-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Add `activeWallet` prop to `PayEmbed` to pre select a wallet in the UI

apps/playground-web/src/app/connect/auth/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ import {
134134
import { THIRDWEB_CLIENT } from "@/lib/client";
135135
import { type SiweAuthOptions, useConnectModal } from "thirdweb/react";
136136
137+
// server actions
137138
const auth: SiweAuthOptions = {
138139
isLoggedIn: (address) => isLoggedIn(address),
139140
doLogin: (params) => login(params),
@@ -151,6 +152,7 @@ export function AuthHook() {
151152
auth.doLogout();
152153
} else {
153154
connect({
155+
client: THIRDWEB_CLIENT,
154156
auth,
155157
});
156158
}

apps/playground-web/src/components/auth/auth-hook.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useConnectModal,
1313
useSiweAuth,
1414
} from "thirdweb/react";
15+
import { THIRDWEB_CLIENT } from "../../lib/client";
1516
import { Button } from "../ui/button";
1617

1718
const auth: SiweAuthOptions = {
@@ -36,10 +37,8 @@ export function AuthHook() {
3637
await doLogout();
3738
} else {
3839
await connect({
40+
client: THIRDWEB_CLIENT,
3941
auth,
40-
onConnect: (wallet) => {
41-
console.log("connected to", wallet);
42-
},
4342
});
4443
}
4544
};

apps/playground-web/src/components/pay/embed.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
arbitrumNova,
88
base,
99
defineChain,
10-
sepolia,
1110
treasure,
1211
} from "thirdweb/chains";
1312
import { PayEmbed, getDefaultToken } from "thirdweb/react";
@@ -18,18 +17,7 @@ export function StyledPayEmbedPreview() {
1817
return (
1918
<div className="flex flex-col items-center justify-center">
2019
<StyledConnectButton
21-
chains={[
22-
base,
23-
defineChain(466),
24-
arbitrum,
25-
treasure,
26-
arbitrumNova,
27-
sepolia,
28-
]}
29-
accountAbstraction={{
30-
chain: base,
31-
sponsorGas: true,
32-
}}
20+
chains={[base, defineChain(466), arbitrum, treasure, arbitrumNova]}
3321
supportedTokens={{
3422
466: [
3523
{
@@ -57,23 +45,9 @@ export function StyledPayEmbedPreview() {
5745
},
5846
],
5947
}}
60-
detailsButton={{
61-
displayBalanceToken: {
62-
466: "0x675C3ce7F43b00045a4Dab954AF36160fb57cB45",
63-
8453: getDefaultToken(base, "USDC")?.address ?? "",
64-
42161: "0x539bde0d7dbd336b79148aa742883198bbf60342",
65-
[arbitrumNova.id]: "0xb5130f4767ab0acc579f25a76e8f9e977cb3f948",
66-
},
67-
}}
6848
/>
6949
<div className="h-10" />
7050
<PayEmbed
71-
connectOptions={{
72-
accountAbstraction: {
73-
chain: base,
74-
sponsorGas: true,
75-
},
76-
}}
7751
client={THIRDWEB_CLIENT}
7852
theme={theme === "light" ? "light" : "dark"}
7953
payOptions={{

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export type PayEmbedProps = {
130130
*/
131131
hiddenWallets?: WalletId[];
132132

133+
/**
134+
* The wallet that should be pre-selected in the PayEmbed UI.
135+
*/
136+
activeWallet?: Wallet;
137+
133138
style?: React.CSSProperties;
134139

135140
className?: string;
@@ -308,6 +313,12 @@ export function PayEmbed(props: PayEmbedProps) {
308313
}
309314
}, [props.connectOptions?.chains, connectionManager]);
310315

316+
useEffect(() => {
317+
if (props.activeWallet) {
318+
connectionManager.setActiveWallet(props.activeWallet);
319+
}
320+
}, [props.activeWallet, connectionManager]);
321+
311322
let content = null;
312323
const metadata =
313324
props.payOptions && "metadata" in props.payOptions

0 commit comments

Comments
 (0)