Skip to content

Commit e0dcc22

Browse files
authored
Merge pull request #13 from magiclabs/PDEEXP-2143-add-kadena-to-make-magic-cli
Pdeexp 2143 add kadena to make magic cli
2 parents 91eddba + 9e1b078 commit e0dcc22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+11034
-11
lines changed

core/utils/templateMappings.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ import SolanaDedicatedScaffold, {
1717
flags as solanaDedicatedFlags,
1818
} from '../../scaffolds/nextjs-solana-dedicated-wallet/scaffold';
1919
import { Timer } from './timer';
20+
import KadenaDedicatedScaffold, {
21+
flags as kadenaDedicatedFlags,
22+
} from '../../scaffolds/nextjs-kadena-dedicated-wallet/scaffold';
2023

21-
export type Chain = 'evm' | 'solana' | 'flow';
22-
export type Template = 'nextjs-dedicated-wallet' | 'nextjs-solana-dedicated-wallet' | 'nextjs-flow-dedicated-wallet';
24+
export type Chain = 'evm' | 'solana' | 'flow' | 'kadena';
25+
export type Template =
26+
| 'nextjs-dedicated-wallet'
27+
| 'nextjs-solana-dedicated-wallet'
28+
| 'nextjs-flow-dedicated-wallet'
29+
| 'nextjs-kadena-dedicated-wallet';
2330

2431
type ConfigType = CreateMagicAppConfig & {
2532
chain: Chain | undefined;
@@ -36,6 +43,8 @@ function mapTemplateToChain(template: string): Chain | undefined {
3643
return 'solana';
3744
case 'nextjs-flow-dedicated-wallet':
3845
return 'flow';
46+
case 'nextjs-kadena-dedicated-wallet':
47+
return 'kadena';
3948
default:
4049
return undefined;
4150
}
@@ -81,6 +90,14 @@ export async function mapTemplateToScaffold(
8190
data.loginMethods = await AuthTypePrompt.loginMethodsPrompt();
8291
}
8392
return new FlowDedicatedScaffold(data);
93+
case 'nextjs-kadena-dedicated-wallet':
94+
if (!data.network) {
95+
data.network = await BlockchainNetworkPrompt.kadenaNetworkPrompt();
96+
}
97+
if (!data.loginMethods || data.loginMethods.length === 0) {
98+
data.loginMethods = await AuthTypePrompt.loginMethodsPrompt('kadena');
99+
}
100+
return new KadenaDedicatedScaffold(data);
84101
default:
85102
throw new Error(`Invalid template: ${template}`);
86103
}
@@ -94,6 +111,8 @@ export function mapTemplateToFlags(template: string): any {
94111
return solanaDedicatedFlags;
95112
case 'nextjs-flow-dedicated-wallet':
96113
return flowDedicatedFlags;
114+
case 'nextjs-kadena-dedicated-wallet':
115+
return kadenaDedicatedFlags;
97116
default:
98117
throw new Error(`Invalid template: ${template}`);
99118
}
@@ -108,6 +127,15 @@ const quickstartConfig = (config: ConfigType): ConfigType => ({
108127
isQuickstart: true,
109128
});
110129

