@@ -4,7 +4,7 @@ import { useConnectModal } from "@rainbow-me/rainbowkit";
4
4
import { Abi , AbiFunction } from "abitype" ;
5
5
import { Address , TransactionReceipt , encodeFunctionData } from "viem" ;
6
6
import { useAccount , useConfig , useWaitForTransactionReceipt , useWriteContract } from "wagmi" ;
7
- import { DocumentDuplicateIcon } from "@heroicons/react/24/outline" ;
7
+ import { CheckCircleIcon , DocumentDuplicateIcon } from "@heroicons/react/24/outline" ;
8
8
import {
9
9
ContractInput ,
10
10
IntegerInput ,
@@ -16,7 +16,7 @@ import {
16
16
} from "~~/components/scaffold-eth" ;
17
17
import { useTransactor } from "~~/hooks/scaffold-eth" ;
18
18
import { useGlobalState } from "~~/services/store/store" ;
19
- import { notification } from "~~/utils/scaffold-eth" ;
19
+ import { getParsedError , notification } from "~~/utils/scaffold-eth" ;
20
20
import { simulateContractWriteAndNotifyError } from "~~/utils/scaffold-eth/contract" ;
21
21
22
22
type WriteOnlyFunctionFormProps = {
@@ -47,6 +47,8 @@ export const WriteOnlyFunctionForm = ({
47
47
48
48
const wagmiConfig = useConfig ( ) ;
49
49
50
+ const [ calldataCopied , setCalldataCopied ] = useState ( false ) ;
51
+
50
52
const handleWrite = async ( ) => {
51
53
if ( writeContractAsync ) {
52
54
try {
@@ -103,10 +105,14 @@ export const WriteOnlyFunctionForm = ({
103
105
args : getParsedContractFunctionArgs ( form ) ,
104
106
} ) ;
105
107
await navigator . clipboard . writeText ( calldata ) ;
106
- notification . success ( "Calldata copied to clipboard!" ) ;
108
+ setCalldataCopied ( true ) ;
109
+ setTimeout ( ( ) => {
110
+ setCalldataCopied ( false ) ;
111
+ } , 800 ) ;
107
112
} catch ( e ) {
113
+ const errorMessage = getParsedError ( e ) ;
108
114
console . error ( "Error copying calldata:" , e ) ;
109
- notification . error ( "Failed to copy calldata" ) ;
115
+ notification . error ( errorMessage ) ;
110
116
}
111
117
} ;
112
118
@@ -143,7 +149,14 @@ export const WriteOnlyFunctionForm = ({
143
149
< div className = "flex gap-2" >
144
150
< div className = "tooltip tooltip-left" data-tip = "Copy Calldata" >
145
151
< button className = "btn btn-ghost btn-sm" onClick = { handleCopyCalldata } >
146
- < DocumentDuplicateIcon className = "h-5 w-5" />
152
+ { calldataCopied ? (
153
+ < CheckCircleIcon
154
+ className = "h-5 w-5 text-xl font-normal text-secondary-content cursor-pointer"
155
+ aria-hidden = "true"
156
+ />
157
+ ) : (
158
+ < DocumentDuplicateIcon className = "h-5 w-5 text-xl font-normal text-secondary-content cursor-pointer" />
159
+ ) }
147
160
</ button >
148
161
</ div >
149
162
{ connectedAddress ? (
0 commit comments