diff --git a/CHANGELOG.md b/CHANGELOG.md index 204dafc..66cf900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# v4.2.2 (Tue Sep 12 2023) + +#### 🚀 Enhancement + +- Fix bug where network isn't always added into template configuration + +#### Authors: 2 + +- James ([@jamesrp13](https://github.com/jamesrp13)) +- Aditya Kulkarni ([@AdityaKulkarni](https://github.com/AdityaKulkarni)) + # v4.2.0 (Mon Sep 11 2023) #### 🚀 Enhancement diff --git a/core/create-app.tsx b/core/create-app.tsx index ed5f70f..69ce4a6 100644 --- a/core/create-app.tsx +++ b/core/create-app.tsx @@ -20,6 +20,7 @@ import { printWarning } from './utils/errors-warnings'; import { parseFlags } from './flags'; import { addShutdownTask } from './utils/shutdown'; import { SharedAnalytics } from './analytics'; +import { Chain, mapTemplateToChain, mapTemplateToProduct } from './utils/templateMappings'; const { Select, Input } = require('enquirer'); @@ -57,7 +58,6 @@ export async function createApp(config: CreateMagicAppConfig) { const isProgrammaticFlow = !!config.data; const destinationRoot = process.cwd(); - let network = ''; const availableScaffolds = fs .readdirSync(resolveToDist('scaffolds')) @@ -87,7 +87,9 @@ export async function createApp(config: CreateMagicAppConfig) { config.projectName = projectName; } - let quickstart = false; + let network = ''; + let chain: Chain | undefined = undefined; + let product: 'universal' | 'dedicated' | undefined = undefined; if (!config.template) { const configuration = await new Select({ name: 'configuration', @@ -100,86 +102,90 @@ export async function createApp(config: CreateMagicAppConfig) { if (configuration === 'quickstart') { config.template = 'nextjs-universal-wallet'; + network = 'polygon-mumbai'; + product = 'universal'; + chain = 'evm'; isChosenTemplateValid = true; - quickstart = true; - } else { - const chain = await new Select({ - name: 'chain', - message: 'Which blockchain do you want to use?', + } + } else { + chain = mapTemplateToChain(config.template); + product = mapTemplateToProduct(config.template); + } + + if (!chain && !network) { + chain = await new Select({ + name: 'chain', + message: 'Which blockchain do you want to use?', + choices: [ + { name: 'evm', message: 'EVM (Ethereum, Polygon, etc.)' }, + { name: 'solana', message: 'Solana' }, + { name: 'flow', message: 'Flow' }, + ], + }).run(); + } + + if (!network) { + if (chain === 'solana') { + network = await new Select({ + name: 'network', + message: 'Which network would you like to use?', + hint: 'We recommend starting with a test network', choices: [ - { name: 'evm', message: 'EVM (Ethereum, Polygon, etc.)' }, - { name: 'solana', message: 'Solana' }, - { name: 'flow', message: 'Flow' }, + { name: 'solana-mainnet', message: 'Mainnet' }, + { name: 'solana-devnet', message: 'Devnet' }, ], }).run(); - if (chain === 'solana') { - network = await new Select({ - name: 'network', - message: 'Which network would you like to use?', - hint: 'We recommend starting with a test network', - choices: [ - { name: 'solana-mainnet', message: 'Mainnet' }, - { name: 'solana-devnet', message: 'Devnet' }, - ], - }).run(); - - config.template = 'nextjs-solana-dedicated-wallet'; - isChosenTemplateValid = true; - } else { - if (chain === 'flow') { - network = await new Select({ - name: 'network', - message: 'Which network would you like to use?', - hint: 'We recommend starting with a test network', - choices: [ - { name: 'flow-mainnet', message: 'Mainnet' }, - { name: 'flow-testnet', message: 'Testnet' }, - ], - }).run(); - } + product = 'dedicated'; + config.template = 'nextjs-solana-dedicated-wallet'; + isChosenTemplateValid = true; + } else if (chain === 'flow') { + network = await new Select({ + name: 'network', + message: 'Which network would you like to use?', + hint: 'We recommend starting with a test network', + choices: [ + { name: 'flow-mainnet', message: 'Mainnet' }, + { name: 'flow-testnet', message: 'Testnet' }, + ], + }).run(); + } else if (chain === 'evm') { + network = await new Select({ + name: 'network', + message: 'Which network would like to use?', + hint: 'We recommend starting with a test network', + choices: [ + { name: 'ethereum', message: 'Ethereum (Mainnet)' }, + { name: 'ethereum-goerli', message: 'Ethereum (Goerli Testnet)' }, + { name: 'polygon', message: 'Polygon (Mainnet)' }, + { name: 'polygon-mumbai', message: 'Polygon (Mumbai Testnet)' }, + ], + }).run(); + } + } - if (chain === 'evm') { - network = await new Select({ - name: 'network', - message: 'Which network would like to use?', - hint: 'We recommend starting with a test network', - choices: [ - { name: 'ethereum', message: 'Ethereum (Mainnet)' }, - { name: 'ethereum-goerli', message: 'Ethereum (Goerli Testnet)' }, - { name: 'polygon', message: 'Polygon (Mainnet)' }, - { name: 'polygon-mumbai', message: 'Polygon (Mumbai Testnet)' }, - ], - }).run(); - } + if (!product) { + product = await new Select({ + name: 'product', + message: 'Choose your wallet type', + choices: [ + { name: 'universal', message: 'Universal' }, + { name: 'dedicated', message: 'Dedicated' }, + ], + }).run(); - const product = await new Select({ - name: 'product', - message: 'Choose your wallet type', - choices: [ - { name: 'universal', message: 'Universal' }, - { name: 'dedicated', message: 'Dedicated' }, - ], - }).run(); - - if (product === 'universal') { - if (chain === 'flow') { - config.template = 'nextjs-flow-universal-wallet'; - } else { - config.template = 'nextjs-universal-wallet'; - } - } else if (chain === 'flow') { - config.template = 'nextjs-flow-dedicated-wallet'; - } else { - config.template = 'nextjs-dedicated-wallet'; - } - isChosenTemplateValid = true; + if (product === 'universal') { + if (chain === 'flow') { + config.template = 'nextjs-flow-universal-wallet'; + } else { + config.template = 'nextjs-universal-wallet'; } + } else if (chain === 'flow') { + config.template = 'nextjs-flow-dedicated-wallet'; + } else { + config.template = 'nextjs-dedicated-wallet'; } - } - - if (quickstart) { - network = 'polygon-mumbai'; + isChosenTemplateValid = true; } const template = ( diff --git a/core/utils/templateMappings.ts b/core/utils/templateMappings.ts new file mode 100644 index 0000000..fadff61 --- /dev/null +++ b/core/utils/templateMappings.ts @@ -0,0 +1,38 @@ +export type Chain = 'evm' | 'solana' | 'flow'; +export type Template = + | 'nextjs-dedicated-wallet' + | 'nextjs-universal-wallet' + | 'nextjs-solana-dedicated-wallet' + | 'nextjs-flow-universal-wallet' + | 'nextjs-flow-dedicated-wallet'; + +export type Product = 'universal' | 'dedicated'; + +export function mapTemplateToChain(template: string): Chain | undefined { + switch (template) { + case 'nextjs-dedicated-wallet': + case 'nextjs-universal-wallet': + return 'evm'; + case 'nextjs-solana-dedicated-wallet': + return 'solana'; + case 'nextjs-flow-universal-wallet': + case 'nextjs-flow-dedicated-wallet': + return 'flow'; + default: + return undefined; + } +} + +export function mapTemplateToProduct(template: string): Product | undefined { + switch (template) { + case 'nextjs-dedicated-wallet': + case 'nextjs-solana-dedicated-wallet': + case 'nextjs-flow-dedicated-wallet': + return 'dedicated'; + case 'nextjs-universal-wallet': + case 'nextjs-flow-universal-wallet': + return 'universal'; + default: + return undefined; + } +} diff --git a/package.json b/package.json index 6a82348..014cbd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "make-magic", - "version": "4.2.1", + "version": "4.2.2", "description": "A tool for quickly scaffolding an app with Magic authentication baked-in!", "repository": "magiclabs/create-magic-app", "license": "MIT", diff --git a/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx b/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx index ae6c6d7..332196e 100644 --- a/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx +++ b/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx @@ -8,7 +8,7 @@ type NextDedicatedWalletData = NpmClientPrompt.Data & PublishableApiKeyPrompt.Da export default createScaffold( (props) => ( - {(data) => { + {(data) => ( <>