Skip to content

Commit 3e8c074

Browse files
committed
Fix Publish page not prepopulated with latest published version metadata (#4806)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `PublishContractPage` by adding logic to handle cases where published contract metadata lacks a version. It fetches existing contracts associated with a publisher and merges their data with the fetched metadata. ### Detailed summary - Imported `getPublishedContractsWithPublisherMapping` utility. - Renamed variable `publishMetadata` to `publishMetadataFromUri`. - Added logic to check if `publishMetadataFromUri` lacks a version. - Fetched existing published contracts for the publisher. - Merged existing contract data with `publishMetadataFromUri` if applicable. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 206340c commit 3e8c074

File tree

1 file changed

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

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ContractPublishForm } from "components/contract-components/contract-pub
55
import { revalidatePath } from "next/cache";
66
import { redirect } from "next/navigation";
77
import { fetchDeployMetadata } from "thirdweb/contract";
8+
import { getPublishedContractsWithPublisherMapping } from "../../../published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping";
89

910
type DirectDeployPageProps = {
1011
params: {
@@ -20,18 +21,43 @@ export default async function PublishContractPage(
2021
? decodedPublishUri
2122
: `ipfs://${decodedPublishUri}`;
2223

23-
const publishMetadata = await fetchDeployMetadata({
24+
const publishMetadataFromUri = await fetchDeployMetadata({
2425
uri: publishUri,
2526
client: getThirdwebClient(),
2627
});
2728

29+
let publishMetadata = publishMetadataFromUri;
30+
2831
const pathname = `/contracts/publish/${props.params.publish_uri}`;
2932

3033
const address = getActiveAccountCookie();
3134
if (!address) {
3235
redirect(`/login?next=${encodeURIComponent(pathname)}`);
3336
}
3437

38+
// Deploying the next version of a contract scenario:
39+
// check if this is a pre-deployed metadata ( doesn't have a version )
40+
// If that's the case:
41+
// - get the publish metadata with name+publisher address
42+
// - merge the two objects with publishMetadataFromUri taking higher precedence
43+
if (!publishMetadataFromUri.version) {
44+
const publishedContractVersions =
45+
await getPublishedContractsWithPublisherMapping({
46+
publisher: address,
47+
contract_id: publishMetadataFromUri.name,
48+
});
49+
50+
const publishedContract = publishedContractVersions[0];
51+
52+
if (publishedContract) {
53+
publishMetadata = {
54+
...publishedContract,
55+
...publishMetadataFromUri,
56+
version: publishedContract.version,
57+
};
58+
}
59+
}
60+
3561
const token = getJWTCookie(address);
3662
if (!token) {
3763
redirect(`/login?next=${encodeURIComponent(pathname)}`);

0 commit comments

Comments
 (0)