From 1d736d823eac500c407d325d459d53e86bfdce79 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Mon, 7 Jul 2025 21:47:40 +0530 Subject: [PATCH] Ask SPONSOR_SIGNER --- bin/init.js | 34 ++++++++++++++++++++++++++++++++++ scripts/build.js | 7 ++++++- scripts/deploy.js | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/bin/init.js b/bin/init.js index 659f36c..1534beb 100644 --- a/bin/init.js +++ b/bin/init.js @@ -221,6 +221,8 @@ export async function init(projectName = null, autoAcceptDefaults = false) { useWallet: true, useTunnel: true, enableAnalytics: true, + seedPhrase: null, + sponsorSigner: false, }; } else { // If autoAcceptDefaults is false but we have a projectName, we still need to ask for other options @@ -347,6 +349,34 @@ export async function init(projectName = null, autoAcceptDefaults = false) { }, ]); answers.enableAnalytics = analyticsAnswer.enableAnalytics; + + // Ask about SEED_PHRASE + const seedPhraseAnswer = await inquirer.prompt([ + { + type: 'password', + name: 'seedPhrase', + message: + '⚠️ If SEED_PHRASE is not provided, you will not be able to use Sign In With Neynar.\n\n' + + 'Enter your SEED_PHRASE (or press enter to skip):', + default: null, + }, + ]); + answers.seedPhrase = seedPhraseAnswer.seedPhrase; + + // Ask about sponsor signer if SEED_PHRASE is provided + if (answers.seedPhrase) { + const sponsorSignerAnswer = await inquirer.prompt([ + { + type: 'confirm', + name: 'sponsorSigner', + message: + 'Do you want to sponsor the signer? (This will be used in Sign In With Neynar)\n' + + 'Note: If you choose to sponsor the signer, Neynar will sponsor it for you and you will be charged in CUs.', + default: false, + }, + ]); + answers.sponsorSigner = sponsorSignerAnswer.sponsorSigner; + } } const finalProjectName = answers.projectName; @@ -598,6 +628,10 @@ export async function init(projectName = null, autoAcceptDefaults = false) { '\n⚠️ Could not find a Neynar client ID and/or API key. Please configure Neynar manually in .env.local with NEYNAR_API_KEY and NEYNAR_CLIENT_ID' ); } + if (answers.seedPhrase) { + fs.appendFileSync(envPath, `\nSEED_PHRASE="${answers.seedPhrase}"`); + fs.appendFileSync(envPath, `\nSPONSOR_SIGNER="${answers.sponsorSigner}"`); + } fs.appendFileSync(envPath, `\nUSE_TUNNEL="${answers.useTunnel}"`); fs.unlinkSync(envExamplePath); diff --git a/scripts/build.js b/scripts/build.js index b680399..a4580ce 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -65,7 +65,7 @@ async function loadEnvLocal() { let newEnvContent = envContent; for (const [key, value] of Object.entries(localEnv)) { - if (key !== 'SEED_PHRASE') { + if (key !== 'SEED_PHRASE' && key !== 'SPONSOR_SIGNER') { // Update process.env process.env[key] = value; // Add to .env content if not already there @@ -87,6 +87,9 @@ async function loadEnvLocal() { if (localEnv.SEED_PHRASE) { process.env.SEED_PHRASE = localEnv.SEED_PHRASE; } + if (localEnv.SPONSOR_SIGNER) { + process.env.SPONSOR_SIGNER = localEnv.SPONSOR_SIGNER; + } } } catch (error) { // Error reading .env.local, which is fine @@ -370,6 +373,8 @@ async function main() { [`NEYNAR_API_KEY="${process.env.NEYNAR_API_KEY}"`] : []), ...(neynarClientId ? [`NEYNAR_CLIENT_ID="${neynarClientId}"`] : []), + ...(process.env.SPONSOR_SIGNER ? + [`SPONSOR_SIGNER="${process.env.SPONSOR_SIGNER}"`] : []), // FID (if it exists in current env) ...(process.env.FID ? [`FID="${process.env.FID}"`] : []), diff --git a/scripts/deploy.js b/scripts/deploy.js index ca53f97..1b4c0f8 100755 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -115,6 +115,7 @@ async function loadEnvLocal() { const allowedVars = [ 'SEED_PHRASE', + 'SPONSOR_SIGNER', 'NEXT_PUBLIC_MINI_APP_NAME', 'NEXT_PUBLIC_MINI_APP_DESCRIPTION', 'NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY', @@ -131,7 +132,7 @@ async function loadEnvLocal() { for (const [key, value] of Object.entries(localEnv)) { if (allowedVars.includes(key)) { process.env[key] = value; - if (key !== 'SEED_PHRASE' && !envContent.includes(`${key}=`)) { + if (key !== 'SEED_PHRASE' && key !== 'SPONSOR_SIGNER' && !envContent.includes(`${key}=`)) { newEnvContent += `${key}="${value}"\n`; } } @@ -224,6 +225,35 @@ async function checkRequiredEnvVars() { } else { console.log('ℹ️ Seed phrase will only be used for this deployment'); } + + // Ask about sponsor signer if SEED_PHRASE is provided + if (!process.env.SPONSOR_SIGNER) { + const { sponsorSigner } = await inquirer.prompt([ + { + type: 'confirm', + name: 'sponsorSigner', + message: + 'Do you want to sponsor the signer? (This will be used in Sign In With Neynar)\n' + + 'Note: If you choose to sponsor the signer, Neynar will sponsor it for you and you will be charged in CUs.', + default: false, + }, + ]); + + process.env.SPONSOR_SIGNER = sponsorSigner.toString(); + + if (storeSeedPhrase) { + fs.appendFileSync('.env.local', `\nSPONSOR_SIGNER="${sponsorSigner}"`); + console.log('✅ Sponsor signer preference stored in .env.local'); + } + } + } + } + + // Load SPONSOR_SIGNER from .env.local if SEED_PHRASE exists but SPONSOR_SIGNER doesn't + if (process.env.SEED_PHRASE && !process.env.SPONSOR_SIGNER && fs.existsSync('.env.local')) { + const localEnv = dotenv.parse(fs.readFileSync('.env.local')); + if (localEnv.SPONSOR_SIGNER) { + process.env.SPONSOR_SIGNER = localEnv.SPONSOR_SIGNER; } } } @@ -585,6 +615,7 @@ async function deployToVercel(useGitHub = false) { ...(process.env.NEYNAR_API_KEY && { NEYNAR_API_KEY: process.env.NEYNAR_API_KEY }), ...(process.env.NEYNAR_CLIENT_ID && { NEYNAR_CLIENT_ID: process.env.NEYNAR_CLIENT_ID }), + ...(process.env.SPONSOR_SIGNER && { SPONSOR_SIGNER: process.env.SPONSOR_SIGNER }), ...(miniAppMetadata && { MINI_APP_METADATA: miniAppMetadata }), ...Object.fromEntries(