@@ -16,6 +16,7 @@ import {
16
16
useWritePnkIncreaseAllowance ,
17
17
} from "hooks/contracts/generated" ;
18
18
import { useCourtDetails } from "hooks/queries/useCourtDetails" ;
19
+ import { useLockOverlayScroll } from "hooks/useLockOverlayScroll" ;
19
20
import { usePnkData } from "hooks/usePNKData" ;
20
21
import { formatETH } from "utils/format" ;
21
22
import { isUndefined } from "utils/index" ;
@@ -55,6 +56,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
55
56
const [ isSuccess , setIsSuccess ] = useState ( false ) ;
56
57
const [ popupStepsState , setPopupStepsState ] = useState < Steps > ( ) ;
57
58
const controllerRef = useRef < AbortController | null > ( null ) ;
59
+ useLockOverlayScroll ( isPopupOpen ) ;
58
60
59
61
const { data : courtDetails } = useCourtDetails ( id ) ;
60
62
const { balance, jurorBalance, allowance, refetchAllowance } = usePnkData ( { courtId : id } ) ;
@@ -83,7 +85,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
83
85
error : allowanceError ,
84
86
} = useSimulatePnkIncreaseAllowance ( {
85
87
query : {
86
- enabled : isAllowance && ! isUndefined ( targetStake ) && ! isUndefined ( allowance ) && ! isUndefined ( balance ) ,
88
+ enabled :
89
+ isAllowance &&
90
+ ! isUndefined ( targetStake ) &&
91
+ ! isUndefined ( allowance ) &&
92
+ ! isUndefined ( balance ) &&
93
+ parsedAmount <= balance ,
87
94
} ,
88
95
args : [ klerosCoreAddress [ DEFAULT_CHAIN ] , BigInt ( targetStake ?? 0 ) - BigInt ( allowance ?? 0 ) ] ,
89
96
} ) ;
@@ -103,7 +110,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
103
110
parsedAmount !== 0n &&
104
111
targetStake >= 0n &&
105
112
! isAllowance &&
106
- ( isStaking ? true : jurorBalance && parsedAmount <= jurorBalance [ 2 ] ) ,
113
+ Boolean ( isStaking ? balance && parsedAmount <= balance : jurorBalance && parsedAmount <= jurorBalance [ 2 ] ) ,
107
114
} ,
108
115
args : [ BigInt ( id ?? 0 ) , targetStake ] ,
109
116
} ) ;
@@ -231,30 +238,26 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
231
238
232
239
useEffect ( ( ) => {
233
240
if ( isPopupOpen ) return ;
234
- if ( setStakeError || allowanceError ) {
235
- setErrorMsg ( parseWagmiError ( setStakeError || allowanceError ) ) ;
236
- } else if ( targetStake !== 0n && courtDetails && targetStake < BigInt ( courtDetails . court ?. minStake ) ) {
241
+ if (
242
+ action === ActionType . stake &&
243
+ targetStake !== 0n &&
244
+ courtDetails &&
245
+ targetStake < BigInt ( courtDetails . court ?. minStake )
246
+ ) {
237
247
setErrorMsg ( `Min Stake in court is: ${ formatETH ( courtDetails ?. court ?. minStake ) } ` ) ;
248
+ } else if ( setStakeError || allowanceError ) {
249
+ setErrorMsg ( parseWagmiError ( setStakeError || allowanceError ) ) ;
238
250
}
239
- } , [ setStakeError , setErrorMsg , targetStake , courtDetails , allowanceError , isPopupOpen ] ) ;
251
+ } , [ setStakeError , setErrorMsg , targetStake , courtDetails , allowanceError , isPopupOpen , action ] ) ;
240
252
241
253
const isDisabled = useMemo ( ( ) => {
242
- if (
243
- parsedAmount == 0n ||
244
- isUndefined ( targetStake ) ||
245
- isUndefined ( courtDetails ) ||
246
- ( targetStake !== 0n && targetStake < BigInt ( courtDetails . court ?. minStake ) )
247
- )
248
- return true ;
254
+ if ( parsedAmount == 0n ) return true ;
249
255
if ( isAllowance ) {
250
256
return isUndefined ( increaseAllowanceConfig ) || isSimulatingAllowance || ! isUndefined ( allowanceError ) ;
251
257
}
252
-
253
258
return isUndefined ( setStakeConfig ) || isSimulatingSetStake || ! isUndefined ( setStakeError ) ;
254
259
} , [
255
260
parsedAmount ,
256
- targetStake ,
257
- courtDetails ,
258
261
increaseAllowanceConfig ,
259
262
isSimulatingAllowance ,
260
263
setStakeConfig ,
0 commit comments