Skip to content

Commit ece14b2

Browse files
Redarcher9Snehit Paunikarwith-heartDhaiwat10
authored
Add docstrings for useContract and useTokenBalance hooks (#216)
* added docstring to usecontract and use token balance hooks * added docstring to usecontract and usetokenbalance hooks * Added requested changes * Added requested changes * Delete rude chefs love.md * Delete vscode directory * Update packages/hooks/src/hooks/useTokenBalance.ts Co-authored-by: with-heart <[email protected]> * Update .changeset/three-donuts-sniff.md Co-authored-by: with-heart <[email protected]> * Update packages/hooks/src/hooks/useContract.ts Co-authored-by: with-heart <[email protected]> * Update packages/hooks/src/hooks/useContract.ts Co-authored-by: with-heart <[email protected]> * Update useTokenBalance.ts Co-authored-by: Snehit Paunikar <[email protected]> Co-authored-by: with-heart <[email protected]> Co-authored-by: Dhaiwat Pandya <[email protected]>
1 parent 1c01073 commit ece14b2

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.changeset/three-donuts-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web3-ui/hooks': minor
3+
---
4+
5+
Added docstring to the `useContract` and `useTokenBalance` hooks

packages/hooks/src/hooks/useContract.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Web3Context } from '../Provider';
33
import { Contract, ContractInterface } from 'ethers';
44

5+
56
/**
67
* @description
78
* Defines the contract instance on `useState` hook
@@ -17,6 +18,15 @@ export type UseContractHook<T extends Contract> = [
1718
boolean
1819
];
1920

21+
/**
22+
* Gets an instance of a contract from its ABI and address.
23+
* @param address contract address
24+
* @param abi contract ABI
25+
* @returns {
26+
* contract: An instance of the current contract
27+
* isReady: True when the contract is ready to use, false otherwise.
28+
* }
29+
*/
2030
export function useContract<T extends Contract>(
2131
address: string,
2232
abi: ContractInterface

packages/hooks/src/hooks/useTokenBalance.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ interface Props {
99
accountAddress: string;
1010
}
1111

12+
/**
13+
* Gets the token balance of the provided account.
14+
* @param tokenAddress Address of the token
15+
* @param accountAddress Address of the account
16+
* @returns {
17+
* balance: gives account balance for the token in Wei as a string
18+
* loading: True until the transaction is executing, false otherwise
19+
* error: Contains the error object if the transaction failed, null otherwise.
20+
* decimals: number of decimals the token contract is using
21+
* formattedBalance: Balance in ethers eg. 0.01 ETH, 20 GTC, etc.
22+
* balanceInBigNumber: Balance in BigNumber
23+
* }
24+
*/
25+
1226
export function useTokenBalance({ tokenAddress, accountAddress }: Props) {
1327
const context = useContext(Web3Context);
1428
const provider = context?.provider;
@@ -46,6 +60,6 @@ export function useTokenBalance({ tokenAddress, accountAddress }: Props) {
4660
error,
4761
decimals,
4862
formattedBalance: balance && ethers.utils.formatUnits(balance, decimals), // The balance in ethers eg. 0.01 ETH, 20 GTC, etc.
49-
balanceInBigNumber: balance,
63+
balanceInBigNumber: balance
5064
};
5165
}

0 commit comments

Comments
 (0)