Skip to content

Commit d0bbbfd

Browse files
[SDK] Add all connected wallets in onConnect callbacks (#8403)
1 parent e26d81c commit d0bbbfd

File tree

17 files changed

+104
-51
lines changed

17 files changed

+104
-51
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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,17 @@ const getEcosystemWallet = () => {
1919
export function EcosystemConnectEmbed(
2020
props?: Omit<ConnectButtonProps, "client" | "theme">,
2121
) {
22-
return <StyledConnectEmbed {...props} wallets={[getEcosystemWallet()]} />;
22+
return (
23+
<StyledConnectEmbed
24+
{...props}
25+
wallets={[getEcosystemWallet()]}
26+
onConnect={(activeWallet, allConnectedWallets) => {
27+
console.log("active wallet", activeWallet.id);
28+
console.log(
29+
"all connected wallets",
30+
allConnectedWallets.map((wallet) => wallet.id),
31+
);
32+
}}
33+
/>
34+
);
2335
}

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
2+
3+
export type OnConnectCallback = (
4+
activeWallet: Wallet,
5+
allConnectedWallets: Wallet[],
6+
) => 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
@@ -16,6 +16,7 @@ import {
1616
useSiweAuth,
1717
} from "../../../../core/hooks/auth/useSiweAuth.js";
1818
import type { ConnectEmbedProps } from "../../../../core/hooks/connection/ConnectEmbedProps.js";
19+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
1920
import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js";
2021
import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js";
2122
import { useIsAutoConnecting } from "../../../../core/hooks/wallets/useIsAutoConnecting.js";
@@ -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
@@ -6,6 +6,7 @@ import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
66
import type { SmartWalletOptions } from "../../../../../wallets/smart/types.js";
77
import type { WalletId } from "../../../../../wallets/wallet-types.js";
88
import type { SiweAuthOptions } from "../../../../core/hooks/auth/useSiweAuth.js";
9+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
910
import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js";
1011
import {
1112
useIsWalletModalOpen,
@@ -26,7 +27,7 @@ type ConnectModalOptions = {
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
@@ -9,6 +9,7 @@ import {
99
type SiweAuthOptions,
1010
useSiweAuth,
1111
} from "../../../../core/hooks/auth/useSiweAuth.js";
12+
import type { OnConnectCallback } from "../../../../core/hooks/connection/types.js";
1213
import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js";
1314
import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js";
1415
import { useSetActiveWallet } from "../../../../core/hooks/wallets/useSetActiveWallet.js";
@@ -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(() => {

0 commit comments

Comments
 (0)