create-near-app 6.0.0-beta.5 → 6.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "6.0.0-beta.5",
3
+ "version": "6.0.0",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -2,6 +2,9 @@
2
2
  "name": "hello_near",
3
3
  "version": "1.0.0",
4
4
  "license": "(MIT AND Apache-2.0)",
5
+ "engines": {
6
+ "node": "16.x"
7
+ },
5
8
  "type": "module",
6
9
  "scripts": {
7
10
  "build": "near-sdk-js build src/contract.ts build/hello_near.wasm",
@@ -2,6 +2,9 @@
2
2
  "name": "hello-near",
3
3
  "version": "1.0.0",
4
4
  "private": true,
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
5
8
  "scripts": {
6
9
  "dev": "next dev",
7
10
  "build": "next build",
@@ -1,6 +1,6 @@
1
1
  import dynamic from 'next/dynamic';
2
2
 
3
- import styles from '@/app/app.module.css'
3
+ import styles from '@/app/app.module.css';
4
4
  import { DocsCard, HelloNearCard } from '@/components/cards';
5
5
  import { NetworkId, ComponentMap } from '@/config';
6
6
 
@@ -12,33 +12,33 @@ export default function HelloComponents() {
12
12
 
13
13
  return (
14
14
  <>
15
- <main className={styles.main}>
16
- <div className={styles.description}>
17
- <p>
18
- Loading components from: &nbsp;
19
- <code className={styles.code}>{socialComponents.socialDB}</code>
20
- </p>
21
- </div>
22
- <div className={styles.center}>
23
- <h1> <code>Multi-chain</code> Components Made Simple </h1>
24
- </div>
25
- <div className='row'>
26
- <div class="col-6">
27
- <Component src={socialComponents.HelloNear} />
28
- <p class="my-4">&nbsp;</p>
29
- <Component src={socialComponents.LoveNear} />
15
+ <main className={styles.main}>
16
+ <div className={styles.description}>
17
+ <p>
18
+ Loading components from: &nbsp;
19
+ <code className={styles.code}>{socialComponents.socialDB}</code>
20
+ </p>
30
21
  </div>
31
- <div class="col-6">
32
- <Component src={socialComponents.Lido} />
22
+ <div className={styles.center}>
23
+ <h1> <code>Multi-chain</code> Components Made Simple </h1>
33
24
  </div>
34
- </div>
35
- <hr />
25
+ <div className='row'>
26
+ <div class="col-6">
27
+ <Component src={socialComponents.HelloNear} />
28
+ <p class="my-4">&nbsp;</p>
29
+ <Component src={socialComponents.LoveNear} />
30
+ </div>
31
+ <div class="col-6">
32
+ <Component src={socialComponents.Lido} />
33
+ </div>
34
+ </div>
35
+ <hr />
36
36
 
37
- <div className={styles.grid}>
38
- <DocsCard />
39
- <HelloNearCard />
40
- </div>
41
- </main>
37
+ <div className={styles.grid}>
38
+ <DocsCard />
39
+ <HelloNearCard />
40
+ </div>
41
+ </main>
42
42
  </>
43
43
  );
44
44
  }
@@ -1,35 +1,35 @@
1
- 'use client'
1
+ 'use client';
2
2
  import { DocsCard, HelloComponentsCard } from '@/components/cards';
3
3
  import { useWallet } from '@/wallets/wallet-selector';
4
- import { useState, useEffect } from 'react'
4
+ import { useState, useEffect } from 'react';
5
5
  import { HelloNearContract, NetworkId } from '../../config';
6
- import styles from '../app.module.css'
6
+ import styles from '../app.module.css';
7
7
 
8
8
  // Contract that the app will interact with
9
9
  const CONTRACT = HelloNearContract[NetworkId];
10
10
 
11
- export default function HelloNear({ }) {
12
- const { signedAccountId, viewMethod, callMethod } = useWallet()
11
+ export default function HelloNear() {
12
+ const { signedAccountId, viewMethod, callMethod } = useWallet();
13
13
 
14
- const [greeting, setGreeting] = useState('loading...')
15
- const [loggedIn, setLoggedIn] = useState(false)
16
- const [showSpinner, setShowSpinner] = useState(false)
14
+ const [greeting, setGreeting] = useState('loading...');
15
+ const [loggedIn, setLoggedIn] = useState(false);
16
+ const [showSpinner, setShowSpinner] = useState(false);
17
17
 
18
18
  useEffect(() => {
19
19
  viewMethod && viewMethod(CONTRACT, 'get_greeting', {}).then(
20
20
  greeting => setGreeting(greeting)
21
- )
22
- }, [viewMethod])
21
+ );
22
+ }, [viewMethod]);
23
23
 
24
24
  useEffect(() => {
25
- setLoggedIn(!!signedAccountId)
26
- }, [signedAccountId])
25
+ setLoggedIn(!!signedAccountId);
26
+ }, [signedAccountId]);
27
27
 
