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

JsDoc cleanup #665

Merged
merged 7 commits into from
Dec 19, 2023
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
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/99_generateTsAbis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This script generates the file containing the contracts Abi definitions.
* These definitions are used to derive the types needed in the custom scaffold-eth hooks, for example.
* This script should run as the last deploy script.
* */
*/

import * as fs from "fs";
import prettier from "prettier";
Expand Down
1 change: 0 additions & 1 deletion packages/hardhat/scripts/generateAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const envFilePath = "./.env";

/**
* Generate a new random private key and write it to the .env file
* @param existingEnvConfig
*/
const setNewEnvConfig = (existingEnvConfig = {}) => {
console.log("👛 Generating new Wallet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import { BaseError as BaseViemError, DecodeErrorResultReturnType } from "viem";

/**
* Generates a key based on function metadata
* @param {string} functionName
* @param {AbiParameter} input - object containing function name and input type corresponding to index
* @param {number} inputIndex
* @returns {string} key
*/
const getFunctionInputKey = (functionName: string, input: AbiParameter, inputIndex: number): string => {
const name = input?.name || `input_${inputIndex}_`;
return functionName + "_" + name + "_" + input.internalType + "_" + input.type;
};

/**
* Parses an error to get a displayable string
* Parses an viem/wagmi error to get a displayable string
* @param e - error object
* @returns {string} parsed error string
* @returns parsed error string
*/
const getParsedError = (e: any): string => {
let message: string = e.message ?? "An unknown error occurred";
Expand Down Expand Up @@ -48,8 +44,6 @@ const ARRAY_TYPE_REGEX = /\[.*\]$/;

/**
* Parses form input with array support
* @param {Record<string,any>} form - form object containing key value pairs
* @returns parsed error string
*/
const getParsedContractFunctionArgs = (form: Record<string, any>) => {
const keys = Object.keys(form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { usePublicClient } from "wagmi";
import { Contract, ContractCodeStatus, ContractName, contracts } from "~~/utils/scaffold-eth/contract";

/**
* Gets the matching contract info from the contracts file generated by `yarn deploy`
* @param contractName - name of deployed contract
* Gets the matching contract info for the provided contract name from the contracts present in deployedContracts.ts and externalContracts.ts corrsponding to targetNetworks configured in scaffold.congfig.ts
*/
export const useDeployedContractInfo = <TContractName extends ContractName>(contractName: TContractName) => {
const isMounted = useIsMounted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const enablePolling = false;

/**
* Get the price of Native Currency based on Native Token/DAI trading pair from Uniswap SDK
* @returns nativeCurrencyPrice: number
*/
export const useNativeCurrencyPrice = () => {
const { targetNetwork } = useTargetNetwork();
Expand Down
4 changes: 3 additions & 1 deletion packages/nextjs/hooks/scaffold-eth/useOutsideClick.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useEffect } from "react";

/**
* Check if a click was made outside the passed ref
* Handles clicks outside of passed ref element
* @param ref - react ref of the element
* @param callback - callback function to call when clicked outside
*/
export const useOutsideClick = (ref: React.RefObject<HTMLElement>, callback: { (): void }) => {
useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useDeployedContractInfo } from "~~/hooks/scaffold-eth";
import { Contract, ContractName } from "~~/utils/scaffold-eth/contract";

/**
* Gets a deployed contract by contract name and returns a contract instance
* @param config - The config settings
* @param config.contractName - Deployed contract name
* @param config.walletClient - An viem wallet client instance (optional)
* Gets an viem instance of the contract present in deployedContracts.ts or externalContracts.ts corrsponding to targetNetworks configured in scaffold.congfig.ts. Optional walletClient can be passed for doing write transactions.
* @param config - The config settings for the hook
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
* @param config.contractName - deployed contract name
* @param config.walletClient - optional walletClient from wagmi useWalletClient hook can be passed for doing write transactions
*/
export const useScaffoldContract = <
TContractName extends ContractName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
} from "~~/utils/scaffold-eth/contract";

/**
* Wrapper for wagmi's useContractRead hook which automatically loads (by name)
* the contract ABI and address from the deployed contracts
* Wrapper around wagmi's useContractRead hook which automatically loads (by name) the contract ABI and address from the contracts present in deployedContracts.ts & externalContracts.ts corrsponding to targetNetworks configured in scaffold.congfig.ts
* @param config - The config settings, including extra wagmi configuration
* @param config.contractName - deployed contract name
* @param config.functionName - name of the function to be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { ContractAbi, ContractName, UseScaffoldWriteConfig } from "~~/utils/scaf
type UpdatedArgs = Parameters<ReturnType<typeof useContractWrite<Abi, string, undefined>>["writeAsync"]>[0];

/**
* Wrapper for wagmi's useContractWrite hook (with config prepared by usePrepareContractWrite hook)
* which automatically loads (by name) the contract ABI and address from the deployed contracts
* Wrapper around wagmi's useContractWrite hook which automatically loads (by name) the contract ABI and address from the contracts present in deployedContracts.ts & externalContracts.ts corrsponding to targetNetworks configured in scaffold.congfig.ts
* @param config - The config settings, including extra wagmi configuration
* @param config.contractName - deployed contract name
* @param config.contractName - contract name
* @param config.functionName - name of the function to be called
* @param config.args - arguments for the function
* @param config.value - value in ETH that will be sent with transaction
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
* @param config.blockConfirmations - number of block confirmations to wait for (default: 1)
* @param config.onBlockConfirmation - callback that will be called after blockConfirmations.
*/
export const useScaffoldContractWrite = <
TContractName extends ContractName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { addIndexedArgsToEvent, useDeployedContractInfo } from "~~/hooks/scaffol
import { ContractAbi, ContractName, UseScaffoldEventConfig } from "~~/utils/scaffold-eth/contract";

/**
* Wrapper for wagmi's useContractEvent which automatically loads (by name)
* the contract ABI and address from the deployed contracts.
* Wrapper around wagmi's useEventSubscriber hook which automatically loads (by name) the contract ABI and address from the contracts present in deployedContracts.ts & externalContracts.ts
* @param config - The config settings
* @param config.contractName - deployed contract name
* @param config.eventName - name of the event to listen for
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { useGlobalState } from "~~/services/store/store";
import { ChainWithAttributes } from "~~/utils/scaffold-eth";
import { NETWORKS_EXTRA_DATA } from "~~/utils/scaffold-eth";

/**
* Retrieves the connected wallet's network from scaffold.config or defaults to the 0th network in the list if the wallet is not connected.
*/
export function useTargetNetwork(): { targetNetwork: ChainWithAttributes } {
const { chain } = useNetwork();
const targetNetwork = useGlobalState(({ targetNetwork }) => targetNetwork);
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/hooks/scaffold-eth/useTransactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const TxnNotification = ({ message, blockExplorerLink }: { message: string; bloc
};

/**
* @description Runs Transaction passed in to returned function showing UI feedback.
* @param _walletClient
* @returns function that takes a transaction and returns a promise of the transaction hash
* Runs Transaction passed in to returned function showing UI feedback.
* @param _walletClient - Optional wallet client to use. If not provided, will use the one from useWalletClient.
* @returns function that takes in transaction function as callback, shows UI feedback for transcation and returns a promise of the transaction hash
*/
export const useTransactor = (_walletClient?: WalletClient): TransactionFunc => {
let walletClient = _walletClient;
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/services/web3/wagmi-burner/BurnerConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export class BurnerConnector extends Connector<StaticJsonRpcProvider, BurnerConn
readonly ready = true;

private provider?: StaticJsonRpcProvider;
/**
* this is the store for getWallet()
*/

// store for getWallet()
private burnerWallet: WalletClient<HttpTransport, Chain, PrivateKeyAccount> | undefined;

constructor(config: { chains?: Chain[]; options: BurnerConnectorOptions }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const burnerWalletIconBase64 =

/**
* Wagmi config for burner wallet
* @param param0
* @returns
*/
export const burnerWalletConfig = ({ chains }: BurnerWalletOptions): Wallet => ({
id: burnerWalletId,
Expand Down
3 changes: 1 addition & 2 deletions packages/nextjs/utils/scaffold-eth/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ export const NETWORKS_EXTRA_DATA: Record<string, ChainAttributes> = {
};

/**
* Gives the block explorer transaction URL.
* Returns empty string if the network is a local chain
* Gives the block explorer transaction URL, returns empty string if the network is a local chain
*/
export function getBlockExplorerTxLink(chainId: number, txnHash: string) {
const chainNames = Object.keys(chains);
Expand Down