Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Dec 4, 2024
1 parent 9d8ecce commit d15a998
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .changeset/metal-mails-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"thirdweb": patch
---

Add onClose callback to Connect Details modal

```tsx
<ConnectButton
detailsModal={{
onClose: (screen: string) => {
// The last screen name that was being shown when user closed the modal
console.log({ screen });
}
}}
/>
```
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ export type ConnectButton_detailsModalOptions = {
* Note: If an empty array is passed, the [View Funds] button will be hidden
*/
assetTabs?: AssetTabs[];
/**
*
* @param screen The screen's name that was last shown when user closed the modal
* @returns
*/
onClose?: (screen: string) => void;
};

/**
Expand Down
11 changes: 11 additions & 0 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ const TW_CONNECT_WALLET = "tw-connect-wallet";
* />
* ```
*
* ### Callback for when the details modal is closed
* ```tsx
* <ConnectButton
* detailsModal={{
* onClose: (screen: string) => {
* console.log({ screen });
* }
* }}
* />
* ```
*
* @param props
* Props for the `ConnectButton` component
*
Expand Down
16 changes: 16 additions & 0 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ function DetailsModal(props: {
setOpen={(_open) => {
if (!_open) {
closeModal();
if (props.detailsModal?.onClose) {
props.detailsModal?.onClose(screen);
}

Check warning on line 995 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L993-L995

Added lines #L993 - L995 were not covered by tests
}
}}
>
Expand Down Expand Up @@ -1507,12 +1510,15 @@ export type UseWalletDetailsModalOptions = {
* Note: If an empty array is passed, the [View Funds] button will be hidden
*/
assetTabs?: AssetTabs[];

onClose?: (screen: string) => void;
};

/**
* 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.
*
* @example
* ### Basic usage
* ```tsx
* import { createThirdwebClient } from "thirdweb";
* import { useWalletDetailsModal } from "thirdweb/react";
Expand All @@ -1531,6 +1537,15 @@ export type UseWalletDetailsModalOptions = {
* return <button onClick={handleClick}> Show Wallet Details </button>
* }
* ```
*
* ### Callback for when the modal is closed
* ```tsx
* detailsModal.open({
* client,
* onClose
* });
* ```
*
* @wallet
*/
export function useWalletDetailsModal() {
Expand Down Expand Up @@ -1565,6 +1580,7 @@ export function useWalletDetailsModal() {
hideReceiveFunds: props.hideReceiveFunds,
hideSendFunds: props.hideSendFunds,
assetTabs: props.assetTabs,
onClose: props.onClose,

Check warning on line 1583 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1583 was not covered by tests
}}
displayBalanceToken={props.displayBalanceToken}
theme={props.theme || "dark"}
Expand Down

0 comments on commit d15a998

Please sign in to comment.