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

added docstring to usecontract and use token balance hooks #216

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
5 changes: 5 additions & 0 deletions .changeset/three-donuts-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web3-ui/hooks': minor
---

Added docstring to the `useContract` and `useTokenBalance` hooks
10 changes: 10 additions & 0 deletions packages/hooks/src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,15 @@ export type UseContractHook<T extends Contract> = [
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<T extends Contract>(
address: string,
abi: ContractInterface
Expand Down
16 changes: 15 additions & 1 deletion packages/hooks/src/hooks/useTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
}