130+
const evmConfig = async (config: ConfigType): Promise<ConfigType> => ({
131+
...config,
132+
template: 'nextjs-dedicated-wallet',
133+
network: await BlockchainNetworkPrompt.evmNetworkPrompt(),
134+
chain: 'evm',
135+
isChosenTemplateValid: true,
136+
isQuickstart: false,
137+
});
138+
111139
const solanaConfig = async (config: ConfigType): Promise<ConfigType> => ({
112140
...config,
113141
template: 'nextjs-solana-dedicated-wallet',
@@ -117,6 +145,24 @@ const solanaConfig = async (config: ConfigType): Promise<ConfigType> => ({
117145
isQuickstart: false,
118146
});
119147

148+
const flowConfig = async (config: ConfigType): Promise<ConfigType> => ({
149+
...config,
150+
template: 'nextjs-flow-dedicated-wallet',
151+
network: await BlockchainNetworkPrompt.flowNetworkPrompt(),
152+
chain: 'flow',
153+
isChosenTemplateValid: true,
154+
isQuickstart: false,
155+
});
156+
157+
const kadenaConfig = async (config: ConfigType): Promise<ConfigType> => ({
158+
...config,
159+
template: 'nextjs-kadena-dedicated-wallet',
160+
network: await BlockchainNetworkPrompt.kadenaNetworkPrompt(),
161+
chain: 'kadena',
162+
isChosenTemplateValid: true,
163+
isQuickstart: false,
164+
});
165+
120166
export const buildTemplate = async (appConfig: ConfigType): Promise<ConfigType> => {
121167
let config = { ...appConfig };
122168

@@ -144,13 +190,16 @@ export const buildTemplate = async (appConfig: ConfigType): Promise<ConfigType>
144190
config = await solanaConfig(config);
145191
break;
146192
case 'flow':
147-
config.network = await BlockchainNetworkPrompt.flowNetworkPrompt();
193+
config = await flowConfig(config);
194+
break;
195+
case 'kadena':
196+
config = await kadenaConfig(config);
148197
break;
149198
case 'evm':
150-
config.network = await BlockchainNetworkPrompt.evmNetworkPrompt();
199+
config = await evmConfig(config);
151200
break;
152201
default:
153-
config.network = await BlockchainNetworkPrompt.evmNetworkPrompt();
202+
config = await evmConfig(config);
154203
break;
155204
}
156205
} else {
@@ -165,17 +214,19 @@ export const buildTemplate = async (appConfig: ConfigType): Promise<ConfigType>
165214
'zksync-sepolia',
166215
];
167216
const solanaNetworks = ['solana-devnet', 'solana-mainnet'];
217+
const kadenaNetworks = ['kadena-testnet', 'kadena-mainnet'];
168218

169219
if (evmNetworks.includes(config.network)) {
170220
config.chain = 'evm';
171221
} else if (solanaNetworks.includes(config.network)) {
172222
config.chain = 'solana';
223+
} else if (kadenaNetworks.includes(config.network)) {
224+
config.chain = 'kadena';
173225
} else {
174226
config.chain = 'flow';
175227
}
176228
}
177229

178-
config.template = config.chain === 'flow' ? 'nextjs-flow-dedicated-wallet' : 'nextjs-dedicated-wallet';
179230
config.isChosenTemplateValid = true;
180231

181232
return config;

