diff --git a/apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx b/apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx index 567c8ab8caf..0b6e0686e1b 100644 --- a/apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx +++ b/apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx @@ -5,6 +5,7 @@ import { ContractPublishForm } from "components/contract-components/contract-pub import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { fetchDeployMetadata } from "thirdweb/contract"; +import { getPublishedContractsWithPublisherMapping } from "../../../published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping"; type DirectDeployPageProps = { params: { @@ -20,11 +21,13 @@ export default async function PublishContractPage( ? decodedPublishUri : `ipfs://${decodedPublishUri}`; - const publishMetadata = await fetchDeployMetadata({ + const publishMetadataFromUri = await fetchDeployMetadata({ uri: publishUri, client: getThirdwebClient(), }); + let publishMetadata = publishMetadataFromUri; + const pathname = `/contracts/publish/${props.params.publish_uri}`; const address = getActiveAccountCookie(); @@ -32,6 +35,29 @@ export default async function PublishContractPage( redirect(`/login?next=${encodeURIComponent(pathname)}`); } + // Deploying the next version of a contract scenario: + // check if this is a pre-deployed metadata ( doesn't have a version ) + // If that's the case: + // - get the publish metadata with name+publisher address + // - merge the two objects with publishMetadataFromUri taking higher precedence + if (!publishMetadataFromUri.version) { + const publishedContractVersions = + await getPublishedContractsWithPublisherMapping({ + publisher: address, + contract_id: publishMetadataFromUri.name, + }); + + const publishedContract = publishedContractVersions[0]; + + if (publishedContract) { + publishMetadata = { + ...publishedContract, + ...publishMetadataFromUri, + version: publishedContract.version, + }; + } + } + const token = getJWTCookie(address); if (!token) { redirect(`/login?next=${encodeURIComponent(pathname)}`);