1- import React , { useMemo , useEffect } from "react" ;
1+ import React , { useMemo } from "react" ;
22
33import { useParams } from "react-router-dom" ;
44import { useAccount , usePublicClient } from "wagmi" ;
@@ -35,6 +35,8 @@ interface IActionButton {
3535 setAmount : ( arg0 : string ) => void ;
3636 setIsPopupOpen : ( arg0 : boolean ) => void ;
3737 setErrorMsg : ( arg0 : string | undefined ) => void ;
38+ hasInteracted : boolean ;
39+ setHasInteracted : ( arg0 : boolean ) => void ;
3840}
3941
4042const StakeWithdrawButton : React . FC < IActionButton > = ( {
@@ -43,7 +45,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
4345 isSending,
4446 setIsSending,
4547 setIsPopupOpen,
46- setErrorMsg ,
48+ setHasInteracted ,
4749} ) => {
4850 const { id } = useParams ( ) ;
4951 const { address } = useAccount ( ) ;
@@ -82,7 +84,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
8284 return 0n ;
8385 } , [ jurorBalance , parsedAmount , isAllowance , isStaking ] ) ;
8486
85- const { config : increaseAllowanceConfig , error : allowanceError } = usePreparePnkIncreaseAllowance ( {
87+ const { config : increaseAllowanceConfig } = usePreparePnkIncreaseAllowance ( {
8688 enabled : isAllowance && ! isUndefined ( klerosCore ) && ! isUndefined ( targetStake ) && ! isUndefined ( allowance ) ,
8789 args : [ klerosCore ?. address , BigInt ( targetStake ?? 0 ) - BigInt ( allowance ?? 0 ) ] ,
8890 } ) ;
@@ -99,7 +101,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
99101 } ;
100102
101103 const { config : setStakeConfig , error : setStakeError } = usePrepareKlerosCoreSetStake ( {
102- enabled : ! isUndefined ( targetStake ) && ! isUndefined ( id ) && ! isAllowance ,
104+ enabled : ! isUndefined ( targetStake ) && ! isUndefined ( id ) && ! isAllowance && parsedAmount !== 0n ,
103105 args : [ BigInt ( id ?? 0 ) , targetStake ] ,
104106 } ) ;
105107 const { writeAsync : setStake } = useKlerosCoreSetStake ( setStakeConfig ) ;
@@ -114,19 +116,6 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
114116 }
115117 } ;
116118
117- useEffect ( ( ) => {
118- let errorMessage = parsedAmount === 0n
119- ? "Please enter a valid amount to stake or withdraw."
120- : "There was an error processing your request. Please try again later." ;
121-
122- if ( isAllowance && allowanceError ?. shortMessage ) {
123- setErrorMsg ( errorMessage ) ;
124- } else if ( ! isAllowance && setStakeError ?. shortMessage ) {
125- setErrorMsg ( errorMessage ) ;
126- }
127- } , [ allowanceError , setStakeError , isAllowance , isStaking , parsedAmount , setErrorMsg ] ) ;
128-
129-
130119 const buttonProps = {
131120 [ ActionType . allowance ] : {
132121 text : "Allow PNK" ,
@@ -160,10 +149,13 @@ useEffect(() => {
160149 ( targetStake !== 0n && targetStake < BigInt ( courtDetails . court ?. minStake ) ) ||
161150 ( isStaking && ! isAllowance && isUndefined ( setStakeConfig . request ) )
162151 }
163- onClick = { onClick }
152+ onClick = { ( ) => {
153+ setHasInteracted ( true ) ;
154+ onClick ( ) ;
155+ } }
164156 />
165157 </ EnsureChain >
166158 ) ;
167159} ;
168160
169- export default StakeWithdrawButton ;
161+ export default StakeWithdrawButton ;
0 commit comments