diff --git a/src/components/dialogs/mint-to-dialog.tsx b/src/components/dialogs/mint-to-dialog.tsx index 4870739..fd48941 100644 --- a/src/components/dialogs/mint-to-dialog.tsx +++ b/src/components/dialogs/mint-to-dialog.tsx @@ -1,7 +1,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import React from "react"; import { useForm } from "react-hook-form"; -import { isAddress, parseUnits } from "viem"; +import { isAddress, parseGwei, parseUnits } from "viem"; import { useAccount, useBalance, useWriteContract } from "wagmi"; import * as z from "zod"; import { abi } from "~/contracts/erc20-demurrage-token/contract"; @@ -55,7 +55,6 @@ const MintToDialog = ({ }); const mintTo = useWriteContract({ config, - mutation: { onError: (error) => { toast.toast({ @@ -76,6 +75,9 @@ const MintToDialog = ({ address: voucher.voucher_address as `0x${string}`, abi: abi, functionName: "mintTo", + gas: 350_000n, + maxFeePerGas: parseGwei("10"), + maxPriorityFeePerGas: 5n, args: [ data.recipientAddress, parseUnits(data.amount.toString() ?? "", balance.data?.decimals ?? 6), diff --git a/src/components/dialogs/send-dialog.tsx b/src/components/dialogs/send-dialog.tsx index 6d426e1..9d7e322 100644 --- a/src/components/dialogs/send-dialog.tsx +++ b/src/components/dialogs/send-dialog.tsx @@ -4,6 +4,7 @@ import { useState } from "react"; import { useForm } from "react-hook-form"; import * as z from "zod"; +import { WriteContractErrorType } from "@wagmi/core"; import React from "react"; import { erc20Abi, getAddress, isAddress, parseGwei, parseUnits } from "viem"; import { @@ -73,9 +74,6 @@ const SendForm = (props: { const { data: simData, error } = useSimulateContract({ address: voucherAddress, abi: erc20Abi, - gas: BigInt(350000), - maxFeePerGas: parseGwei("10"), - maxPriorityFeePerGas: BigInt(5), functionName: "transfer", args: [ deboucedRecipientAddress, @@ -86,6 +84,9 @@ const SendForm = (props: { deboucedAmount && deboucedRecipientAddress && voucherAddress ), }, + gas: 350_000n, + maxFeePerGas: parseGwei("10"), + maxPriorityFeePerGas: 5n, }); const { data: hash, writeContractAsync, isPending } = useWriteContract(); @@ -96,12 +97,23 @@ const SendForm = (props: { }); const handleSubmit = () => { if (simData?.request) { - writeContractAsync?.(simData.request).catch((error: Error) => { - toast.toast({ - title: "Error", - description: error.message, - }); - }); + writeContractAsync?.(simData.request).catch( + (error: WriteContractErrorType) => { + if ( + (error?.cause as { reason?: string })?.reason === "ERR_OVERSPEND" + ) { + form.setError("amount", { + type: "manual", + message: "Insufficient balance", + }); + } else { + toast.toast({ + title: "Error", + description: error.message, + }); + } + } + ); } }; diff --git a/src/hooks/useDeploy.ts b/src/hooks/useDeploy.ts index c8bf1ef..cd4bae9 100644 --- a/src/hooks/useDeploy.ts +++ b/src/hooks/useDeploy.ts @@ -2,6 +2,7 @@ import { useCallback, useState } from "react"; import { getAddress, isAddress, + parseGwei, parseUnits, type Hash, type TransactionReceipt, @@ -43,6 +44,9 @@ export const useDeploy = ( abi: dmrContract.abi, args, bytecode: dmrContract.bytecode, + gas: 7_000_000n, + maxFeePerGas: parseGwei("10"), + maxPriorityFeePerGas: 5n, }); if (!hash) { throw new Error("Failed to deploy contract"); diff --git a/tsconfig.json b/tsconfig.json index 08e6589..a80600e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es2017", + "target": "es2020", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "checkJs": true,