28
28
  const saveGreeting = async () => {
29
- setShowSpinner(true)
29
+ setShowSpinner(true);
30
30
  await callMethod(CONTRACT, 'set_greeting', { greeting });
31
- setShowSpinner(false)
32
- }
31
+ setShowSpinner(false);
32
+ };
33
33
 
34
34
  return (
35
35
  <main className={styles.main}>
@@ -43,7 +43,7 @@ export default function HelloNear({ }) {
43
43
  <div className={styles.center}>
44
44
  <h1 className="w-100"> The contract says: <code>{greeting}</code> </h1>
45
45
  <div className="input-group" hidden={!loggedIn}>
46
- <input type="text" className="form-control w-20" placeholder="Store a new greeting" onChange={t => { setGreeting(t.target.value) }} />
46
+ <input type="text" className="form-control w-20" placeholder="Store a new greeting" onChange={t => { setGreeting(t.target.value); } } />
47
47
  <div className="input-group-append">
48
48
  <button className="btn btn-secondary" onClick={saveGreeting}>
49
49
  <span hidden={showSpinner}> Save </span>
@@ -60,5 +60,5 @@ export default function HelloNear({ }) {
60
60
  <HelloComponentsCard />
61
61
  </div>
62
62
  </main>
63
- )
63
+ );
64
64
  }
@@ -1,16 +1,15 @@
1
- 'use client'
2
- import './globals.css'
1
+ 'use client';
2
+ import './globals.css';
3
3
  import '@near-wallet-selector/modal-ui/styles.css';
4
4
 
5
- import { ComponentMap, NetworkId } from '@/config';
5
+ import { NetworkId } from '@/config';
6
6
  import { Navigation } from '@/components/navigation';
7
- import { initWallet } from '@/wallets/wallet-selector';
7
+ import { useInitWallet } from '@/wallets/wallet-selector';
8
8
 
9
9
  export default function RootLayout({ children }) {
10
10
 
11
- const createAccessKeyFor = ComponentMap[NetworkId].socialDB;
12
- initWallet({ createAccessKeyFor });
13
-
11
+ useInitWallet({ createAccessKeyFor: '', networkId: NetworkId });
12
+
14
13
  return (
15
14
  <html lang="en">
16
15
  <body>
@@ -18,5 +17,5 @@ export default function RootLayout({ children }) {
18
17
  {children}
19
18
  </body>
20
19
  </html>
21
- )
20
+ );
22
21
  }
@@ -1,8 +1,8 @@
1
- import Image from 'next/image'
2
- import styles from './app.module.css'
3
- import { DocsCard, HelloComponentsCard, HelloNearCard } from '@/components/cards'
1
+ import Image from 'next/image';
2
+ import styles from './app.module.css';
3
+ import { DocsCard, HelloComponentsCard, HelloNearCard } from '@/components/cards';
4
4
 
