create-near-app 6.0.2 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/dist/messages.js +37 -12
  3. package/dist/types.js +1 -1
  4. package/dist/user-input.js +2 -1
  5. package/package.json +1 -1
  6. package/templates/contracts/rs/Cargo.toml +3 -0
  7. package/templates/frontend/next-page/README.md +36 -0
  8. package/templates/frontend/next-page/jsconfig.json +7 -0
  9. package/templates/frontend/next-page/next.config.js +6 -0
  10. package/templates/frontend/next-page/package-lock.json +14642 -0
  11. package/templates/frontend/next-page/package.json +43 -0
  12. package/templates/frontend/next-page/public/favicon.ico +0 -0
  13. package/templates/frontend/next-page/public/near-logo.svg +43 -0
  14. package/templates/frontend/next-page/public/near.svg +1 -0
  15. package/templates/frontend/next-page/public/next.svg +1 -0
  16. package/templates/frontend/next-page/public/vercel.svg +1 -0
  17. package/templates/frontend/next-page/src/components/cards.js +43 -0
  18. package/templates/frontend/next-page/src/components/navigation.js +36 -0
  19. package/templates/frontend/next-page/src/components/vm-component.js +26 -0
  20. package/templates/frontend/next-page/src/config.js +21 -0
  21. package/templates/frontend/next-page/src/layout.js +17 -0
  22. package/templates/frontend/next-page/src/pages/_app.js +10 -0
  23. package/templates/frontend/next-page/src/pages/_document.js +17 -0
  24. package/templates/frontend/next-page/src/pages/hello-components/index.js +48 -0
  25. package/templates/frontend/next-page/src/pages/hello-near/index.js +78 -0
  26. package/templates/frontend/next-page/src/pages/index.js +41 -0
  27. package/templates/frontend/next-page/src/styles/app.module.css +228 -0
  28. package/templates/frontend/next-page/src/styles/globals.css +95 -0
  29. package/templates/frontend/next-page/src/wallets/wallet-selector.js +120 -0
  30. package/templates/frontend/next-page/src/wallets/web3-wallet.ts +289 -0
  31. /package/templates/frontend/{next → next-app}/README.md +0 -0
  32. /package/templates/frontend/{next → next-app}/jsconfig.json +0 -0
  33. /package/templates/frontend/{next → next-app}/next.config.js +0 -0
  34. /package/templates/frontend/{next → next-app}/package.json +0 -0
  35. /package/templates/frontend/{next → next-app}/public/near-logo.svg +0 -0
  36. /package/templates/frontend/{next → next-app}/public/near.svg +0 -0
  37. /package/templates/frontend/{next → next-app}/public/next.svg +0 -0
  38. /package/templates/frontend/{next → next-app}/public/vercel.svg +0 -0
  39. /package/templates/frontend/{next → next-app}/src/app/app.module.css +0 -0
  40. /package/templates/frontend/{next → next-app}/src/app/favicon.ico +0 -0
  41. /package/templates/frontend/{next → next-app}/src/app/globals.css +0 -0
  42. /package/templates/frontend/{next → next-app}/src/app/hello-components/page.js +0 -0
  43. /package/templates/frontend/{next → next-app}/src/app/hello-near/page.js +0 -0
  44. /package/templates/frontend/{next → next-app}/src/app/layout.js +0 -0
  45. /package/templates/frontend/{next → next-app}/src/app/page.js +0 -0
  46. /package/templates/frontend/{next → next-app}/src/components/cards.js +0 -0
  47. /package/templates/frontend/{next → next-app}/src/components/navigation.js +0 -0
  48. /package/templates/frontend/{next → next-app}/src/components/vm-component.js +0 -0
  49. /package/templates/frontend/{next → next-app}/src/config.js +0 -0
  50. /package/templates/frontend/{next → next-app}/src/wallets/wallet-selector.js +0 -0
  51. /package/templates/frontend/{next → next-app}/src/wallets/web3-wallet.ts +0 -0
