Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: add jsDocs to exported methods #137

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/hooks/useStarknetkitConnectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ type UseStarknetkitConnectors = {
starknetkitConnectModal: () => Promise<ModalResult>
}

/**
* @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 => {
Expand Down
37 changes: 36 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down