@@ -15,14 +15,14 @@ import {
1515 useSimulatePnkIncreaseAllowance ,
1616 useWritePnkIncreaseAllowance ,
1717} from "hooks/contracts/generated" ;
18- import { useCourtDetails } from "hooks/queries/useCourtDetails" ;
1918import { useLockOverlayScroll } from "hooks/useLockOverlayScroll" ;
2019import { usePnkData } from "hooks/usePNKData" ;
21- import { formatETH } from "utils/format" ;
2220import { isUndefined } from "utils/index" ;
2321import { parseWagmiError } from "utils/parseWagmiError" ;
2422import { refetchWithRetry } from "utils/refecthWithRetry" ;
2523
24+ import { useCourtDetails } from "queries/useCourtDetails" ;
25+
2626import { EnsureChain } from "components/EnsureChain" ;
2727
2828import StakeWithdrawPopup from "./StakeWithdrawPopup" ;
@@ -67,9 +67,8 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
6767 const controllerRef = useRef < AbortController | null > ( null ) ;
6868 useLockOverlayScroll ( isPopupOpen ) ;
6969
70- const { data : courtDetails } = useCourtDetails ( id ) ;
7170 const { balance, jurorBalance, allowance, refetchAllowance } = usePnkData ( { courtId : id } ) ;
72-
71+ const { data : courtDetails } = useCourtDetails ( id ) ;
7372 const publicClient = usePublicClient ( ) ;
7473
7574 const isStaking = action === ActionType . stake ;
@@ -181,6 +180,16 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
181180 )
182181 ) ;
183182 } ) ;
183+ } else {
184+ updatePopupState (
185+ signal ,
186+ getStakeSteps (
187+ StakeSteps . StakeFailed ,
188+ ...commonArgs ,
189+ undefined ,
190+ new Error ( "Simulation Failed. Please restart the process." )
191+ )
192+ ) ;
184193 }
185194 } ,
186195 [ setStake , setStakeConfig , publicClient , amount , theme , action ]
@@ -248,20 +257,20 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
248257
249258 useEffect ( ( ) => {
250259 if ( isPopupOpen ) return ;
251- if (
252- action === ActionType . stake &&
253- targetStake !== 0n &&
254- courtDetails &&
255- targetStake < BigInt ( courtDetails . court ?. minStake )
256- ) {
257- setErrorMsg ( `Min Stake in court is: ${ formatETH ( courtDetails ?. court ?. minStake ) } ` ) ;
258- } else if ( setStakeError || allowanceError ) {
260+ if ( setStakeError || allowanceError ) {
259261 setErrorMsg ( parseWagmiError ( setStakeError || allowanceError ) ) ;
260262 }
261- } , [ setStakeError , setErrorMsg , targetStake , courtDetails , allowanceError , isPopupOpen , action ] ) ;
263+ } , [ setStakeError , setErrorMsg , targetStake , allowanceError , isPopupOpen ] ) ;
262264
263265 const isDisabled = useMemo ( ( ) => {
264- if ( parsedAmount == 0n ) return true ;
266+ if (
267+ parsedAmount == 0n ||
268+ ( action === ActionType . stake &&
269+ targetStake !== 0n &&
270+ courtDetails &&
271+ targetStake < BigInt ( courtDetails ?. court ?. minStake ) )
272+ )
273+ return true ;
265274 if ( isAllowance ) {
266275 return isUndefined ( increaseAllowanceConfig ) || isSimulatingAllowance || ! isUndefined ( allowanceError ) ;
267276 }
@@ -275,6 +284,9 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
275284 setStakeError ,
276285 allowanceError ,
277286 isAllowance ,
287+ targetStake ,
288+ action ,
289+ courtDetails ,
278290 ] ) ;
279291
280292 const closePopup = ( ) => {
0 commit comments