@@ -4,13 +4,17 @@ import styled from "styled-components";
44import { useParams } from "react-router-dom" ;
55import { useDebounce } from "react-use" ;
66import { useAccount , useBalance , usePublicClient } from "wagmi" ;
7+
78import { Field , Button } from "@kleros/ui-components-library" ;
89
910import { REFETCH_INTERVAL } from "consts/index" ;
10- import { useSimulateDisputeKitShutterFundAppeal , useWriteDisputeKitShutterFundAppeal } from "hooks/contracts/generated" ;
11+ import {
12+ useSimulateDisputeKitGatedShutterFundAppeal ,
13+ useSimulateDisputeKitShutterFundAppeal ,
14+ useWriteDisputeKitShutterFundAppeal ,
15+ } from "hooks/contracts/generated" ;
1116import { useSelectedOptionContext , useFundingContext , useCountdownContext } from "hooks/useClassicAppealContext" ;
1217import { useParsedAmount } from "hooks/useParsedAmount" ;
13-
1418import { isUndefined } from "utils/index" ;
1519import { wrapWithToast } from "utils/wrapWithToast" ;
1620
@@ -61,29 +65,49 @@ const useNeedFund = () => {
6165 ) ;
6266} ;
6367
64- const useFundAppeal = ( parsedAmount : bigint , insufficientBalance : boolean ) => {
68+ const useFundAppeal = ( parsedAmount : bigint , isGated : boolean , insufficientBalance ? : boolean ) => {
6569 const { id } = useParams ( ) ;
6670 const { selectedOption } = useSelectedOptionContext ( ) ;
6771 const {
6872 data : fundAppealConfig ,
6973 isLoading,
7074 isError,
7175 } = useSimulateDisputeKitShutterFundAppeal ( {
72- query : { enabled : ! isUndefined ( id ) && ! isUndefined ( selectedOption ) && ! insufficientBalance } ,
76+ query : { enabled : ! isUndefined ( id ) && ! isUndefined ( selectedOption ) && ! insufficientBalance && ! isGated } ,
7377 args : [ BigInt ( id ?? 0 ) , BigInt ( selectedOption ?. id ?? 0 ) ] ,
7478 value : parsedAmount ,
7579 } ) ;
7680 const { writeContractAsync : fundAppeal } = useWriteDisputeKitShutterFundAppeal ( ) ;
77- return { fundAppeal, fundAppealConfig, isLoading, isError } ;
81+
82+ const {
83+ data : fundAppealGatedConfig ,
84+ isLoading : isLoadingGated ,
85+ isError : isErrorGated ,
86+ } = useSimulateDisputeKitGatedShutterFundAppeal ( {
87+ query : { enabled : ! isUndefined ( id ) && ! isUndefined ( selectedOption ) && ! insufficientBalance && isGated } ,
88+ args : [ BigInt ( id ?? 0 ) , BigInt ( selectedOption ?. id ?? 0 ) ] ,
89+ value : parsedAmount ,
90+ } ) ;
91+ const { writeContractAsync : fundAppealGated } = useWriteDisputeKitShutterFundAppeal ( ) ;
92+
93+ return isGated
94+ ? {
95+ fundAppeal : fundAppealGated ,
96+ fundAppealConfig : fundAppealGatedConfig ,
97+ isLoading : isLoadingGated ,
98+ isError : isErrorGated ,
99+ }
100+ : { fundAppeal, fundAppealConfig, isLoading, isError } ;
78101} ;
79102
80103interface IFund {
81104 amount : `${number } `;
82105 setAmount : ( val : string ) => void ;
83106 setIsOpen : ( val : boolean ) => void ;
107+ isGated : boolean ;
84108}
85109
86- const Fund : React . FC < IFund > = ( { amount, setAmount, setIsOpen } ) => {
110+ const Fund : React . FC < IFund > = ( { amount, setAmount, setIsOpen, isGated } ) => {
87111 const needFund = useNeedFund ( ) ;
88112 const { address, isDisconnected } = useAccount ( ) ;
89113 const { data : balance } = useBalance ( {
@@ -96,7 +120,11 @@ const Fund: React.FC<IFund> = ({ amount, setAmount, setIsOpen }) => {
96120 useDebounce ( ( ) => setDebouncedAmount ( amount ) , 500 , [ amount ] ) ;
97121 const parsedAmount = useParsedAmount ( debouncedAmount as `${number } `) ;
98122 const insufficientBalance = useMemo ( ( ) => balance && balance . value < parsedAmount , [ balance , parsedAmount ] ) ;
99- const { fundAppealConfig, fundAppeal, isLoading, isError } = useFundAppeal ( parsedAmount , insufficientBalance ) ;
123+ const { fundAppealConfig, fundAppeal, isLoading, isError } = useFundAppeal (
124+ parsedAmount ,
125+ isGated ,
126+ insufficientBalance
127+ ) ;
100128 const isFundDisabled = useMemo (
101129 ( ) =>
102130 isDisconnected ||
0 commit comments