From e4b68c1e60bf0ca576c4032b9c9f8915c674fb28 Mon Sep 17 00:00:00 2001 From: cussone Date: Thu, 3 Oct 2024 16:33:53 +0200 Subject: [PATCH] chore: add jsDocs to exported methods --- src/hooks/useStarknetkitConnectModal.ts | 15 ++++++++++ src/main.ts | 37 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/hooks/useStarknetkitConnectModal.ts b/src/hooks/useStarknetkitConnectModal.ts index 68c1354..186d43c 100644 --- a/src/hooks/useStarknetkitConnectModal.ts +++ b/src/hooks/useStarknetkitConnectModal.ts @@ -5,6 +5,21 @@ type UseStarknetkitConnectors = { starknetkitConnectModal: () => Promise } +/** + * @description React hook that abstracts {@link connect} function + * + * @param [modalMode="canAsk"] - Choose connection behavior: + * - "canAsk" - Connect silently if possible, if not prompt a user with the modal + * - "alwaysAsk" - Always prompt a user with the modal + * - "neverAsk" - Connect silently if possible, if not fail gracefully + * @param [storeVersion=Current browser] - Name of the targeted store extension (chrome, firefox, or edge); It will select current browser by default + * @param [modalTheme] - Theme color + * @param [dappName] - Name of your dapp, displayed in the modal + * @param [resultType="wallet"] - It will by default return selected wallet's connector by default, otherwise null + * @param [connectors] - Array of wallet connectors to show in the modal + * + * @returns starknetkitConnectModal - connect function ready for invoking + */ const useStarknetkitConnectModal = ( options?: ConnectOptionsWithConnectors, ): UseStarknetkitConnectors => { diff --git a/src/main.ts b/src/main.ts index a99cbe3..57e0fa8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,34 @@ import type { let selectedConnector: StarknetkitConnector | null = null + +/** + * + * @param [modalMode="canAsk"] - Choose connection behavior: + * - "canAsk" - Connect silently if possible, if not prompt a user with the modal + * - "alwaysAsk" - Always prompt a user with the modal + * - "neverAsk" - Connect silently if possible, if not fail gracefully + * @param [storeVersion=Current browser] - Name of the targeted store extension (chrome, firefox, or edge); It will select current browser by default + * @param [modalTheme] - Theme color + * @param [dappName] - Name of your dapp, displayed in the modal + * @param [resultType="wallet"] - It will by default return selected wallet's connector by default, otherwise null + * @param [connectors] - Array of wallet connectors to show in the modal + * @param [webWalletUrl="https://web.argent.xyz"] - Link to Argent's web wallet - Mainnet env by default, if as a dApp for integration and testing purposes, you need access to an internal testnet environment, please contact Argent + * @param [argentMobileOptions] - Argent Mobile connector options - used only when `connectors` is not explicitly passed + * @param [argentMobileOptions.dappName] - Name of the dapp + * @param [argentMobileOptions.projectId] - WalletConnect project id + * @param [argentMobileOptions.chainId] - Starknet chain ID (SN_MAIN or SN_SEPOLIA) + * @param [argentMobileOptions.description] - Dapp description + * @param [argentMobileOptions.url] - Dapp url + * @param [argentMobileOptions.icons] - Icon to show in the modal + * @param [argentMobileOptions.rpcUrl] - Custom RPC url + * + * @returns { + * wallet: Selected wallet or null, + * connectorData: Selected account and chain ID, or null + * connector: Selected connector + * } + */ export const connect = async ({ modalMode = "canAsk", storeVersion = getStoreVersionFromBrowser(), @@ -172,10 +200,17 @@ export const connect = async ({ }) } -// Should be used after a sucessful connect +/** + * @returns Selected wallet if user was previously successfully connected, otherwise null + */ export const getSelectedConnectorWallet = () => selectedConnector ? selectedConnector.wallet : null +/** + * + * @param [options] - Options + * @param [options.clearLastWallet] - Clear last connected wallet + */ export const disconnect = async (options: DisconnectOptions = {}) => { removeStarknetLastConnectedWallet() if (selectedConnector) {