Skip to content

Commit 1822370

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

File tree

14 files changed

+61
-30
lines changed

14 files changed

+61
-30
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

packages/thirdweb/src/exports/react.native.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ export type {
1717
ConnectButton_detailsButtonOptions,
1818
ConnectButton_detailsModalOptions,
1919
ConnectButtonProps,
20+
DirectPaymentOptions,
21+
FundWalletOptions,
22+
PaymentInfo,
23+
PayUIOptions,
24+
TransactionOptions,
2025
} from "../react/core/hooks/connection/ConnectButtonProps.js";
26+
export type { ConnectEmbedProps } from "../react/core/hooks/connection/ConnectEmbedProps.js";
27+
export type { OnConnectCallback } from "../react/core/hooks/connection/types.js";
2128
export { useContractEvents } from "../react/core/hooks/contract/useContractEvents.js";
2229
// contract
2330
export { useReadContract } from "../react/core/hooks/contract/useReadContract.js";

packages/thirdweb/src/exports/react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type {
2323
TransactionOptions,
2424
} from "../react/core/hooks/connection/ConnectButtonProps.js";
2525
export type { ConnectEmbedProps } from "../react/core/hooks/connection/ConnectEmbedProps.js";
26+
export type { OnConnectCallback } from "../react/core/hooks/connection/types.js";
2627
export { useContractEvents } from "../react/core/hooks/contract/useContractEvents.js";
2728
// contract
2829
export { useReadContract } from "../react/core/hooks/contract/useReadContract.js";

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
TokenInfo,
2626
} from "../../utils/defaultTokens.js";
2727
import type { SiweAuthOptions } from "../auth/useSiweAuth.js";
28+
import type { OnConnectCallback } from "./types.js";
2829

2930
export type PaymentInfo = Prettify<
3031
{
@@ -937,13 +938,14 @@ export type ConnectButtonProps = {
937938
*
938939
* ```tsx
939940
* <ConnectButton
940-
* onConnect={(wallet) => {
941-
* console.log("connected to", wallet)
941+
* onConnect={(activeWallet, allConnectedWallets) => {
942+
* console.log("connected to", activeWallet)
943+
* console.log("all connected wallets", allConnectedWallets)
942944
* }}
943945
* />
944946
* ```
945947
*/
946-
onConnect?: (wallet: Wallet) => void;
948+
onConnect?: OnConnectCallback;
947949

948950
/**
949951
* 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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { WelcomeScreen } from "../../../web/ui/ConnectWallet/screens/types.
88
import type { LocaleId } from "../../../web/ui/types.js";
99
import type { Theme } from "../../design-system/index.js";
1010
import type { SiweAuthOptions } from "../auth/useSiweAuth.js";
11+
import type { OnConnectCallback } from "./types.js";
1112

1213
export type ConnectEmbedProps = {
1314
/**
@@ -213,14 +214,15 @@ export type ConnectEmbedProps = {
213214
*
214215
* ```tsx
215216
* <ConnectEmbed
216-
* onConnect={(wallet) => {
217-
* console.log("connected to", wallet)
217+
* onConnect={(activeWallet, allConnectedWallets) => {
218+
* console.log("connected to", activeWallet)
219+
* console.log("all connected wallets", allConnectedWallets)
218220
* }}
219221
* />
220222
* ```
221223
* ```
222224
*/
223-
onConnect?: (wallet: Wallet) => void;
225+
onConnect?: OnConnectCallback;
224226

225227
/**
226228
* 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
},

0 commit comments

Comments
 (0)