From a2ffb68ce2a7ba9a758b5ed39a77bd96233bde16 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 4 Dec 2024 18:07:06 +0700 Subject: [PATCH] update --- .changeset/metal-mails-ring.md | 16 +++++++++++++++ .../hooks/connection/ConnectButtonProps.ts | 7 +++++++ .../web/ui/ConnectWallet/ConnectButton.tsx | 11 ++++++++++ .../react/web/ui/ConnectWallet/Details.tsx | 20 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 .changeset/metal-mails-ring.md diff --git a/.changeset/metal-mails-ring.md b/.changeset/metal-mails-ring.md new file mode 100644 index 00000000000..fefd88ab93f --- /dev/null +++ b/.changeset/metal-mails-ring.md @@ -0,0 +1,16 @@ +--- +"thirdweb": patch +--- + +Add onClose callback to Connect Details modal + +```tsx + { + // The last screen name that was being shown when user closed the modal + console.log({ screen }); + } + }} +/> +``` \ No newline at end of file diff --git a/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts b/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts index 2a25abd8191..f7b82c48569 100644 --- a/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts +++ b/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts @@ -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; }; /** diff --git a/packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx b/packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx index 31dcf7aa530..4dde6ac5f52 100644 --- a/packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx +++ b/packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx @@ -262,6 +262,17 @@ const TW_CONNECT_WALLET = "tw-connect-wallet"; * /> * ``` * + * ### Callback for when the details modal is closed + * ```tsx + * { + * console.log({ screen }); + * } + * }} + * /> + * ``` + * * @param props * Props for the `ConnectButton` component * diff --git a/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx b/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx index 6aa59573a4d..661127592dd 100644 --- a/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx +++ b/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx @@ -1084,6 +1084,9 @@ export function DetailsModal(props: { setOpen={(_open) => { if (!_open) { closeModal(); + if (props.detailsModal?.onClose) { + props.detailsModal?.onClose(screen); + } } }} > @@ -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"; @@ -1638,6 +1648,15 @@ export type UseWalletDetailsModalOptions = { * return * } * ``` + * + * ### Callback for when the modal is closed + * ```tsx + * detailsModal.open({ + * client, + * onClose: (screen: string) => console.log({ screen }) + * }); + * ``` + * * @wallet */ export function useWalletDetailsModal() { @@ -1672,6 +1691,7 @@ export function useWalletDetailsModal() { hideReceiveFunds: props.hideReceiveFunds, hideSendFunds: props.hideSendFunds, assetTabs: props.assetTabs, + onClose: props.onClose, }} displayBalanceToken={props.displayBalanceToken} theme={props.theme || "dark"}