From 9ea40a5f92b9ba68ff73a30818083ed3c344d2d1 Mon Sep 17 00:00:00 2001 From: veganbeef Date: Wed, 16 Jul 2025 09:46:35 -0700 Subject: [PATCH] feat: add requiredChains support --- scripts/deploy.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++ src/lib/constants.ts | 12 +++++++++++ src/lib/utils.ts | 2 ++ 3 files changed, 64 insertions(+) diff --git a/scripts/deploy.ts b/scripts/deploy.ts index fbbd792..a96a637 100755 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -140,6 +140,56 @@ async function checkRequiredEnvVars(): Promise { console.log('✅ Sponsor signer preference stored in .env.local'); } } + + // Ask about required chains + const { useRequiredChains } = await inquirer.prompt([ + { + type: 'confirm', + name: 'useRequiredChains', + message: + 'Does your mini app require support for specific blockchains?\n' + + 'If yes, the host will only render your mini app if it supports all the chains you specify.\n' + + 'If no, the mini app will be rendered regardless of chain support.', + default: false, + }, + ]); + + let requiredChains: string[] = []; + if (useRequiredChains) { + const { selectedChains } = await inquirer.prompt([ + { + type: 'checkbox', + name: 'selectedChains', + message: 'Select the required chains (CAIP-2 identifiers):', + choices: [ + { name: 'Ethereum Mainnet (eip155:1)', value: 'eip155:1' }, + { name: 'Polygon (eip155:137)', value: 'eip155:137' }, + { name: 'Arbitrum One (eip155:42161)', value: 'eip155:42161' }, + { name: 'Optimism (eip155:10)', value: 'eip155:10' }, + { name: 'Base (eip155:8453)', value: 'eip155:8453' }, + { name: 'Solana (solana:mainnet)', value: 'solana:mainnet' }, + { name: 'Solana Devnet (solana:devnet)', value: 'solana:devnet' }, + ], + }, + ]); + requiredChains = selectedChains; + } + + // Update constants.ts with required chains + const constantsPath = path.join(projectRoot, 'src', 'lib', 'constants.ts'); + if (fs.existsSync(constantsPath)) { + let constantsContent = fs.readFileSync(constantsPath, 'utf8'); + + // Replace the APP_REQUIRED_CHAINS line + const requiredChainsString = JSON.stringify(requiredChains); + constantsContent = constantsContent.replace( + /^export const APP_REQUIRED_CHAINS\s*:\s*string\[\]\s*=\s*\[[^\]]*\];$/m, + `export const APP_REQUIRED_CHAINS: string[] = ${requiredChainsString};`, + ); + + fs.writeFileSync(constantsPath, constantsContent); + console.log('✅ Required chains updated in constants.ts'); + } } } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index dc05838..4938795 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -111,6 +111,18 @@ export const USE_WALLET: boolean = true; */ export const ANALYTICS_ENABLED: boolean = true; +/** + * Required chains for the mini app. + * + * Contains an array of CAIP-2 identifiers for blockchains that the mini app requires. + * If the host does not support all chains listed here, it will not render the mini app. + * If empty or undefined, the mini app will be rendered regardless of chain support. + * + * Supported chains: eip155:1, eip155:137, eip155:42161, eip155:10, eip155:8453, + * solana:mainnet, solana:devnet + */ +export const APP_REQUIRED_CHAINS: string[] = []; + // PLEASE DO NOT UPDATE THIS export const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = { name: 'Farcaster SignedKeyRequestValidator', diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 59430e8..d39dc79 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -13,6 +13,7 @@ import { APP_TAGS, APP_URL, APP_WEBHOOK_URL, APP_ACCOUNT_ASSOCIATION, + APP_REQUIRED_CHAINS, } from './constants'; export function cn(...inputs: ClassValue[]) { @@ -56,6 +57,7 @@ export async function getFarcasterDomainManifest(): Promise { description: APP_DESCRIPTION, primaryCategory: APP_PRIMARY_CATEGORY, tags: APP_TAGS, + requiredChains: APP_REQUIRED_CHAINS.length > 0 ? APP_REQUIRED_CHAINS : undefined, }, }; }