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

remove parseEther from useScaffoldContractWrite #548

Merged
merged 4 commits into from
Oct 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import { CopyIcon } from "./assets/CopyIcon";
import { DiamondIcon } from "./assets/DiamondIcon";
import { HareIcon } from "./assets/HareIcon";
import { parseEther } from "viem";
import { ArrowSmallRightIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { useScaffoldContractWrite } from "~~/hooks/scaffold-eth";

Expand All @@ -13,7 +14,7 @@ export const ContractInteraction = () => {
contractName: "YourContract",
functionName: "setGreeting",
args: [newGreeting],
value: "0.01",
value: parseEther("0.01"),
onBlockConfirmation: txnReceipt => {
console.log("📦 Transaction blockHash", txnReceipt.blockHash);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from "react";
import { Abi, ExtractAbiFunctionNames } from "abitype";
import { parseEther } from "viem";
import { useContractWrite, useNetwork } from "wagmi";
import { getParsedError } from "~~/components/scaffold-eth";
import { useDeployedContractInfo, useTransactor } from "~~/hooks/scaffold-eth";
Expand Down Expand Up @@ -41,7 +40,7 @@ export const useScaffoldContractWrite = <
abi: deployedContractData?.abi as Abi,
functionName: functionName as any,
args: args as unknown[],
value: value ? parseEther(value) : undefined,
value: value,
...writeConfig,
});

Expand Down Expand Up @@ -73,7 +72,7 @@ export const useScaffoldContractWrite = <
() =>
wagmiContractWrite.writeAsync({
args: newArgs ?? args,
value: newValue ? parseEther(newValue) : value && parseEther(value),
value: newValue ?? value,
...otherConfig,
}),
{ onBlockConfirmation, blockConfirmations },
Expand Down
19 changes: 3 additions & 16 deletions packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ type UseScaffoldArgsParam<
args?: never;
};

type ExtractStateMutability<
TContractName extends ContractName,
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>, WriteAbiStateMutability>,
> = Extract<
ContractAbi<TContractName>[number],
{
name: TFunctionName;
stateMutability: string;
}
>["stateMutability"];

export type UseScaffoldReadConfig<
TContractName extends ContractName,
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>, ReadAbiStateMutability>,
Expand All @@ -154,13 +143,11 @@ export type UseScaffoldWriteConfig<
onBlockConfirmation?: (txnReceipt: TransactionReceipt) => void;
blockConfirmations?: number;
} & IsContractDeclarationMissing<
Partial<Omit<UseContractWriteConfig, "value"> & { value: `${number}` }>,
(ExtractStateMutability<TContractName, TFunctionName> extends "payable"
? { value: `${number}` }
: { value?: never }) & {
Partial<UseContractWriteConfig>,
{
functionName: TFunctionName;
} & UseScaffoldArgsParam<TContractName, TFunctionName> &
Omit<UseContractWriteConfig, "chainId" | "abi" | "address" | "functionName" | "args" | "value" | "mode">
Omit<UseContractWriteConfig, "chainId" | "abi" | "address" | "functionName" | "args" | "mode">
>;

export type UseScaffoldEventConfig<
Expand Down