@@ -0,0 +1,95 @@
1
+ @import 'bootstrap';
2
+ @import 'bootstrap-icons';
3
+
4
+ :root {
5
+ --max-width: 1100px;
6
+ --border-radius: 12px;
7
+
8
+ --foreground-rgb: 0, 0, 0;
9
+ --background-start-rgb: 214, 219, 220;
10
+ --background-end-rgb: 255, 255, 255;
11
+
12
+ --primary-glow: conic-gradient(from 180deg at 50% 50%,
13
+ #16abff33 0deg,
14
+ #0885ff33 55deg,
15
+ #54d6ff33 120deg,
16
+ #0071ff33 160deg,
17
+ transparent 360deg);
18
+ --secondary-glow: radial-gradient(rgba(255, 255, 255, 1),
19
+ rgba(255, 255, 255, 0));
20
+
21
+ --tile-start-rgb: 239, 245, 249;
22
+ --tile-end-rgb: 228, 232, 233;
23
+ --tile-border: conic-gradient(#00000080,
24
+ #00000040,
25
+ #00000030,
26
+ #00000020,
27
+ #00000010,
28
+ #00000010,
29
+ #00000080);
30
+
31
+ --callout-rgb: 238, 240, 241;
32
+ --callout-border-rgb: 172, 175, 176;
33
+ --card-rgb: 180, 185, 188;
34
+ --card-border-rgb: 131, 134, 135;
35
+ }
36
+
37
+ @media (prefers-color-scheme: dark) {
38
+ :root {
39
+ --foreground-rgb: 255, 255, 255;
40
+ --background-start-rgb: 0, 0, 0;
41
+ --background-end-rgb: 0, 0, 0;
42
+
43
+ --primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
44
+ --secondary-glow: linear-gradient(to bottom right,
45
+ rgba(1, 65, 255, 0),
46
+ rgba(1, 65, 255, 0),
47
+ rgba(1, 65, 255, 0.3));
48
+
49
+ --tile-start-rgb: 2, 13, 46;
50
+ --tile-end-rgb: 2, 5, 19;
51
+ --tile-border: conic-gradient(#ffffff80,
52
+ #ffffff40,
53
+ #ffffff30,
54
+ #ffffff20,
55
+ #ffffff10,
56
+ #ffffff10,
57
+ #ffffff80);
58
+
59
+ --callout-rgb: 20, 20, 20;
60
+ --callout-border-rgb: 108, 108, 108;
61
+ --card-rgb: 100, 100, 100;
62
+ --card-border-rgb: 200, 200, 200;
63
+ }
64
+ }
65
+
66
+ * {
67
+ box-sizing: border-box;
68
+ padding: 0;
69
+ margin: 0;
70
+ }
71
+
72
+ html,
73
+ body {
74
+ max-width: 100vw;
75
+ overflow-x: hidden;
76
+ }
77
+
78
+ body {
79
+ color: rgb(var(--foreground-rgb));
80
+ background: linear-gradient(to bottom,
81
+ transparent,
82
+ rgb(var(--background-end-rgb))) rgb(var(--background-start-rgb));
83
+ font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Droid Sans, Helvetica Neue, sans-serif;
84
+ }
85
+
86
+ a {
87
+ color: inherit;
88
+ text-decoration: none;
89
+ }
90
+
91
+ @media (prefers-color-scheme: dark) {
92
+ html {
93
+ color-scheme: dark;
94
+ }
95
+ }
@@ -0,0 +1,120 @@
1
+ import { create as createStore } from 'zustand';
2
+ import { distinctUntilChanged, map } from 'rxjs';
3
+ import { providers } from 'near-api-js';
4
+ import { setupWalletSelector } from '@near-wallet-selector/core';
5
+ import { setupModal } from '@near-wallet-selector/modal-ui';
6
+ import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
7
+ import { setupHereWallet } from '@near-wallet-selector/here-wallet';
8
+
9
+ import { useEffect, useState } from 'react';
10
+
11
+ export const useWallet = createStore(set => ({
12
+ signedAccountId: '',
13
+ logOut: undefined,
14
+ logIn: undefined,
15
+ selector: undefined,
16
+ viewMethod: undefined,
17
+ callMethod: undefined,
18
+ setLogActions: ({ logOut, logIn }) => set({ logOut, logIn }),
19
+ setAuth: ({ signedAccountId }) => set({ signedAccountId }),
20
+ setMethods: ({ viewMethod, callMethod }) => set({ viewMethod, callMethod }),
21
+ setStoreSelector: ({ selector }) => set({ selector }),
22
+ }));
23
+
24
+ export function useInitWallet({ createAccessKeyFor, networkId }) {
25
+ const setAuth = useWallet(store => store.setAuth);
26
+ const setLogActions = useWallet(store => store.setLogActions);
27
+ const setMethods = useWallet(store => store.setMethods);
28
+ const setStoreSelector = useWallet(store => store.setStoreSelector);
29
+ const [selector, setSelector] = useState(undefined);
30
+
31
+ useEffect(() => {
32
+ const selector = setupWalletSelector({
33
+ network: networkId,
34
+ modules: [setupMyNearWallet(), setupHereWallet()]
35
+ });
36
+
37
+ setSelector(selector);
38
+ setStoreSelector({ selector });
39
+ }, [networkId, setStoreSelector]);
40
+
41
+ useEffect(() => {
42
+ if (!selector) return;
43
+
44
+ selector.then(walletSelector => {
45
+ const accounts = walletSelector.store.getState().accounts;
46
+ const signedAccountId = accounts.find((account) => account.active)?.accountId || '';
47
+ setAuth({ signedAccountId });
48
+
49
+ walletSelector.store.observable
50
+ .pipe(
51
+ map((state) => state.accounts),
52
+ distinctUntilChanged()
53
+ )
54
+ .subscribe((accounts) => {
55
+ const signedAccountId = accounts.find((account) => account.active)?.accountId || '';
56
+ setAuth({ signedAccountId });
57
+ });
58
+ });
59
+ }, [selector, setAuth]);
60
+
61
+ useEffect(() => {
62
+ if (!selector) return;
63
+
64
+ // defined logOut and logIn actions
65
+ const logOut = async () => {
66
+ const wallet = await (await selector).wallet();
67
+ await wallet.signOut();
68
+ setAuth({ signedAccountId: '' });
69
+ };
70
+
71
+ const logIn = async () => {
72
+ const modal = setupModal(await selector, { contractId: createAccessKeyFor });
73
+ modal.show();
74
+ };
75
+
76
+ setLogActions({ logOut, logIn });
77
+ }, [createAccessKeyFor, selector, setAuth, setLogActions]);
78
+
79
+ useEffect(() => {
80
+ if (!selector) return;
81
+
82
+ const viewMethod = async (contractId, method, args = {}) => {
83
+ const { network } = (await selector).options;
84
+ const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
85
+
86
+ let res = await provider.query({
87
+ request_type: 'call_function',
88
+ account_id: contractId,
89
+ method_name: method,
90
+ args_base64: Buffer.from(JSON.stringify(args)).toString('base64'),
91
+ finality: 'optimistic',
92
+ });
93
+ return JSON.parse(Buffer.from(res.result).toString());
94
+ };
95
+
96
+ const callMethod = async (contractId, method, args = {}, gas = '30000000000000', deposit = 0) => {
97
+ const wallet = await (await selector).wallet();
98
+
99
+ const outcome = await wallet.signAndSendTransaction({
100
+ receiverId: contractId,
101
+ actions: [
102
+ {
103
+ type: 'FunctionCall',
104
+ params: {
105
+ methodName: method,
106
+ args,
107
+ gas,
108
+ deposit,
109
+ },
110
+ },
111
+ ],
112
+ });
113
+
114
+ return providers.getTransactionLastResult(outcome);
115
+ };
116
+
117
+ setMethods({ viewMethod, callMethod });
118
+
119
+ }, [selector, setMethods]);
120
+ }
@@ -0,0 +1,289 @@
1
+ 'use client';
2
+ import type { EIP1193Provider } from '@web3-onboard/core';
3
+ import injectedModule from '@web3-onboard/injected-wallets';
4
+ import ledgerModule from '@web3-onboard/ledger';
5
+ import { init, useConnectWallet } from '@web3-onboard/react';
6
+ import walletConnectModule from '@web3-onboard/walletconnect';
7
+ import { useEffect, useState } from 'react';
8
+ import { singletonHook } from 'react-singleton-hook';
9
+
10
+ const web3onboardKey = 'web3-onboard:connectedWallets';
11
+
12
+ const wcV2InitOptions: any = {
13
+ version: 2,
14
+ projectId: '72b7b3359ab477e339a070f615806aa6',
15
+ requiredChains: [1, 56],
16
+ };
17
+
18
+ const walletConnect = walletConnectModule(wcV2InitOptions);
19
+ const ledger = ledgerModule(wcV2InitOptions);
20
+ const injected = injectedModule();
21
+
22
+ // initialize Onboard
23
+ export const onboard = init({
24
+ wallets: [injected, walletConnect, ledger],
25
+ chains: [
26
+ {
27
+ id: 1,
28
+ token: 'ETH',
29
+ label: 'Ethereum Mainnet',
30
+ rpcUrl: 'https://rpc.ankr.com/eth',
31
+ },
32
+ {
33
+ id: 3,
34
+ token: 'ETH',
35
+ label: 'Ropsten - Ethereum Testnet',
36
+ rpcUrl: 'https://rpc.ankr.com/eth_ropsten',
37
+ },
38
+ {
39
+ id: 5,
40
+ token: 'ETH',
41
+ label: 'Goerli - Ethereum Testnet',
42
+ rpcUrl: 'https://rpc.ankr.com/eth_goerli',
43
+ },
44
+ {
45
+ id: 10,
46
+ token: 'ETH',
47
+ label: 'Optimism',
48
+ rpcUrl: 'https://rpc.ankr.com/optimism',
49
+ },
50
+ {
51
+ id: 420,
52
+ token: 'ETH',
53
+ label: 'Optimism Goerli Testnet',
54
+ rpcUrl: 'https://optimism-goerli.publicnode.com',
55
+ },
56
+ {
57
+ id: 56,
58
+ token: 'BNB',
59
+ label: 'Binance Smart Chain Mainnet',
60
+ rpcUrl: 'https://bsc.publicnode.com',
61
+ },
62
+ {
63
+ id: 97,
64
+ token: 'tBNB',
65
+ label: 'Binance Smart Chain Testnet',
66
+ rpcUrl: 'https://bsc-testnet.publicnode.com',
67
+ },
68
+ {
69
+ id: 1313161554,
70
+ token: 'ETH',
71
+ label: 'Aurora Mainnet',
72
+ rpcUrl: 'https://mainnet.aurora.dev',
73
+ },
74
+ {
75
+ id: 1313161555,
76
+ token: 'ETH',
77
+ label: 'Aurora Testnet',
78
+ rpcUrl: 'https://testnet.aurora.dev',
79
+ },
80
+ {
81
+ id: 137,
82
+ token: 'MATIC',
83
+ label: 'Polygon Mainnet',
84
+ rpcUrl: 'https://rpc.ankr.com/polygon',
85
+ },
86
+ {
87
+ id: 80001,
88
+ token: 'MATIC',
89
+ label: 'Polygon Testnet Mumbai',
90
+ rpcUrl: 'https://rpc.ankr.com/polygon_mumbai',
91
+ },
92
+ {
93
+ id: 280,
94
+ token: 'ETH',
95
+ label: 'zkSync Era Testnet',
96
+ rpcUrl: 'https://testnet.era.zksync.dev',
97
+ },
98
+ {
99
+ id: 324,
100
+ token: 'ETH',
101
+ label: 'zkSync Era Mainnet',
102
+ rpcUrl: 'https://zksync2-mainnet.zksync.io',
103
+ },
104
+ {
105
+ id: 1101,
106
+ token: 'ETH',
107
+ label: 'Polygon zkEVM',
108
+ rpcUrl: 'https://zkevm-rpc.com',
109
+ },
110
+ {
111
+ id: 1442,
112
+ token: 'ETH',
113
+ label: 'Polygon zkEVM Testnet',
114
+ rpcUrl: 'https://rpc.public.zkevm-test.net',
115
+ },
116
+ {
117
+ id: 42161,
118
+ token: 'ETH',
119
+ label: 'Arbitrum One Mainnet',
120
+ rpcUrl: 'https://arb1.arbitrum.io/rpc',
121
+ },
122
+ {
123
+ id: 42170,
124
+ token: 'ETH',
125
+ label: 'Arbitrum Nova',
126
+ rpcUrl: 'https://nova.arbitrum.io/rpc',
127
+ },
128
+ {
129
+ id: 421613,
130
+ token: 'AGOR',
131
+ label: 'Arbitrum Goerli',
132
+ rpcUrl: 'https://goerli-rollup.arbitrum.io/rpc',
133
+ },
134
+ {
135
+ id: 25,
136
+ token: 'CRO',
137
+ label: 'Cronos Mainnet Beta',
138
+ rpcUrl: 'https://evm.cronos.org',
139
+ },
140
+ {
141
+ id: 338,
142
+ token: 'TCRO',
143
+ label: 'Cronos Testnet',
144
+ rpcUrl: 'https://evm-t3.cronos.org',
145
+ },
146
+ {
147
+ id: 100,
148
+ token: 'XDAI',
149
+ label: 'Gnosis',
150
+ rpcUrl: 'https://rpc.ankr.com/gnosis',
151
+ },
152
+ {
153
+ id: 10200,
154
+ token: 'XDAI',
155
+ label: 'Gnosis Chiado Testnet',
156
+ rpcUrl: 'https://rpc.chiadochain.net',
157
+ },
158
+ {
159
+ id: 42220,
160
+ token: 'CELO',
161
+ label: 'Celo Mainnet',
162
+ rpcUrl: 'https://rpc.ankr.com/celo',
163
+ },
164
+ {
165
+ id: 44787,
166
+ token: 'CELO',
167
+ label: 'Celo Alfajores Testnet',
168
+ rpcUrl: 'https://alfajores-forno.celo-testnet.org',
169
+ },
170
+ {
171
+ id: 43114,
172
+ token: 'AVAX',
173
+ label: 'Avalanche C-Chain',
174
+ rpcUrl: 'https://rpc.ankr.com/avalanche',
175
+ },
176
+ {
177
+ id: 43113,
178
+ token: 'AVAX',
179
+ label: 'Avalanche Fuji Testnet',
180
+ rpcUrl: 'https://rpc.ankr.com/avalanche_fuji',
181
+ },
182
+ {
183
+ id: 250,
184
+ token: 'FTM',
185
+ label: 'Fantom Opera',
186
+ rpcUrl: 'https://rpc.ankr.com/fantom',
187
+ },
188
+ {
189
+ id: 4002,
190
+ token: 'FTM',
191
+ label: 'Fantom Testnet',
192
+ rpcUrl: 'https://rpc.ankr.com/fantom_testnet',
193
+ },
194
+ {
195
+ id: 1284,
196
+ token: 'GLMR',
197
+ label: 'Moonbeam',
198
+ rpcUrl: 'https://rpc.ankr.com/moonbeam',
199
+ },
200
+ {
201
+ id: 61,
202
+ token: 'ETC',
203
+ label: 'Ethereum Classic Mainnet',
204
+ rpcUrl: 'https://etc.rivet.link',
205
+ },
206
+ {
207
+ id: 84531,
208
+ token: 'ETH',
209
+ label: 'Base Goerli Testnet',
210
+ rpcUrl: 'https://goerli.base.org',
211
+ },
212
+ {
213
+ id: 8453,
214
+ token: 'ETH',
215
+ label: 'Base',
216
+ rpcUrl: 'https://mainnet.base.org',
217
+ },
218
+ {
219
+ id: 5001,
220
+ token: 'MNT',
221
+ label: 'Mantle Testnet',
222
+ rpcUrl: 'https://rpc.testnet.mantle.xyz',
223
+ },
224
+ {
225
+ id: 5000,
226
+ token: 'MNT',
227
+ label: 'Mantle',
228
+ rpcUrl: 'https://rpc.mantle.xyz',
229
+ },
230
+ ],
231
+ appMetadata: {
232
+ name: 'NEAR',
233
+ icon: '/next.svg',
234
+ description: 'NEAR',
235
+ },
236
+ theme: 'dark',
237
+ containerElements: {
238
+ // connectModal: '#near-social-navigation-bar',
239
+ // accountCenter: "#near-social-web3-account",
240
+ },
241
+ });
242
+
243
+ type EthersProviderContext = {
244
+ provider?: EIP1193Provider;
245
+ useConnectWallet: typeof useConnectWallet;
246
+ };
247
+
248
+ const defaultEthersProviderContext: EthersProviderContext = { useConnectWallet };
249
+
250
+ export const useEthersProviderContext = singletonHook(defaultEthersProviderContext, () => {
251
+ const [{ wallet }] = useConnectWallet();
252
+ const [ethersProvider, setEthersProvider] = useState(defaultEthersProviderContext);
253
+
254
+ useEffect(() => {
255
+ (async () => {
256
+ if (typeof localStorage === 'undefined') return;
257
+
258
+ const walletsSub = onboard.state.select('wallets');
259
+
260
+ walletsSub.subscribe((wallets) => {
261
+ const connectedWallets = wallets.map(({ label }) => label);
262
+ localStorage.setItem(web3onboardKey, JSON.stringify(connectedWallets));
263
+ });
264
+
265
+ const previouslyConnectedWallets = JSON.parse(localStorage.getItem(web3onboardKey) || '[]');
266
+
267
+ if (previouslyConnectedWallets) {
268
+ // You can also auto connect "silently" and disable all onboard modals to avoid them flashing on page load
269
+ await onboard.connectWallet({
270
+ autoSelect: {
271
+ label: previouslyConnectedWallets[0],
272
+ disableModals: true,
273
+ },
274
+ });
275
+ }
276
+ })();
277
+ }, []);
278
+
279
+ useEffect(() => {
280
+ if (!wallet) return;
281
+
282
+ setEthersProvider({
283
+ provider: wallet.provider,
284
+ useConnectWallet,
285
+ });
286
+ }, [wallet]);
287
+
288
+ return ethersProvider;
289
+ });
File without changes