5
- export default function Home({ }) {
5
+ export default function Home() {
6
6
  return (
7
7
  <main className={styles.main}>
8
8
  <div className={styles.description}> </div>
@@ -33,5 +33,5 @@ export default function Home({ }) {
33
33
  <DocsCard />
34
34
  </div>
35
35
  </main>
36
- )
36
+ );
37
37
  }
@@ -13,7 +13,7 @@ export const DocsCard = () => {
13
13
  </h2>
14
14
  <p>Learn how this application works, and what you can build on Near.</p>
15
15
  </a>);
16
- }
16
+ };
17
17
 
18
18
  export const HelloNearCard = () => {
19
19
  return (
@@ -28,7 +28,7 @@ export const HelloNearCard = () => {
28
28
  <p>Discover how simple it is to interact with a Near smart contract.</p>
29
29
  </a>
30
30
  );
31
- }
31
+ };
32
32
 
33
33
  export const HelloComponentsCard = () => {
34
34
  return (
@@ -42,5 +42,5 @@ export const HelloComponentsCard = () => {
42
42
  </h2>
43
43
  <p>See how Web3 components can help you to create multi-chain apps.</p>
44
44
  </a>
45
- )
46
- }
45
+ );
46
+ };
@@ -7,17 +7,17 @@ import { useWallet } from '@/wallets/wallet-selector';
7
7
 
8
8
  export const Navigation = () => {
9
9
 
10
- const { signedAccountId, logOut, logIn } = useWallet()
11
- const [action, setAction] = useState(() => { })
12
- const [label, setLabel] = useState('Loading...')
10
+ const { signedAccountId, logOut, logIn } = useWallet();
11
+ const [action, setAction] = useState(() => { });
12
+ const [label, setLabel] = useState('Loading...');
13
13
 
14
14
  useEffect(() => {
15
15
  if (signedAccountId) {
16
- setAction(() => logOut)
17
- setLabel(`Logout ${signedAccountId}`)
16
+ setAction(() => logOut);
17
+ setLabel(`Logout ${signedAccountId}`);
18
18
  } else {
19
- setAction(() => logIn)
20
- setLabel('Login')
19
+ setAction(() => logIn);
20
+ setLabel('Login');
21
21
  }
22
22
  }, [signedAccountId, logOut, logIn, setAction, setLabel]);
23
23
 
@@ -33,4 +33,4 @@ export const Navigation = () => {
33
33
  </div>
34
34
  </nav>
35
35
  );
36
- }
36
+ };
@@ -1,12 +1,11 @@
1
1
  import { create as createStore } from 'zustand';
2
- import { distinctUntilChanged, map } from "rxjs";
2
+ import { distinctUntilChanged, map } from 'rxjs';
3
3
  import { providers } from 'near-api-js';
4
4
  import { setupWalletSelector } from '@near-wallet-selector/core';
5
5
  import { setupModal } from '@near-wallet-selector/modal-ui';
6
6
  import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
7
7
  import { setupHereWallet } from '@near-wallet-selector/here-wallet';
8
8
 
9
- import { NetworkId } from '@/config';
10
9
  import { useEffect, useState } from 'react';
11
10
 
