Files
js/apps/dashboard/next-sitemap.config.js
T
jnsdls 95b3c787a3 [Update] Refactor contract publish form to use thirdweb v5 (#4605)
<!-- start pr-codex -->

## PR-Codex overview
This PR removes unnecessary files, updates type definitions, refactors contract-related components, and improves API handling.

### Detailed summary
- Removed several files related to publishing contracts and provider setup
- Updated type definitions and constants
- Refactored contract-related components for consistency
- Improved API handling and URL configurations

> The following files were skipped due to too many changes: `apps/dashboard/src/pages/explore/[category]/index.tsx`, `apps/dashboard/src/contract-ui/tabs/claim-conditions/components/claim-conditions-form/hooks.ts`, `apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/page.tsx`, `apps/dashboard/src/contract-ui/tabs/manage/components/moduleContractInfo.ts`, `apps/dashboard/src/constants/chains.ts`, `apps/dashboard/src/components/contract-components/contract-table/cells/description.tsx`, `apps/dashboard/src/contract-ui/tabs/claim-conditions/components/claim-conditions-form/index.tsx`, `apps/dashboard/src/components/contract-components/contract-publish-form/landing-fieldset.tsx`, `apps/dashboard/src/components/contract-components/contract-publish-form/factory-fieldset.tsx`, `apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx`, `apps/dashboard/src/components/explore/contract-card/index.tsx`, `apps/dashboard/src/components/contract-components/contract-publish-form/default-factory.tsx`, `apps/dashboard/src/components/contract-components/shared/contract-id-image.tsx`, `apps/dashboard/src/components/smart-wallets/AccountFactories/index.tsx`, `apps/dashboard/src/lib/sdk.ts`, `apps/dashboard/src/contract-ui/tabs/code/components/code-overview.tsx`, `apps/dashboard/src/components/contract-components/publisher/edit-profile.tsx`, `apps/dashboard/src/pages/profile/[profileAddress].tsx`, `apps/dashboard/src/contract-ui/tabs/claim-conditions/legacy-zod-schema.ts`, `apps/dashboard/src/contract-ui/tabs/manage/components/ModuleForm.tsx`, `apps/dashboard/src/components/contract-functions/contract-function.tsx`, `apps/dashboard/src/components/contract-components/hooks.ts`, `apps/dashboard/src/components/contract-components/contract-publish-form/index.tsx`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
2024-09-16 19:33:35 +00:00

124 lines
3.2 KiB
JavaScript

// @ts-check
/**
*
*/
async function fetchChainsFromApi() {
const res = await fetch(`https://api.thirdweb.com/v1/chains`, {
headers: {
"Content-Type": "application/json",
},
});
const json = await res.json();
if (json.error) {
throw new Error(json.message);
}
return json.data;
}
/**
*
* @param {number|string} chainIdOrSlug
*/
async function getSingleChain(chainIdOrSlug) {
const res = await fetch(
`https://api.thirdweb.com/v1/chains/${chainIdOrSlug}`,
{
headers: {
"Content-Type": "application/json",
},
},
);
const json = await res.json();
if (json.error) {
throw new Error(json.message);
}
return json.data;
}
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: process.env.SITE_URL || "https://thirdweb.com",
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{
userAgent: "*",
[process.env.VERCEL_ENV !== "preview" &&
process.env.VERCEL_ENV !== "development"
? "allow"
: "disallow"]: "/",
},
],
},
exclude: ["/chain/validate"],
transform: async (config, path) => {
// ignore og image paths
if (path.includes("_og")) {
return null;
}
// rewrite paths that include deployer to use thirdweb.eth directly
if (path.includes("deployer.thirdweb.eth")) {
path = path.replace("deployer.thirdweb.eth", "thirdweb.eth");
}
return {
// => this will be exported as http(s)://<config.siteUrl>/<path>
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
alternateRefs: config.alternateRefs ?? [],
};
},
additionalPaths: async (config) => {
const allChains = await fetchChainsFromApi();
return [
...allChains.map((chain) => {
return {
loc: `/${chain.slug}`,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
};
}),
...(await createSearchRecordSitemaps(config)),
];
},
};
/**
* @param {{ changefreq?: any; priority?: any; autoLastmod?: any; }} config
*/
async function createSearchRecordSitemaps(config) {
if (!process.env.TYPESENSE_CONTRACT_EXPORT_API_KEY) {
return [];
}
const response = await fetch(
"https://search.thirdweb.com/collections/contracts/documents/export?filter_by=testnet:false",
{
headers: {
"x-typesense-api-key": process.env.TYPESENSE_CONTRACT_EXPORT_API_KEY,
},
},
);
const data = await response.text();
const parsedLines = data.split("\n").map((l) => JSON.parse(l));
const chainsForLines = await Promise.all(
parsedLines.map((parsedLine) => {
return getSingleChain(parsedLine.chain_id)
.then((parsedLineChain) => ({
loc: `/${parsedLineChain.slug}/${parsedLine.contract_address}`,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
}))
.catch(() => null);
}),
);
// filter out any failed requests
return chainsForLines.filter(Boolean);
}