Skip to content

Commit d15a998

Browse files
committed
update
1 parent 9d8ecce commit d15a998

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

.changeset/metal-mails-ring.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add onClose callback to Connect Details modal
6+
7+
```tsx
8+
<ConnectButton
9+
detailsModal={{
10+
onClose: (screen: string) => {
11+
// The last screen name that was being shown when user closed the modal
12+
console.log({ screen });
13+
}
14+
}}
15+
/>
16+
```

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ export type ConnectButton_detailsModalOptions = {
320320
* Note: If an empty array is passed, the [View Funds] button will be hidden
321321
*/
322322
assetTabs?: AssetTabs[];
323+
/**
324+
*
325+
* @param screen The screen's name that was last shown when user closed the modal
326+
* @returns
327+
*/
328+
onClose?: (screen: string) => void;
323329
};
324330

325331
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ const TW_CONNECT_WALLET = "tw-connect-wallet";
262262
* />
263263
* ```
264264
*
265+
* ### Callback for when the details modal is closed
266+
* ```tsx
267+
* <ConnectButton
268+
* detailsModal={{
269+
* onClose: (screen: string) => {
270+
* console.log({ screen });
271+
* }
272+
* }}
273+
* />
274+
* ```
275+
*
265276
* @param props
266277
* Props for the `ConnectButton` component
267278
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ function DetailsModal(props: {
990990
setOpen={(_open) => {
991991
if (!_open) {
992992
closeModal();
993+
if (props.detailsModal?.onClose) {
994+
props.detailsModal?.onClose(screen);
995+
}
993996
}
994997
}}
995998
>
@@ -1507,12 +1510,15 @@ export type UseWalletDetailsModalOptions = {
15071510
* Note: If an empty array is passed, the [View Funds] button will be hidden
15081511
*/
15091512
assetTabs?: AssetTabs[];
1513+
1514+
onClose?: (screen: string) => void;
15101515
};
15111516

15121517
/**
15131518
* Hook to open the Wallet Details Modal that shows various information about the connected wallet and allows users to perform various actions like sending funds, receiving funds, switching networks, Buying tokens, etc.
15141519
*
15151520
* @example
1521+
* ### Basic usage
15161522
* ```tsx
15171523
* import { createThirdwebClient } from "thirdweb";
15181524
* import { useWalletDetailsModal } from "thirdweb/react";
@@ -1531,6 +1537,15 @@ export type UseWalletDetailsModalOptions = {
15311537
* return <button onClick={handleClick}> Show Wallet Details </button>
15321538
* }
15331539
* ```
1540+
*
1541+
* ### Callback for when the modal is closed
1542+
* ```tsx
1543+
* detailsModal.open({
1544+
* client,
1545+
* onClose
1546+
* });
1547+
* ```
1548+
*
15341549
* @wallet
15351550
*/
15361551
export function useWalletDetailsModal() {
@@ -1565,6 +1580,7 @@ export function useWalletDetailsModal() {
15651580
hideReceiveFunds: props.hideReceiveFunds,
15661581
hideSendFunds: props.hideSendFunds,
15671582
assetTabs: props.assetTabs,
1583+
onClose: props.onClose,
15681584
}}
15691585
displayBalanceToken={props.displayBalanceToken}
15701586
theme={props.theme || "dark"}

0 commit comments

Comments
 (0)