12
11
  export const useWallet = createStore(set => ({
@@ -22,7 +21,7 @@ export const useWallet = createStore(set => ({
22
21
  setStoreSelector: ({ selector }) => set({ selector }),
23
22
  }));
24
23
 
25
- export function initWallet({ createAccessKeyFor }) {
24
+ export function useInitWallet({ createAccessKeyFor, networkId }) {
26
25
  const setAuth = useWallet(store => store.setAuth);
27
26
  const setLogActions = useWallet(store => store.setLogActions);
28
27
  const setMethods = useWallet(store => store.setMethods);
@@ -30,22 +29,20 @@ export function initWallet({ createAccessKeyFor }) {
30
29
  const [selector, setSelector] = useState(undefined);
31
30
 
32
31
  useEffect(() => {
33
- console.log('initWallet')
34
32
  const selector = setupWalletSelector({
35
- network: NetworkId,
33
+ network: networkId,
36
34
  modules: [setupMyNearWallet(), setupHereWallet()]
37
- })
35
+ });
38
36
 
39
37
  setSelector(selector);
40
38
  setStoreSelector({ selector });
41
- }, []);
39
+ }, [networkId, setStoreSelector]);
42
40
 
43
41
  useEffect(() => {
44
- console.log('selector then')
45
- if(!selector) return;
46
-
42
+ if (!selector) return;
43
+
47
44
  selector.then(walletSelector => {
48
- const accounts = walletSelector.store.getState().accounts
45
+ const accounts = walletSelector.store.getState().accounts;
49
46
  const signedAccountId = accounts.find((account) => account.active)?.accountId || '';
50
47
  setAuth({ signedAccountId });
51
48
 
@@ -55,37 +52,32 @@ export function initWallet({ createAccessKeyFor }) {
55
52
  distinctUntilChanged()
56
53
  )
57
54
  .subscribe((accounts) => {
58
- console.log("accounts", accounts)
59
55
  const signedAccountId = accounts.find((account) => account.active)?.accountId || '';
60
56
  setAuth({ signedAccountId });
61
57
  });
62
- })
58
+ });
63
59
  }, [selector, setAuth]);
64
60
 
65
61
  useEffect(() => {
66
- console.log('actions')
62
+ if (!selector) return;
67
63
 
68
- if(!selector) return;
69
-
70
64
  // defined logOut and logIn actions
71
65
  const logOut = async () => {
72
66
  const wallet = await (await selector).wallet();
73
67
  await wallet.signOut();
74
68
  setAuth({ signedAccountId: '' });
75
- }
69
+ };
76
70
 
77
71
  const logIn = async () => {
78
72
  const modal = setupModal(await selector, { contractId: createAccessKeyFor });
79
73
  modal.show();
80
- }
74
+ };
81
75
 
82
76
  setLogActions({ logOut, logIn });
83
- }, [selector, setAuth]);
77
+ }, [createAccessKeyFor, selector, setAuth, setLogActions]);
84
78
 
85
79
  useEffect(() => {
86
- console.log('methods')
87
-
88
- if(!selector) return;
80
+ if (!selector) return;
89
81
 
90
82
  const viewMethod = async (contractId, method, args = {}) => {
91
83
  const { network } = (await selector).options;
@@ -99,7 +91,7 @@ export function initWallet({ createAccessKeyFor }) {
99
91
  finality: 'optimistic',
100
92
  });
101
93
  return JSON.parse(Buffer.from(res.result).toString());
102
- }
94
+ };
103
95
 
104
96
  const callMethod = async (contractId, method, args = {}, gas = '30000000000000', deposit = 0) => {
105
97
  const wallet = await (await selector).wallet();
@@ -119,10 +111,10 @@ export function initWallet({ createAccessKeyFor }) {
119
111
  ],
120
112
  });
121
113
 
122
- return providers.getTransactionLastResult(outcome)
123
- }
114
+ return providers.getTransactionLastResult(outcome);
115
+ };
124
116
 
125
117
  setMethods({ viewMethod, callMethod });
126
118
 
127
- }, [selector]);
119
+ }, [selector, setMethods]);
128
120
  }
@@ -3,11 +3,7 @@ import { Wallet } from './near-wallet';
3
3
  import { useInitNear, Widget } from 'near-social-vm';
4
4
  import { useEffect } from 'react';
5
5
 
6
- const CONTRACT_ADDRESS = 'v1.social08.testnet';
7
-
8
- // When creating the wallet you can optionally ask to create an access key
9
- // Having the key enables to call non-payable methods without interrupting the user to sign
10
- const wallet = new Wallet({createAccessKeyFor: CONTRACT_ADDRESS, network: 'testnet'});
6
+ const wallet = new Wallet({network: 'testnet'});
11
7
 
