Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Dec 7, 2024
1 parent 43fbcac commit a2ffb68
Show file tree
Hide file tree
Showing 4 changed files with 54 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 @@ -327,6 +327,13 @@ export type ConnectButton_detailsModalOptions = {
* Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
*/
showBalanceInFiat?: SupportedFiatCurrency;

/**
*
* @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
20 changes: 20 additions & 0 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,9 @@ export function DetailsModal(props: {
setOpen={(_open) => {
if (!_open) {
closeModal();
if (props.detailsModal?.onClose) {
props.detailsModal?.onClose(screen);
}

Check warning on line 1089 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#L1088-L1089

Added lines #L1088 - L1089 were not covered by tests
}
}}
>
Expand Down Expand Up @@ -1614,12 +1617,19 @@ export type UseWalletDetailsModalOptions = {
* Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
*/
showBalanceInFiat?: SupportedFiatCurrency;

/**
* The callback function for when the modal is closed
* @param screen The name of the screen that was being shown when user closed the modal
*/
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 @@ -1638,6 +1648,15 @@ export type UseWalletDetailsModalOptions = {
* return <button onClick={handleClick}> Show Wallet Details </button>
* }
* ```
*
* ### Callback for when the modal is closed
* ```tsx
* detailsModal.open({
* client,
* onClose: (screen: string) => console.log({ screen })
* });
* ```
*
* @wallet
*/
export function useWalletDetailsModal() {
Expand Down Expand Up @@ -1672,6 +1691,7 @@ export function useWalletDetailsModal() {
hideReceiveFunds: props.hideReceiveFunds,
hideSendFunds: props.hideSendFunds,
assetTabs: props.assetTabs,
onClose: props.onClose,

Check warning on line 1694 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#L1694

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

0 comments on commit a2ffb68

Please sign in to comment.