scaffolds/dev-data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ export const templateDevData = {
1717
loginMethods: ['EmailOTP', 'SMSOTP'],
1818
projectName: 'My Solana Dedicated Wallet',
1919
},
20+
'nextjs-kadena-dedicated-wallet': {
21+
network: 'kadena-testnet',
22+
publishableApiKey: 'pk_live_FD2D70B32ABE11BD',
23+
loginMethods: ['EmailOTP', 'SMSOTP'],
24+
projectName: 'My Kadena Dedicated Wallet',
25+
},
2026
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { Flags } from '../../core/flags';
2+
import BaseScaffold, { ExecaCommand } from '../../core/types/BaseScaffold';
3+
import { AuthTypePrompt, NpmClientPrompt, PublishableApiKeyPrompt } from '../prompts';
4+
5+
export type Data = NpmClientPrompt.Data & PublishableApiKeyPrompt.Data & AuthTypePrompt.Data;
6+
7+
export const flags: Flags<Partial<Data>> = {
8+
...NpmClientPrompt.flags,
9+
...PublishableApiKeyPrompt.flags,
10+
...AuthTypePrompt.flags,
11+
};
12+
13+
export const definition = {
14+
shortDescription: 'A dedicated wallet scaffold for Next.js using Kadena',
15+
featured: true,
16+
};
17+
18+
export default class KadenaDedicatedScaffold extends BaseScaffold {
19+
public templateName = 'nextjs-kadena-dedicated-wallet';
20+
21+
private data: Data;
22+
23+
public installationCommand: ExecaCommand = { command: 'npm', args: ['install'] };
24+
25+
public startCommand: ExecaCommand = { command: 'npm', args: ['run', 'dev'] };
26+
27+
public source: string | string[] = [
28+
'./public/favicon.ico',
29+
'./public/logo.svg',
30+
'./public/info.svg',
31+
'./public/link.svg',
32+
'./public/link_white.svg',
33+
'./public/redirect_bg.png',
34+
'./public/login_bg.png',
35+
'./.env.example',
36+
'./.eslintrc.json',
37+
'./.gitignore',
38+
'./package.json',
39+
'./postcss.config.js',
40+
'./tailwind.config.js',
41+
'./tsconfig.json',
42+
'./README.md',
43+
'./src/components/ui',
44+
'./src/components/magic/cards',
45+
'./src/components/magic/wallet-methods/Disconnect.tsx',
46+
'./src/components/magic/wallet-methods/GetIdToken.tsx',
47+
'./src/components/magic/wallet-methods/GetMetadata.tsx',
48+
'./src/components/magic/Dashboard.tsx',
49+
'./src/components/magic/DevLinks.tsx',
50+
'./src/components/magic/Header.tsx',
51+
'./src/components/magic/Login.tsx',
52+
'./src/components/magic/MagicProvider.tsx',
53+
'./src/components/magic/MagicDashboardRedirect.tsx',
54+
'./src/pages',
55+
'./src/styles',
56+
'./src/utils',
57+
'./src/pact',
58+
];
59+
60+
constructor(data: Data) {
61+
super();
62+
this.data = data;
63+
64+
if (typeof this.source !== 'string') {
65+
this.data.loginMethods = this.data.loginMethods.map((authType) =>
66+
AuthTypePrompt.mapInputToLoginMethods(authType),
67+
);
68+
this.data.loginMethods.forEach((authType) => {
69+
(this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`);
70+
if (
71+
authType === 'Discord' ||
72+
authType === 'Facebook' ||
73+
authType === 'Github' ||
74+
authType === 'Google' ||
75+
authType === 'Twitch' ||
76+
authType === 'Twitter'
77+
) {
78+
(this.source as string[]).push(`./public/social/${authType.replaceAll(' ', '')}.svg`);
79+
}
80+
if (authType.replaceAll(' ', '') === 'EmailOTP') {
81+
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdateEmail.tsx');
82+
}
83+
});
84+
}
85+
}
86+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Publishable API Key found in the Magic Dashboard
2+
NEXT_PUBLIC_MAGIC_API_KEY=<%= publishableApiKey %>
3+
4+
# The blockchain network
5+
NEXT_PUBLIC_BLOCKCHAIN_NETWORK=<%= network %>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"quotes": [1, "single"],
5+
"indent": [1, 2]
6+
}
7+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# env files
28+
.env
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
37+
38+
#environment
39+
.env
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This scaffold is meant to help you bootstrap your own projects with Magic's [Dedicated Wallet](https://magic.link/docs/auth/overview). Magic is a developer SDK that integrates with your application to enable passwordless Web3 onboarding.
2+
3+
The folder structure of this scaffold is designed to encapsulate all things Magic into one place so you can easily add or remove components and functionality. For example, all Magic-specific components are in the `src/components/magic` directory while generic UI components are in the `src/components/ui` directory.
4+
5+
## Next.js
6+
7+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
8+
9+
### Getting Started
10+
11+
First, run the development server:
12+
13+
```bash
14+
npm run dev
15+
# or
16+
yarn dev
17+
# or
18+
pnpm dev
19+
```
20+
21+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
22+
23+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
24+
25+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
26+
27+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
28+
29+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
30+
31+
### Learn More
32+
33+
To learn more about Next.js, take a look at the following resources:
34+
35+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
36+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
37+
38+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
39+
40+
### Deploy on Vercel
41+
42+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
43+
44+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)