diff --git a/.changeset/three-donuts-sniff.md b/.changeset/three-donuts-sniff.md new file mode 100644 index 00000000..864e711f --- /dev/null +++ b/.changeset/three-donuts-sniff.md @@ -0,0 +1,5 @@ +--- +'@web3-ui/hooks': minor +--- + +Added docstring to the `useContract` and `useTokenBalance` hooks diff --git a/packages/hooks/src/hooks/useContract.ts b/packages/hooks/src/hooks/useContract.ts index 43817662..7342611a 100644 --- a/packages/hooks/src/hooks/useContract.ts +++ b/packages/hooks/src/hooks/useContract.ts @@ -2,6 +2,7 @@ import React from 'react'; import { Web3Context } from '../Provider'; import { Contract, ContractInterface } from 'ethers'; + /** * @description * Defines the contract instance on `useState` hook @@ -17,6 +18,15 @@ export type UseContractHook = [ boolean ]; +/** + * Gets an instance of a contract from its ABI and address. + * @param address contract address + * @param abi contract ABI + * @returns { + * contract: An instance of the current contract + * isReady: True when the contract is ready to use, false otherwise. + * } + */ export function useContract( address: string, abi: ContractInterface diff --git a/packages/hooks/src/hooks/useTokenBalance.ts b/packages/hooks/src/hooks/useTokenBalance.ts index c869b09d..7aed54c1 100644 --- a/packages/hooks/src/hooks/useTokenBalance.ts +++ b/packages/hooks/src/hooks/useTokenBalance.ts @@ -9,6 +9,20 @@ interface Props { accountAddress: string; } +/** + * Gets the token balance of the provided account. + * @param tokenAddress Address of the token + * @param accountAddress Address of the account + * @returns { + * balance: gives account balance for the token in Wei as a string + * loading: True until the transaction is executing, false otherwise + * error: Contains the error object if the transaction failed, null otherwise. + * decimals: number of decimals the token contract is using + * formattedBalance: Balance in ethers eg. 0.01 ETH, 20 GTC, etc. + * balanceInBigNumber: Balance in BigNumber + * } + */ + export function useTokenBalance({ tokenAddress, accountAddress }: Props) { const context = useContext(Web3Context); const provider = context?.provider; @@ -46,6 +60,6 @@ export function useTokenBalance({ tokenAddress, accountAddress }: Props) { error, decimals, formattedBalance: balance && ethers.utils.formatUnits(balance, decimals), // The balance in ethers eg. 0.01 ETH, 20 GTC, etc. - balanceInBigNumber: balance, + balanceInBigNumber: balance }; }