Skip to content

Commit 40f0412

Browse files
[SDK] Add all connected wallets in onConnect callbacks
1 parent e26d81c commit 40f0412

File tree

13 files changed

+52
-31
lines changed

13 files changed

+52
-31
lines changed

.changeset/fair-mails-divide.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 all connected wallets in all onConnect callbacks

apps/playground-web/src/components/in-app-wallet/ecosystem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ const getEcosystemWallet = () => {
1919
export function EcosystemConnectEmbed(
2020
props?: Omit<ConnectButtonProps, "client" | "theme">,
2121
) {
22-
return <StyledConnectEmbed {...props} wallets={[getEcosystemWallet()]} />;
22+
return <StyledConnectEmbed {...props} wallets={[getEcosystemWallet()]} onConnect={} />;
2323
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,14 @@ export type ConnectButtonProps = {
937937
*
938938
* ```tsx
939939
* <ConnectButton
940-
* onConnect={(wallet) => {
941-
* console.log("connected to", wallet)
940+
* onConnect={(activeWallet, otherWallets) => {
941+
* console.log("connected to", activeWallet)
942+
* console.log("other wallets that were also connected", otherWallets)
942943
* }}
943944
* />
944945
* ```
945946
*/
946-
onConnect?: (wallet: Wallet) => void;
947+
onConnect?: (activeWallet: Wallet, otherWallets: Wallet[]) => void;
947948

948949
/**
949950
* Called when the user disconnects the wallet by clicking on the "Disconnect Wallet" button in the `ConnectButton`'s Details Modal.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,15 @@ export type ConnectEmbedProps = {
213213
*
214214
* ```tsx
215215
* <ConnectEmbed
216-
* onConnect={(wallet) => {
217-
* console.log("connected to", wallet)
216+
* onConnect={(activeWallet, otherWallets) => {
217+
* console.log("connected to", activeWallet)
218+
* console.log("other wallets that were also connected", otherWallets)
218219
* }}
219220
* />
220221
* ```
221222
* ```
222223
*/
223-
onConnect?: (wallet: Wallet) => void;
224+
onConnect?: (activeWallet: Wallet, otherWallets: Wallet[]) => void;
224225

225226
/**
226227
* By default, A "Powered by Thirdweb" branding is shown at the bottom of the embed.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
2+
3+
export type OnConnectCallback = (activeWallet: Wallet, otherWallets: Wallet[]) => void;

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type { ConnectLocale } from "../locale/types.js";
4040
import type { WelcomeScreen } from "../screens/types.js";
4141
import { ConnectModalContent } from "./ConnectModalContent.js";
4242
import { useSetupScreen } from "./screen.js";
43+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
4344

4445
/**
4546
* An inline wallet connection component that allows to:
@@ -354,7 +355,7 @@ const ConnectEmbedContent = (props: {
354355
| true
355356
| undefined;
356357
localeId: LocaleId;
357-
onConnect: ((wallet: Wallet) => void) | undefined;
358+
onConnect: OnConnectCallback | undefined;
358359
recommendedWallets: Wallet[] | undefined;
359360
showAllWallets: boolean | undefined;
360361
hiddenWallets: WalletId[] | undefined;

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import type { ConnectLocale } from "../locale/types.js";
1919
import type { WelcomeScreen } from "../screens/types.js";
2020
import { ConnectModalContent } from "./ConnectModalContent.js";
2121
import { useSetupScreen } from "./screen.js";
22+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
2223

2324
type ConnectModalOptions = {
2425
onClose?: () => void;
2526
shouldSetActive: boolean;
2627
wallets: Wallet[];
2728
accountAbstraction: SmartWalletOptions | undefined;
2829
auth: SiweAuthOptions | undefined;
29-
onConnect: ((wallet: Wallet) => void) | undefined;
30+
onConnect: OnConnectCallback | undefined;
3031
size: "compact" | "wide";
3132
welcomeScreen: WelcomeScreen | undefined;
3233
meta: {

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectModalContent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "./ConnectModalSkeleton.js";
2929
import { SmartConnectUI } from "./SmartWalletConnectUI.js";
3030
import { type ScreenSetup, ScreenSetupContext } from "./screen.js";
31+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
3132

3233
const AllWalletsUI = /* @__PURE__ */ lazy(() => import("./AllWalletsUI.js"));
3334

@@ -43,7 +44,7 @@ export const ConnectModalContent = (props: {
4344
wallets: Wallet[];
4445
accountAbstraction: SmartWalletOptions | undefined;
4546
auth: SiweAuthOptions | undefined;
46-
onConnect: ((wallet: Wallet) => void) | undefined;
47+
onConnect: OnConnectCallback | undefined;
4748
size: "compact" | "wide";
4849
meta: {
4950
title?: string;
@@ -93,7 +94,7 @@ export const ConnectModalContent = (props: {
9394
}
9495

9596
if (props.onConnect) {
96-
props.onConnect(wallet);
97+
props.onConnect(wallet, connectionManager.connectedWallets.getValue());
9798
}
9899

99100
onModalUnmount(() => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getConnectLocale } from "./locale/getConnectLocale.js";
1616
import type { ConnectLocale } from "./locale/types.js";
1717
import ConnectModal from "./Modal/ConnectModal.js";
1818
import type { WelcomeScreen } from "./screens/types.js";
19+
import type { OnConnectCallback } from "../../../core/hooks/connection/types.js";
1920

2021
/**
2122
* hook that allows you to open the Connect UI in a Modal to prompt the user to connect wallet.
@@ -90,7 +91,7 @@ export function useConnectModal() {
9091

9192
function Modal(
9293
props: UseConnectModalOptions & {
93-
onConnect: (wallet: Wallet) => void;
94+
onConnect: OnConnectCallback;
9495
onClose: () => void;
9596
connectLocale: ConnectLocale;
9697
},

packages/thirdweb/src/wallets/connection/autoConnect.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import type { AutoConnectProps } from "./types.js";
1717
*
1818
* const autoConnected = await autoConnect({
1919
* client,
20-
* onConnect: (wallet) => {
21-
* console.log("wallet", wallet);
20+
* onConnect: (activeWallet, allConnectedWallets) => {
21+
* console.log("active wallet", activeWallet);
22+
* console.log("all connected wallets", allConnectedWallets);
2223
* },
2324
* });
2425
* ```

0 commit comments

Comments
 (0)