Skip to content

Commit aa5abc0

Browse files
committed
Fix Publish page not prepopulated with older version metadata
1 parent 8e9d13c commit aa5abc0

File tree

1 file changed

+34
-6
lines changed
  • apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]

1 file changed

+34
-6
lines changed

apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { getThirdwebClient } from "@/constants/thirdweb.server";
44
import { ContractPublishForm } from "components/contract-components/contract-publish-form";
55
import { revalidatePath } from "next/cache";
66
import { redirect } from "next/navigation";
7-
import { fetchDeployMetadata } from "thirdweb/contract";
7+
import {
8+
type FetchDeployMetadataResult,
9+
fetchDeployMetadata,
10+
} from "thirdweb/contract";
11+
import { getPublishedContractsWithPublisherMapping } from "../../../published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping";
812

913
type DirectDeployPageProps = {
1014
params: {
@@ -20,10 +24,11 @@ export default async function PublishContractPage(
2024
? decodedPublishUri
2125
: `ipfs://${decodedPublishUri}`;
2226

23-
const publishMetadata = await fetchDeployMetadata({
24-
uri: publishUri,
25-
client: getThirdwebClient(),
26-
});
27+
let publishMetadataFromUri: FetchDeployMetadataResult =
28+
await fetchDeployMetadata({
29+
uri: publishUri,
30+
client: getThirdwebClient(),
31+
});
2732

2833
const pathname = `/contracts/publish/${props.params.publish_uri}`;
2934

@@ -32,6 +37,29 @@ export default async function PublishContractPage(
3237
redirect(`/login?next=${encodeURIComponent(pathname)}`);
3338
}
3439

40+
// Deploying the next version of a contract scenario:
41+
// check if this is a pre-deployed metadata ( doesn't have a version )
42+
// if doesn't have a version
43+
// get the publish metadata with name+publisher address
44+
// merge the two objects with publishMetadata taking higher precedence
45+
if (!publishMetadataFromUri.version) {
46+
const publishedContractVersions =
47+
await getPublishedContractsWithPublisherMapping({
48+
publisher: address,
49+
contract_id: publishMetadataFromUri.name,
50+
});
51+
52+
const publishedContract = publishedContractVersions[0];
53+
54+
if (publishedContract) {
55+
publishMetadataFromUri = {
56+
...publishedContract,
57+
...publishMetadataFromUri,
58+
version: publishedContract.version,
59+
};
60+
}
61+
}
62+
3563
const token = getJWTCookie(address);
3664
if (!token) {
3765
redirect(`/login?next=${encodeURIComponent(pathname)}`);
@@ -42,7 +70,7 @@ export default async function PublishContractPage(
4270
<ChakraProviderSetup>
4371
<ContractPublishForm
4472
jwt={token}
45-
publishMetadata={publishMetadata}
73+
publishMetadata={publishMetadataFromUri}
4674
onPublishSuccess={async () => {
4775
"use server";
4876
// we are pretty brutal here and simply invalidate ALL published contracts (for everyone!) and versions no matter what

0 commit comments

Comments
 (0)