-
Notifications
You must be signed in to change notification settings - Fork 25
Improved writing and reading to the contracts. Fixed button issues. #51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||||||||||
| "use client"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import { useState } from "react"; | ||||||||||||||||||||||||||||||||||||
| import { useState, useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||
| import Layout from "@/components/Layout"; | ||||||||||||||||||||||||||||||||||||
| import { Button } from "@/components/ui/button"; | ||||||||||||||||||||||||||||||||||||
| import { Label } from "@/components/ui/label"; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -11,7 +11,7 @@ import { useRouter } from "next/navigation"; | |||||||||||||||||||||||||||||||||||
| import { ClowderVaultFactories } from "@/utils/address"; | ||||||||||||||||||||||||||||||||||||
| import { useAccount } from "wagmi"; | ||||||||||||||||||||||||||||||||||||
| import { config } from "@/utils/config"; | ||||||||||||||||||||||||||||||||||||
| import { writeContract } from "@wagmi/core"; | ||||||||||||||||||||||||||||||||||||
| import { useWriteContract, useWaitForTransactionReceipt } from "wagmi"; | ||||||||||||||||||||||||||||||||||||
| import { CAT_FACTORY_ABI } from "@/contractsABI/CatFactoryABI"; | ||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||
| Card, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -22,6 +22,8 @@ import { | |||||||||||||||||||||||||||||||||||
| } from "@/components/ui/card"; | ||||||||||||||||||||||||||||||||||||
| import { Info, Loader2 } from "lucide-react"; | ||||||||||||||||||||||||||||||||||||
| import { motion } from "framer-motion"; | ||||||||||||||||||||||||||||||||||||
| import { showTransactionToast } from "@/components/ui/transaction-toast"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| interface DeployContractProps { | ||||||||||||||||||||||||||||||||||||
| tokenName: string; | ||||||||||||||||||||||||||||||||||||
| tokenSymbol: string; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -67,6 +69,7 @@ const fields = [ | |||||||||||||||||||||||||||||||||||
| description: "Maximum percentage the supply can expand (1-100)", | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export default function CreateCAT() { | ||||||||||||||||||||||||||||||||||||
| const [formData, setFormData] = useState<DeployContractProps>({ | ||||||||||||||||||||||||||||||||||||
| tokenName: "", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -80,6 +83,11 @@ export default function CreateCAT() { | |||||||||||||||||||||||||||||||||||
| const { address, chainId } = useAccount(); | ||||||||||||||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const { writeContract: deployCAT, data: deployData } = useWriteContract(); | ||||||||||||||||||||||||||||||||||||
| const { isLoading: isDeployingTx } = useWaitForTransactionReceipt({ | ||||||||||||||||||||||||||||||||||||
| hash: deployData, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const getTransactionHistory = () => { | ||||||||||||||||||||||||||||||||||||
| const history = localStorage.getItem("transactionHistory"); | ||||||||||||||||||||||||||||||||||||
| return history ? JSON.parse(history) : []; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -112,7 +120,7 @@ export default function CreateCAT() { | |||||||||||||||||||||||||||||||||||
| const formattedThresholdSupply = BigInt(thresholdSupply) * BigInt(1e18); | ||||||||||||||||||||||||||||||||||||
| const formattedMaxExpansionRate = BigInt(maxExpansionRate) * BigInt(100); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const tx = await writeContract(config, { | ||||||||||||||||||||||||||||||||||||
| deployCAT({ | ||||||||||||||||||||||||||||||||||||
| address: ClowderVaultFactories[chainId], | ||||||||||||||||||||||||||||||||||||
| abi: CAT_FACTORY_ABI, | ||||||||||||||||||||||||||||||||||||
| functionName: "createCAT", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -124,27 +132,40 @@ export default function CreateCAT() { | |||||||||||||||||||||||||||||||||||
| tokenSymbol, | ||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||
| console.error("Error deploying CAT:", error); | ||||||||||||||||||||||||||||||||||||
| showTransactionToast({ | ||||||||||||||||||||||||||||||||||||
| hash: "0x0" as `0x${string}`, | ||||||||||||||||||||||||||||||||||||
| chainId: config.state.chainId, | ||||||||||||||||||||||||||||||||||||
| success: false, | ||||||||||||||||||||||||||||||||||||
| message: "Failed to deploy CAT contract", | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| setIsDeploying(false); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+135
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling to avoid misleading transaction notifications. The current error handling shows a transaction toast with a dummy hash Consider handling pre-transaction errors differently from transaction failures: } catch (error) {
console.error("Error deploying CAT:", error);
- showTransactionToast({
- hash: "0x0" as `0x${string}`,
- chainId: config.state.chainId,
- success: false,
- message: "Failed to deploy CAT contract",
- });
+ // Only show transaction toast if we have a transaction hash
+ // Otherwise, show a regular error toast
+ toast.error("Failed to deploy CAT contract. Please try again.");
setIsDeploying(false);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ceilican Thank you for confirming! The fix will make the error handling much clearer for users by distinguishing between pre-transaction failures and actual transaction errors. Would you like me to plan the code changes for this improvement, or are you planning to implement it yourself? |
||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||
| if (deployData) { | ||||||||||||||||||||||||||||||||||||
| const txDetails = { | ||||||||||||||||||||||||||||||||||||
| tokenName, | ||||||||||||||||||||||||||||||||||||
| tokenSymbol, | ||||||||||||||||||||||||||||||||||||
| maxSupply, | ||||||||||||||||||||||||||||||||||||
| thresholdSupply, | ||||||||||||||||||||||||||||||||||||
| maxExpansionRate, | ||||||||||||||||||||||||||||||||||||
| transactionHash: tx, | ||||||||||||||||||||||||||||||||||||
| tokenName: formData.tokenName, | ||||||||||||||||||||||||||||||||||||
| tokenSymbol: formData.tokenSymbol, | ||||||||||||||||||||||||||||||||||||
| maxSupply: formData.maxSupply, | ||||||||||||||||||||||||||||||||||||
| thresholdSupply: formData.thresholdSupply, | ||||||||||||||||||||||||||||||||||||
| maxExpansionRate: formData.maxExpansionRate, | ||||||||||||||||||||||||||||||||||||
| transactionHash: deployData, | ||||||||||||||||||||||||||||||||||||
| timestamp: new Date().toISOString(), | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| saveTransaction(txDetails); | ||||||||||||||||||||||||||||||||||||
| toast.success("CAT contract deployed successfully!"); | ||||||||||||||||||||||||||||||||||||
| showTransactionToast({ | ||||||||||||||||||||||||||||||||||||
| hash: deployData, | ||||||||||||||||||||||||||||||||||||
| chainId: config.state.chainId, | ||||||||||||||||||||||||||||||||||||
| message: "CAT contract deployed successfully!", | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| router.push("/my-cats"); | ||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||
| console.error("Error deploying CAT:", error); | ||||||||||||||||||||||||||||||||||||
| toast.error("Failed to deploy CAT contract"); | ||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||
| setIsDeploying(false); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| }, [deployData, formData, router]); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||||||||||||||||||||||||||||
| setFormData({ | ||||||||||||||||||||||||||||||||||||
|
|
@@ -251,9 +272,9 @@ export default function CreateCAT() { | |||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||
| type="submit" | ||||||||||||||||||||||||||||||||||||
| className="w-full h-12 text-lg font-medium transition-all duration-200 hover:scale-[1.02]" | ||||||||||||||||||||||||||||||||||||
| disabled={isDeploying} | ||||||||||||||||||||||||||||||||||||
| disabled={isDeploying || isDeployingTx} | ||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||
| {isDeploying ? ( | ||||||||||||||||||||||||||||||||||||
| {isDeploying || isDeployingTx ? ( | ||||||||||||||||||||||||||||||||||||
| <span className="flex items-center justify-center"> | ||||||||||||||||||||||||||||||||||||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||||||||||||||||||||||||||||||||||||
| Deploying... | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| import { useEffect, useState } from "react"; | ||
| import Layout from "@/components/Layout"; | ||
| import Link from "next/link"; | ||
| import { useAccount } from "wagmi"; | ||
| import { useAccount, useWriteContract, useWaitForTransactionReceipt } from "wagmi"; | ||
| import { ClowderVaultFactories } from "@/utils/address"; | ||
| import { config } from "@/utils/config"; | ||
| import { getPublicClient } from "@wagmi/core"; | ||
|
|
@@ -12,6 +12,7 @@ import detectEthereumProvider from "@metamask/detect-provider"; | |
| import { CONTRIBUTION_ACCOUNTING_TOKEN_ABI } from "@/contractsABI/ContributionAccountingTokenABI"; | ||
| import { motion } from "framer-motion"; | ||
| import { Loader2, AlertCircle } from "lucide-react"; | ||
| import { showTransactionToast } from "@/components/ui/transaction-toast"; | ||
|
|
||
| // Define supported chain IDs | ||
| type SupportedChainId = 1 | 137 | 534351 | 5115 | 61 | 2001; | ||
|
|
@@ -37,6 +38,21 @@ export default function MyCATsPage() { | |
| const [error, setError] = useState<string | null>(null); | ||
| const { address } = useAccount(); | ||
|
|
||
| const { writeContract: fetchCATs, data: fetchData } = useWriteContract(); | ||
| const { isLoading: isFetching } = useWaitForTransactionReceipt({ | ||
| hash: fetchData, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (fetchData) { | ||
| showTransactionToast({ | ||
| hash: fetchData, | ||
| chainId: config.state.chainId, | ||
| message: "CATs fetched successfully!", | ||
| }); | ||
| } | ||
| }, [fetchData]); | ||
|
|
||
| const fetchCATsFromAllChains = async () => { | ||
| try { | ||
| setIsLoading(true); | ||
|
|
@@ -55,6 +71,12 @@ export default function MyCATsPage() { | |
| setOwnedCATs(allCATs); | ||
| } catch (error) { | ||
| console.error("Error fetching CATs:", error); | ||
| showTransactionToast({ | ||
| hash: "0x0" as `0x${string}`, | ||
| chainId: config.state.chainId, | ||
| success: false, | ||
| message: "Failed to fetch CATs. Please try again later.", | ||
| }); | ||
|
Comment on lines
+74
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using dummy hash for error notifications. Using Consider modifying the toast component to handle cases without transaction hashes: showTransactionToast({
- hash: "0x0" as `0x${string}`,
+ hash: "0x0000000000000000000000000000000000000000000000000000000000000000" as `0x${string}`,
chainId: config.state.chainId,
success: false,
message: "Failed to fetch CATs. Please try again later.",
});Or better yet, create a separate error toast function that doesn't require a transaction hash: // In transaction-toast.tsx
export const showErrorToast = (message: string) => {
toast.custom(
(t) => (
<div className={/* similar styling but without hash display */}>
{/* Error content without transaction hash */}
</div>
),
{ duration: 5000, position: "bottom-right" }
);
};🤖 Prompt for AI Agents |
||
| setError("Failed to fetch CATs. Please try again later."); | ||
| } finally { | ||
| setIsLoading(false); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null check for chainId to prevent runtime errors.
The non-null assertion operator (
!) onchainIdcould cause runtime errors ifchainIdis null. Add a safety check:useEffect(() => { - if (mintData) { + if (mintData && chainId) { showTransactionToast({ hash: mintData, - chainId: chainId!, + chainId: chainId, message: "Tokens minted successfully!", }); } }, [mintData, chainId]);This same issue appears in all the transaction toast useEffect hooks (lines 192-230). Apply the same fix to all of them.
📝 Committable suggestion
🤖 Prompt for AI Agents