12
8
  export default function Component({ src }) {
13
9
 
@@ -46,8 +42,8 @@ window.onload = async () => {
46
42
  };
47
43
 
48
44
  // Button clicks
49
- document.querySelector('#sign-in-button').onclick = () => { wallet.signIn() };
50
- document.querySelector('#sign-out-button').onclick = () => { wallet.signOut() };
45
+ document.querySelector('#sign-in-button').onclick = () => { wallet.signIn(); };
46
+ document.querySelector('#sign-out-button').onclick = () => { wallet.signOut(); };
51
47
 
52
48
  // UI: Display the signed-out container
53
49
  function signedOutUI() {
@@ -1,22 +1,22 @@
1
1
  import { Wallet } from './near-wallet';
2
2
 
3
- const CONTRACT_ADDRESS = 'v1.social08.testnet';
3
+ const HELLO_NEAR = 'hello.near-examples.testnet';
4
4
 
5
5
  // When creating the wallet you can optionally ask to create an access key
6
6
  // Having the key enables to call non-payable methods without interrupting the user to sign
7
- const wallet = new Wallet({createAccessKeyFor: CONTRACT_ADDRESS, network: 'testnet'});
7
+ const wallet = new Wallet({ network: 'testnet' });
8
8
 
9
9
  // Setup on page load
10
10
  window.onload = async () => {
11
11
  let isSignedIn = await wallet.startUp();
12
- isSignedIn? signedInUI(): signedOutUI();
12
+ isSignedIn ? signedInUI() : signedOutUI();
13
13
  getGreeting();
14
14
  };
15
15
 
16
16
  // Button clicks
17
17
  document.querySelector('form').onsubmit = setGreeting;
18
- document.querySelector('#sign-in-button').onclick = () => { wallet.signIn() };
19
- document.querySelector('#sign-out-button').onclick = () => { wallet.signOut() };
18
+ document.querySelector('#sign-in-button').onclick = () => { wallet.signIn(); };
19
+ document.querySelector('#sign-out-button').onclick = () => { wallet.signOut(); };
20
20
 
21
21
  async function setGreeting(event) {
22
22
  event.preventDefault();
@@ -26,7 +26,7 @@ async function setGreeting(event) {
26
26
 
27
27
  // use the wallet to send the greeting to the Smart Contract
28
28
  const { greeting } = event.target.elements;
29
- await wallet.callMethod({ method: 'set_greeting', args: { greeting: greeting.value }, contractId: CONTRACT_ADDRESS });
29
+ await wallet.callMethod({ method: 'set_greeting', args: { greeting: greeting.value }, contractId: HELLO_NEAR });
30
30
 
31
31
  // query the new greeting
32
32
  await getGreeting();
@@ -37,7 +37,7 @@ async function setGreeting(event) {
37
37
 
38
38
  async function getGreeting() {
39
39
  // use the wallet to query the Smart Contract
40
- const currentGreeting = await wallet.viewMethod({ method: 'get_greeting', contractId: CONTRACT_ADDRESS });
40
+ const currentGreeting = await wallet.viewMethod({ method: 'get_greeting', contractId: HELLO_NEAR });
41
41
 
42
42
  // Display it
43
43
  document.querySelector('#displayGreeting').innerText = currentGreeting;
@@ -56,6 +56,6 @@ function signedInUI() {
56
56
  });
57
57
  }
58
58
 
59
- function hide(id){
59
+ function hide(id) {
60
60
  document.querySelectorAll(id).forEach(el => el.style.display = 'none');
61
61
  }
@@ -24,8 +24,8 @@ export class Wallet {
24
24
  // key, so the user skips signing non-payable transactions.
25
25
  // Omitting the accountId will result in the user being
26
26
  // asked to sign all transactions.
27
- this.createAccessKeyFor = createAccessKeyFor
28
- this.network = network
27
+ this.createAccessKeyFor = createAccessKeyFor;
28
+ this.network = network;
29
29
  this.selector = setupWalletSelector({
30
30
  network: this.network,
31
31
  modules: [setupMyNearWallet()],
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "next/core-web-vitals"
3
- }