Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Fix data not being provided to zombi
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrp13 committed Sep 12, 2023
1 parent 183f445 commit c4efcc4
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 77 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
152 changes: 79 additions & 73 deletions core/create-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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',
Expand All @@ -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 = (
Expand Down
38 changes: 38 additions & 0 deletions core/utils/templateMappings.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type NextDedicatedWalletData = NpmClientPrompt.Data & PublishableApiKeyPrompt.Da
export default createScaffold<NextDedicatedWalletData>(
(props) => (
<Zombi {...props} prompts={mergePrompts(AuthTypePrompt.questions, PublishableApiKeyPrompt.questions)}>
{(data) => {
{(data) => (
<>
<Template source="./public/background.svg" />
<Template source="./public/favicon.ico" />
Expand Down Expand Up @@ -59,8 +59,8 @@ export default createScaffold<NextDedicatedWalletData>(
</React.Fragment>
),
)}
</>;
}}
</>
)}
</Zombi>
),

Expand Down

0 comments on commit c4efcc4

Please sign in to comment.