Skip to content

Commit d0cb82a

Browse files
authored
feat: allow updating metadata (#1714)
* feat: allow updating metadata * connect wallet cta:
1 parent 957e9ef commit d0cb82a

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

website/src/routes/publish.lazy.tsx

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ const GetSubgraphInfo = graphql(/* GraphQL */ `
146146
}
147147
versions {
148148
id
149+
subgraphDeployment {
150+
ipfsHash
151+
}
149152
metadata {
150153
label
151154
}
@@ -255,6 +258,20 @@ function DeploySubgraph({
255258
enabled: !!subgraphId && !!chain,
256259
});
257260

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+
258275
function ensureNewVersion() {
259276
// If there is no subgraph ID then it means we are just deploying a new subgraph
260277
if (!subgraphId) return true;
@@ -307,6 +324,37 @@ function DeploySubgraph({
307324
return;
308325
}
309326

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+
310358
try {
311359
const hash = await writeContractAsync({
312360
address: selectedChain.contracts.L2GNS.address as Address,
@@ -376,13 +424,15 @@ function DeploySubgraph({
376424
chainSwitchPending ||
377425
isPending ||
378426
!form.formState.isValid ||
379-
!ensureNewVersion() ||
427+
!(ensureNewVersion() || updateMetadata()) ||
380428
!isOwner();
381429

382430
const deployButtonCopy = (() => {
431+
if (!address) return 'Need to connect wallet';
383432
if (deployed) return 'Deployed';
384433
if (chainSwitchPending) return 'Switching Chains...';
385434
if (isPending) return 'Check Wallet...';
435+
if (updateMetadata()) return 'Update Metadata';
386436
return 'Deploy';
387437
})();
388438

0 commit comments

Comments
 (0)