diff --git a/.changeset/tiny-cameras-learn.md b/.changeset/tiny-cameras-learn.md new file mode 100644 index 000000000..fdb908860 --- /dev/null +++ b/.changeset/tiny-cameras-learn.md @@ -0,0 +1,6 @@ +--- +"@carrot-kpi/react": minor +"@carrot-kpi/sdk": minor +--- + +Env-specific template previews diff --git a/packages/react/src/hooks/useTemplateModule.ts b/packages/react/src/hooks/useTemplateModule.ts index 98079c47f..3ce98aa62 100644 --- a/packages/react/src/hooks/useTemplateModule.ts +++ b/packages/react/src/hooks/useTemplateModule.ts @@ -10,7 +10,6 @@ import { import { useFederatedModuleContainer } from "./useFederatedModuleContainer"; import { type State, useSelector } from "@carrot-kpi/shared-state"; import { useIPFSGatewayURL } from "./useIPFSGatewayURL"; -import { useStagingMode } from "./useStagingMode"; import { useAccount } from "wagmi"; import type { RemoteComponentProps, @@ -65,18 +64,18 @@ export const useTemplateModule = < : state.preferences.oracleTemplateBaseURL, ); const { chain } = useAccount(); - const stagingMode = useStagingMode(); const ipfsGatewayURL = useIPFSGatewayURL(); const baseURL = useMemo(() => { if (!template || !chain) return undefined; - let root; + let root: string; if (customBaseURL) root = customBaseURL; - else if (stagingMode && template.specification.stagingURL) - root = template.specification.stagingURL; + else if (template.specification.previewUrl?.[chain.environment]) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + root = template.specification.previewUrl[chain.environment]!; else root = `${ipfsGatewayURL}/ipfs/${template.specification.cid}`; return root.endsWith("/") ? `${root}${type}` : `${root}/${type}`; - }, [chain, customBaseURL, ipfsGatewayURL, stagingMode, template, type]); + }, [chain, customBaseURL, ipfsGatewayURL, template, type]); const { loading: loadingFederatedModule, container } = useFederatedModuleContainer({ type, baseUrl: baseURL, entry }); diff --git a/packages/sdk/src/entities/template.ts b/packages/sdk/src/entities/template.ts index 416029ea5..4365d1050 100644 --- a/packages/sdk/src/entities/template.ts +++ b/packages/sdk/src/entities/template.ts @@ -1,4 +1,5 @@ import { type Address } from "viem"; +import type { Environment } from "../commons"; export interface OnChainTemplate { addrezz: Address; @@ -24,7 +25,10 @@ export class TemplateSpecification { public readonly tags: string[], public readonly repository: string, public readonly commitHash: string, - public readonly stagingURL?: string, + public readonly previewUrl?: { + [Environment.Development]?: string; + [Environment.Staging]?: string; + }, ) {} } export class ResolvedTemplate { diff --git a/packages/sdk/src/fetcher/core.ts b/packages/sdk/src/fetcher/core.ts index 1871590b5..a9eb29b7d 100644 --- a/packages/sdk/src/fetcher/core.ts +++ b/packages/sdk/src/fetcher/core.ts @@ -240,7 +240,7 @@ export class CoreFetcher implements ICoreFetcher { parsedTemplateSpecification.tags, parsedTemplateSpecification.repository, parsedTemplateSpecification.commitHash, - parsedTemplateSpecification.stagingURL, + parsedTemplateSpecification.previewUrl, ); return ResolvedTemplate.from(template, specification); }),