Skip to content

Commit 069c6e9

Browse files
committed
update
1 parent f69d1aa commit 069c6e9

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ export type ConnectButton_detailsModalOptions = {
327327
* Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
328328
*/
329329
showBalanceInFiat?: SupportedFiatCurrency;
330+
331+
/**
332+
*
333+
* @param screen The screen's name that was last shown when user closed the modal
334+
* @returns
335+
*/
336+
onClose?: (screen: string) => void;
330337
};
331338

332339
/**

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ export function DetailsModal(props: {
10841084
setOpen={(_open) => {
10851085
if (!_open) {
10861086
closeModal();
1087+
if (props.detailsModal?.onClose) {
1088+
props.detailsModal?.onClose(screen);
1089+
}
10871090
}
10881091
}}
10891092
>
@@ -1614,12 +1617,19 @@ export type UseWalletDetailsModalOptions = {
16141617
* Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
16151618
*/
16161619
showBalanceInFiat?: SupportedFiatCurrency;
1620+
1621+
/**
1622+
* The callback function for when the modal is closed
1623+
* @param screen The name of the screen that was being shown when user closed the modal
1624+
*/
1625+
onClose?: (screen: string) => void;
16171626
};
16181627

16191628
/**
16201629
* 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.
16211630
*
16221631
* @example
1632+
* ### Basic usage
16231633
* ```tsx
16241634
* import { createThirdwebClient } from "thirdweb";
16251635
* import { useWalletDetailsModal } from "thirdweb/react";
@@ -1638,6 +1648,15 @@ export type UseWalletDetailsModalOptions = {
16381648
* return <button onClick={handleClick}> Show Wallet Details </button>
16391649
* }
16401650
* ```
1651+
*
1652+
* ### Callback for when the modal is closed
1653+
* ```tsx
1654+
* detailsModal.open({
1655+
* client,
1656+
* onClose: (screen: string) => console.log({ screen })
1657+
* });
1658+
* ```
1659+
*
16411660
* @wallet
16421661
*/
16431662
export function useWalletDetailsModal() {
@@ -1672,6 +1691,7 @@ export function useWalletDetailsModal() {
16721691
hideReceiveFunds: props.hideReceiveFunds,
16731692
hideSendFunds: props.hideSendFunds,
16741693
assetTabs: props.assetTabs,
1694+
onClose: props.onClose,
16751695
}}
16761696
displayBalanceToken={props.displayBalanceToken}
16771697
theme={props.theme || "dark"}

0 commit comments

Comments
 (0)