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 #104 from Unboxed-Software/master
Browse files Browse the repository at this point in the history
Update quickstart and add default analytics
  • Loading branch information
jamesrp13 authored Sep 14, 2023
2 parents 055b487 + 947db81 commit 4d9b6d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
18 changes: 14 additions & 4 deletions core/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parseFlags } from './flags';
import { globalOptions } from './global-options';
import { shutdown, useGracefulShutdown } from './utils/shutdown';
import { SharedAnalytics } from './analytics';
import { promptForUsageDataIfNeeded } from './utils/usagePermissions';
import { modifyUsageConsent, initializeUsageConfigIfneeded } from './utils/usagePermissions';
import { loadConfig } from './config';
import suppressWarnings from './utils/suppress-experimental-warnings';

Expand All @@ -34,7 +34,9 @@ function sayHello() {

useGracefulShutdown();

const { version, help, projectName, template, branch, network } = await parseFlags(globalOptions);
const { version, help, projectName, template, branch, network, shareUsageData } = await parseFlags(globalOptions);
const collectUsageData = await initializeUsageConfigIfneeded();
const config = loadConfig();

if (version) {
console.log(getMakeMagicVersion());
Expand All @@ -47,10 +49,18 @@ function sayHello() {
shutdown(0);
}

if (shareUsageData !== undefined) {
const consent = await modifyUsageConsent(shareUsageData);
if (consent) {
console.log('Thanks for helping us improve the developer experience by sharing anonymous usage data!');
} else {
console.log('You are now opted out of sharing anonymous usage data.');
}
shutdown(0);
}

sayHello();

const collectUsageData = await promptForUsageDataIfNeeded();
const config = loadConfig();
if (collectUsageData && config?.id) {
SharedAnalytics.identifyUser(config.id);
}
Expand Down
10 changes: 6 additions & 4 deletions core/create-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,21 @@ export async function createApp(config: CreateMagicAppConfig) {

let chain: Chain | undefined = undefined;
let product: 'universal' | 'dedicated' | undefined = undefined;
let configuration = '';
if (!config.template) {
const configuration = await new Select({
configuration = await new Select({
name: 'configuration',
message: 'Select a configuration to start with:',
choices: [
{ name: 'quickstart', message: 'Quickstart (Nextjs, Universal Wallet, Polygon Testnet)' },
{ name: 'quickstart', message: 'Quickstart (Nextjs, Dedicated Wallet, Polygon Testnet, Email OTP)' },
{ name: 'custom', message: 'Custom Setup (Choose product, network, etc.)' },
],
}).run();

if (configuration === 'quickstart') {
config.template = 'nextjs-universal-wallet';
config.template = 'nextjs-dedicated-wallet';
config.network = 'polygon-mumbai';
product = 'universal';
product = 'dedicated';
chain = 'evm';
isChosenTemplateValid = true;
}
Expand Down Expand Up @@ -199,6 +200,7 @@ export async function createApp(config: CreateMagicAppConfig) {
template: isChosenTemplateValid ? config.template : undefined,
network: config.network,
npmClient: 'npm',
loginMethods: configuration === 'quickstart' ? ['EmailOTP'] : undefined,
})}
prompts={[
{
Expand Down
6 changes: 6 additions & 0 deletions core/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@ export const globalOptions: Flags<GlobalOptions> = {
description: `Show which version of \`${BINARY}\` is currently in use.`,
},

shareUsageData: {
type: Boolean,
description:
'A boolean representing whether or not to share anonymous usage data with Magic. The data cannot be traced back to you and is used to improve the developer experience.',
},

...BlockchainNetworkPrompt.flags,
};
20 changes: 7 additions & 13 deletions core/utils/usagePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import crypto from 'crypto';
import { loadConfig, saveConfig } from '../config';

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

export const promptForUsageDataIfNeeded = async (): Promise<boolean> => {
export const initializeUsageConfigIfneeded = async (): Promise<boolean> => {
let config = await loadConfig();

if (!config) {
const answer = await promptForUsageData();
config = { shouldTrackUsageData: answer };
config = { shouldTrackUsageData: true };
await saveConfig(config);
}

Expand All @@ -22,12 +19,9 @@ export const promptForUsageDataIfNeeded = async (): Promise<boolean> => {
return config.shouldTrackUsageData ?? false;
};

const promptForUsageData = async (): Promise<boolean> => {
const answer = await new Select({
name: 'analytics',
message: 'Would you like to help us improve this tool by allowing us to collect anonymous usage data?',
choices: [{ name: 'Yes' }, { name: 'No' }],
}).run();

return answer === 'Yes';
export const modifyUsageConsent = async (shouldTrackUsageData: boolean) => {
let config = await loadConfig();
config = { ...config, shouldTrackUsageData };
await saveConfig(config);
return config?.shouldTrackUsageData ?? false;
};

0 comments on commit 4d9b6d1

Please sign in to comment.