@@ -8,17 +8,17 @@ import DepositRequired from "./DepositRequired";
8
8
import { StyledModal } from "./StyledModal" ;
9
9
import Info from "./Info" ;
10
10
import {
11
- useCurateV2ChallengeRequest ,
11
+ prepareWriteCurateV2 ,
12
12
useCurateV2GetArbitratorExtraData ,
13
13
useCurateV2RemovalChallengeBaseDeposit ,
14
14
useCurateV2SubmissionChallengeBaseDeposit ,
15
- usePrepareCurateV2ChallengeRequest ,
16
15
} from "hooks/contracts/generated" ;
17
16
import { useArbitrationCost } from "hooks/useArbitrationCostFromKlerosCore" ;
18
- import { useAccount , useBalance , usePublicClient } from "wagmi" ;
17
+ import { useAccount , useBalance , usePublicClient , useWalletClient } from "wagmi" ;
19
18
import { wrapWithToast } from "utils/wrapWithToast" ;
20
19
import { IBaseModal } from "." ;
21
20
import EvidenceUpload , { Evidence } from "./EvidenceUpload" ;
21
+ import { uploadFileToIPFS } from "utils/uploadFileToIPFS" ;
22
22
23
23
const ReStyledModal = styled ( StyledModal ) `
24
24
gap: 32px;
@@ -50,6 +50,7 @@ const ChallengeItemModal: React.FC<IChallengeItemModal> = ({
50
50
useClickAway ( containerRef , ( ) => toggleModal ( ) ) ;
51
51
const { address } = useAccount ( ) ;
52
52
const publicClient = usePublicClient ( ) ;
53
+ const { data : walletClient } = useWalletClient ( ) ;
53
54
54
55
const [ isChallengingItem , setIsChallengingItem ] = useState ( false ) ;
55
56
const [ isEvidenceUploading , setIsEvidenceUploading ] = useState ( false ) ;
@@ -109,16 +110,6 @@ const ChallengeItemModal: React.FC<IChallengeItemModal> = ({
109
110
return userBalance ?. value < depositRequired ;
110
111
} , [ depositRequired , userBalance , isEvidenceUploading , isEvidenceValid ] ) ;
111
112
112
- const { config, isError } = usePrepareCurateV2ChallengeRequest ( {
113
- enabled : address && registryAddress && ! isLoading && ! isDisabled ,
114
- //@ts -ignore
115
- address : registryAddress ,
116
- args : [ itemId as `0x${string } `, JSON . stringify ( evidence ) ] ,
117
- value : depositRequired ,
118
- } ) ;
119
-
120
- const { writeAsync : challengeRequest } = useCurateV2ChallengeRequest ( config ) ;
121
-
122
113
return (
123
114
< >
124
115
< Overlay />
@@ -130,24 +121,37 @@ const ChallengeItemModal: React.FC<IChallengeItemModal> = ({
130
121
< Buttons
131
122
buttonText = "Challenge"
132
123
toggleModal = { toggleModal }
133
- isDisabled = { isDisabled || isError || isChallengingItem }
124
+ isDisabled = { isDisabled || isChallengingItem }
134
125
isLoading = { isLoading }
135
- callback = { ( ) => {
136
- if ( ! challengeRequest ) return ;
126
+ callback = { async ( ) => {
137
127
setIsChallengingItem ( true ) ;
138
- wrapWithToast (
139
- async ( ) =>
140
- await challengeRequest ( ) . then ( ( response ) => {
141
- return response . hash ;
142
- } ) ,
143
- publicClient
144
- )
145
- . then ( ( res ) => {
146
- console . log ( { res } ) ;
147
- refetch ( ) ;
148
- toggleModal ( ) ;
128
+
129
+ const evidenceFile = new File ( [ JSON . stringify ( evidence ) ] , "evidence.json" , {
130
+ type : "application/json" ,
131
+ } ) ;
132
+
133
+ uploadFileToIPFS ( evidenceFile )
134
+ . then ( async ( res ) => {
135
+ if ( res . status === 200 && walletClient ) {
136
+ const response = await res . json ( ) ;
137
+ const fileURI = response [ "cids" ] [ 0 ] ;
138
+
139
+ const { request } = await prepareWriteCurateV2 ( {
140
+ //@ts -ignore
141
+ address : registryAddress ,
142
+ functionName : "challengeRequest" ,
143
+ args : [ itemId as `0x${string } `, fileURI ] ,
144
+ value : depositRequired ,
145
+ } ) ;
146
+
147
+ wrapWithToast ( async ( ) => await walletClient . writeContract ( request ) , publicClient ) . then ( ( res ) => {
148
+ console . log ( { res } ) ;
149
+ refetch ( ) ;
150
+ toggleModal ( ) ;
151
+ } ) ;
152
+ }
149
153
} )
150
- . catch ( ( ) => { } )
154
+ . catch ( ( err ) => console . log ( err ) )
151
155
. finally ( ( ) => setIsChallengingItem ( false ) ) ;
152
156
} }
153
157
/>
0 commit comments