@@ -146,6 +146,9 @@ const GetSubgraphInfo = graphql(/* GraphQL */ `
146
146
}
147
147
versions {
148
148
id
149
+ subgraphDeployment {
150
+ ipfsHash
151
+ }
149
152
metadata {
150
153
label
151
154
}
@@ -255,6 +258,20 @@ function DeploySubgraph({
255
258
enabled : ! ! subgraphId && ! ! chain ,
256
259
} ) ;
257
260
261
+ function updateMetadata ( ) {
262
+ if ( ! subgraphInfo ) return false ;
263
+
264
+ const version = form . watch ( 'versionLabel' ) ;
265
+
266
+ const versionInfo = subgraphInfo . subgraph ?. versions . find (
267
+ ( { metadata } ) => metadata ?. label === version ,
268
+ ) ;
269
+
270
+ if ( ! versionInfo ) return false ;
271
+
272
+ return versionInfo . subgraphDeployment . ipfsHash === deploymentId ;
273
+ }
274
+
258
275
function ensureNewVersion ( ) {
259
276
// If there is no subgraph ID then it means we are just deploying a new subgraph
260
277
if ( ! subgraphId ) return true ;
@@ -307,6 +324,37 @@ function DeploySubgraph({
307
324
return ;
308
325
}
309
326
327
+ // we are just updating the metadata
328
+ if ( updateMetadata ( ) && ! ensureNewVersion ( ) ) {
329
+ const subgraphMeta = await uploadFileToIpfs ( {
330
+ path : '' ,
331
+ content : Buffer . from (
332
+ JSON . stringify (
333
+ subgraphMetadata ( {
334
+ ...values ,
335
+ } ) ,
336
+ ) ,
337
+ ) ,
338
+ } ) ;
339
+
340
+ const hash = await writeContractAsync ( {
341
+ address : selectedChain . contracts . L2GNS . address as Address ,
342
+ abi : L2GNSABI ,
343
+ functionName : 'updateSubgraphMetadata' ,
344
+ args : [ BigInt ( subgraphInfo . subgraph . nftID ) , ipfsHexHash ( subgraphMeta ) ] ,
345
+ } ) ;
346
+
347
+ const etherscanUrl = getEtherscanUrl ( { chainId : selectedChain . chainId , hash } ) ;
348
+
349
+ window . open ( etherscanUrl , '_blank' ) ;
350
+ setDeployed ( true ) ;
351
+ toast ( {
352
+ description : 'You are all set! You can go back to the CLI and close this window' ,
353
+ } ) ;
354
+
355
+ return ;
356
+ }
357
+
310
358
try {
311
359
const hash = await writeContractAsync ( {
312
360
address : selectedChain . contracts . L2GNS . address as Address ,
@@ -376,13 +424,15 @@ function DeploySubgraph({
376
424
chainSwitchPending ||
377
425
isPending ||
378
426
! form . formState . isValid ||
379
- ! ensureNewVersion ( ) ||
427
+ ! ( ensureNewVersion ( ) || updateMetadata ( ) ) ||
380
428
! isOwner ( ) ;
381
429
382
430
const deployButtonCopy = ( ( ) => {
431
+ if ( ! address ) return 'Need to connect wallet' ;
383
432
if ( deployed ) return 'Deployed' ;
384
433
if ( chainSwitchPending ) return 'Switching Chains...' ;
385
434
if ( isPending ) return 'Check Wallet...' ;
435
+ if ( updateMetadata ( ) ) return 'Update Metadata' ;
386
436
return 'Deploy' ;
387
437
} ) ( ) ;
388
438
0 commit comments