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

Commit

Permalink
Merge pull request #103 from magiclabs/staging
Browse files Browse the repository at this point in the history
Network prompt bug
  • Loading branch information
jamesrp13 authored Sep 13, 2023
2 parents 76bfbb7 + 610e87d commit 055b487
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- 'master'
- 'main'
- 'staging'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions core/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function sayHello() {

useGracefulShutdown();

const { version, help, projectName, template, branch } = await parseFlags(globalOptions);
const { version, help, projectName, template, branch, network } = await parseFlags(globalOptions);

if (version) {
console.log(getMakeMagicVersion());
Expand All @@ -56,7 +56,7 @@ function sayHello() {
}

// Run the scaffold...
await createApp({ projectName, template, branch });
await createApp({ projectName, template, branch, network });
})().catch((err) => {
SharedAnalytics.logEvent('cli-tool-error', { error: err });
if (err instanceof ZombiError && err.code === ZombiErrorCode.USER_CANCELED_PROMPT) {
Expand Down
18 changes: 9 additions & 9 deletions core/create-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { parseFlags } from './flags';
import { addShutdownTask } from './utils/shutdown';
import { SharedAnalytics } from './analytics';
import { Chain, mapTemplateToChain, mapTemplateToProduct } from './utils/templateMappings';
import { BlockchainNetworkPrompt } from 'scaffolds/prompts';

const { Select, Input } = require('enquirer');

export interface CreateMagicAppData {
export interface CreateMagicAppData extends BlockchainNetworkPrompt.Data {
/**
* The `make-magic` project branch to source templates from.
*/
Expand Down Expand Up @@ -87,7 +88,6 @@ export async function createApp(config: CreateMagicAppConfig) {
config.projectName = projectName;
}

let network = '';
let chain: Chain | undefined = undefined;
let product: 'universal' | 'dedicated' | undefined = undefined;
if (!config.template) {
Expand All @@ -102,7 +102,7 @@ export async function createApp(config: CreateMagicAppConfig) {

if (configuration === 'quickstart') {
config.template = 'nextjs-universal-wallet';
network = 'polygon-mumbai';
config.network = 'polygon-mumbai';
product = 'universal';
chain = 'evm';
isChosenTemplateValid = true;
Expand All @@ -112,7 +112,7 @@ export async function createApp(config: CreateMagicAppConfig) {
product = mapTemplateToProduct(config.template);
}

if (!chain && !network) {
if (!chain && !config.network) {
chain = await new Select({
name: 'chain',
message: 'Which blockchain do you want to use?',
Expand All @@ -124,9 +124,9 @@ export async function createApp(config: CreateMagicAppConfig) {
}).run();
}

if (!network) {
if (!config.network) {
if (chain === 'solana') {
network = await new Select({
config.network = await new Select({
name: 'network',
message: 'Which network would you like to use?',
hint: 'We recommend starting with a test network',
Expand All @@ -140,7 +140,7 @@ export async function createApp(config: CreateMagicAppConfig) {
config.template = 'nextjs-solana-dedicated-wallet';
isChosenTemplateValid = true;
} else if (chain === 'flow') {
network = await new Select({
config.network = await new Select({
name: 'network',
message: 'Which network would you like to use?',
hint: 'We recommend starting with a test network',
Expand All @@ -150,7 +150,7 @@ export async function createApp(config: CreateMagicAppConfig) {
],
}).run();
} else if (chain === 'evm') {
network = await new Select({
config.network = await new Select({
name: 'network',
message: 'Which network would like to use?',
hint: 'We recommend starting with a test network',
Expand Down Expand Up @@ -197,7 +197,7 @@ export async function createApp(config: CreateMagicAppConfig) {
branch: config?.branch ?? 'master',
projectName: config?.projectName,
template: isChosenTemplateValid ? config.template : undefined,
network: network.length > 0 ? network : undefined,
network: config.network,
npmClient: 'npm',
})}
prompts={[
Expand Down
5 changes: 4 additions & 1 deletion core/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import chalk from 'chalk';
import { BINARY } from './config';
import { CreateMagicAppData } from './create-app';
import { Flags } from './flags';
import { BlockchainNetworkPrompt } from 'scaffolds/prompts';

export interface GlobalOptions extends Partial<CreateMagicAppData> {
export interface GlobalOptions extends Partial<CreateMagicAppData & BlockchainNetworkPrompt.Data> {
help?: boolean;
version?: boolean;
[key: string]: any;
Expand Down Expand Up @@ -41,4 +42,6 @@ export const globalOptions: Flags<GlobalOptions> = {
alias: 'v',
description: `Show which version of \`${BINARY}\` is currently in use.`,
},

...BlockchainNetworkPrompt.flags,
};

0 comments on commit 055b487

Please sign in to comment.