1
1
import { useState } from 'react' ;
2
2
import { ConnectKitButton , useModal } from 'connectkit' ;
3
- import { graphql } from 'gql.tada' ;
4
3
import { useForm } from 'react-hook-form' ;
5
4
import semver from 'semver' ;
6
5
import { Address } from 'viem' ;
@@ -129,9 +128,9 @@ const Manifest = z.object({
129
128
repository : z . string ( ) . describe ( 'An optional link to where the subgraph lives.' ) . optional ( ) ,
130
129
} ) ;
131
130
132
- const GetSubgraphInfo = graphql ( /* GraphQL */ `
133
- query GetSubgraphInfo($subgraphId: ID!) {
134
- subgraph(id: $ subgraphId) {
131
+ const GetSubgraphInfo = ( subgraphId : string ) => `
132
+ {
133
+ subgraph(id: " ${ subgraphId } " ) {
135
134
id
136
135
owner {
137
136
id
@@ -155,7 +154,7 @@ const GetSubgraphInfo = graphql(/* GraphQL */ `
155
154
}
156
155
}
157
156
}
158
- ` ) ;
157
+ ` ;
159
158
160
159
function getEtherscanUrl ( { chainId, hash } : { chainId : number ; hash : string } ) {
161
160
switch ( chainId ) {
@@ -172,10 +171,12 @@ function DeploySubgraph({
172
171
deploymentId,
173
172
subgraphId,
174
173
network,
174
+ apiKey,
175
175
} : {
176
176
deploymentId : string ;
177
177
subgraphId : string | undefined ;
178
178
network : ( typeof CHAINS ) [ number ] | undefined ;
179
+ apiKey : string | undefined ;
179
180
} ) {
180
181
const { writeContractAsync, isPending, error : contractError } = useWriteContract ( { } ) ;
181
182
const { setOpen } = useModal ( ) ;
@@ -214,20 +215,32 @@ function DeploySubgraph({
214
215
const chain = form . watch ( 'chain' ) ;
215
216
216
217
const { data : subgraphInfo } = useQuery ( {
217
- queryKey : [ 'subgraph-info' , subgraphId , chain , chainId ] ,
218
+ queryKey : [ 'subgraph-info' , subgraphId , chain , chainId , apiKey ] ,
218
219
queryFn : async ( ) => {
219
- if ( ! subgraphId ) return ;
220
+ if ( ! subgraphId ) {
221
+ toast ( {
222
+ description : 'Subgraph ID is missing. Please add it to the URL params and try again.' ,
223
+ variant : 'destructive' ,
224
+ } ) ;
225
+ return ;
226
+ }
227
+ if ( ! apiKey ) {
228
+ toast ( {
229
+ description :
230
+ 'apiKey is missing in URL params. Please add it to the URL params and try again.' ,
231
+ variant : 'destructive' ,
232
+ } ) ;
233
+ return ;
234
+ }
220
235
221
236
const subgraphEndpoint = chain ? getChainInfo ( chain ) ?. subgraph : null ;
222
237
223
238
if ( ! subgraphEndpoint ) return ;
224
239
225
240
const data = await networkSubgraphExecute (
226
- GetSubgraphInfo ,
227
- { subgraphId } ,
228
- {
229
- endpoint : subgraphEndpoint ,
230
- } ,
241
+ GetSubgraphInfo ( subgraphId ) ,
242
+ subgraphEndpoint ,
243
+ apiKey ,
231
244
) ;
232
245
233
246
const metadata = data . subgraph ?. metadata ;
@@ -251,6 +264,11 @@ function DeploySubgraph({
251
264
if ( metadata . displayName ) {
252
265
form . setValue ( 'displayName' , metadata . displayName ) ;
253
266
}
267
+
268
+ if ( data . subgraph . versions ?. length > 0 ) {
269
+ const version = data . subgraph . versions [ data . subgraph . versions . length - 1 ] ;
270
+ form . setValue ( 'versionLabel' , version . metadata ?. label ?? '' ) ;
271
+ }
254
272
}
255
273
256
274
return data ;
@@ -264,7 +282,7 @@ function DeploySubgraph({
264
282
const version = form . watch ( 'versionLabel' ) ;
265
283
266
284
const versionInfo = subgraphInfo . subgraph ?. versions . find (
267
- ( { metadata } ) => metadata ?. label === version ,
285
+ ( { metadata } : { metadata : { label : string } } ) => metadata ?. label === version ,
268
286
) ;
269
287
270
288
if ( ! versionInfo ) return false ;
@@ -280,7 +298,9 @@ function DeploySubgraph({
280
298
281
299
const version = form . watch ( 'versionLabel' ) ;
282
300
283
- return ! subgraphInfo . subgraph ?. versions . some ( ( { metadata } ) => metadata ?. label === version ) ;
301
+ return ! subgraphInfo . subgraph ?. versions . some (
302
+ ( { metadata } : { metadata : { label : string } } ) => metadata ?. label === version ,
303
+ ) ;
284
304
}
285
305
286
306
function isOwner ( ) {
@@ -375,7 +395,7 @@ function DeploySubgraph({
375
395
if ( e ?. name === 'ContractFunctionExecutionError' ) {
376
396
if ( e . cause . name === 'ContractFunctionRevertedError' ) {
377
397
toast ( {
378
- description : e . cause . reason ,
398
+ description : e . cause . message ,
379
399
variant : 'destructive' ,
380
400
} ) ;
381
401
return ;
@@ -565,7 +585,7 @@ function DeploySubgraph({
565
585
}
566
586
567
587
function Page ( ) {
568
- const { id, subgraphId, network } = Route . useSearch ( ) ;
588
+ const { id, subgraphId, network, apiKey } = Route . useSearch ( ) ;
569
589
570
590
const protocolNetwork = network
571
591
? // @ts -expect-error we want to compare if it is a string or not
@@ -581,7 +601,12 @@ function Page() {
581
601
< ConnectKitButton />
582
602
</ nav >
583
603
{ id ? (
584
- < DeploySubgraph deploymentId = { id } subgraphId = { subgraphId } network = { protocolNetwork } />
604
+ < DeploySubgraph
605
+ deploymentId = { id }
606
+ subgraphId = { subgraphId }
607
+ network = { protocolNetwork }
608
+ apiKey = { apiKey }
609
+ />
585
610
) : (
586
611
< div className = "flex justify-center items-center min-h-screen -mt-16" >
587
612
Unable to find the Deployment ID. Go back to CLI
0 commit comments