create-near-app 8.4.0 → 8.5.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 (39) hide show
  1. package/package.json +1 -1
  2. package/templates/frontend/next-app/next-env.d.ts +6 -0
  3. package/templates/frontend/next-app/package.json +28 -16
  4. package/templates/frontend/{vite-react/src/pages/hello_near.jsx → next-app/src/app/hello-near/page.tsx} +17 -13
  5. package/templates/frontend/next-app/src/app/layout.tsx +80 -0
  6. package/templates/frontend/next-app/src/components/{cards.js → cards.tsx} +4 -9
  7. package/templates/frontend/next-app/src/components/{navigation.js → navigation.tsx} +17 -7
  8. package/templates/frontend/{next-page/src/wallets/web3modal.js → next-app/src/wallets/web3modal.ts} +0 -1
  9. package/templates/frontend/next-app/tsconfig.json +42 -0
  10. package/templates/frontend/next-page/next-env.d.ts +6 -0
  11. package/templates/frontend/next-page/package.json +23 -16
  12. package/templates/frontend/next-page/src/components/{navigation.js → navigation.tsx} +18 -8
  13. package/templates/frontend/next-page/src/pages/_app.tsx +68 -0
  14. package/templates/frontend/next-page/src/pages/hello-near/{index.js → index.tsx} +22 -21
  15. package/templates/frontend/next-page/src/pages/{index.js → index.tsx} +8 -8
  16. package/templates/frontend/{vite-react/src/wallets/web3modal.js → next-page/src/wallets/web3modal.ts} +0 -1
  17. package/templates/frontend/next-page/tsconfig.json +35 -0
  18. package/templates/frontend/vite-react/eslint.config.js +4 -1
  19. package/templates/frontend/vite-react/package.json +22 -17
  20. package/templates/frontend/vite-react/src/App.tsx +81 -0
  21. package/templates/frontend/vite-react/src/components/{cards.jsx → cards.tsx} +4 -4
  22. package/templates/frontend/vite-react/src/components/{navigation.jsx → navigation.tsx} +19 -7
  23. package/templates/frontend/vite-react/src/{config.js → config.ts} +1 -1
  24. package/templates/frontend/vite-react/src/main.tsx +14 -0
  25. package/templates/frontend/vite-react/src/pages/hello_near.tsx +95 -0
  26. package/templates/frontend/{next-app/src/wallets/web3modal.js → vite-react/src/wallets/web3modal.ts} +0 -1
  27. package/templates/frontend/vite-react/tsconfig.json +35 -0
  28. package/templates/frontend/next-app/jsconfig.json +0 -7
  29. package/templates/frontend/next-app/src/app/hello-near/page.js +0 -67
  30. package/templates/frontend/next-app/src/app/layout.js +0 -54
  31. package/templates/frontend/next-page/jsconfig.json +0 -7
  32. package/templates/frontend/next-page/src/pages/_app.js +0 -45
  33. package/templates/frontend/vite-react/src/App.jsx +0 -56
  34. package/templates/frontend/vite-react/src/main.jsx +0 -11
  35. /package/templates/frontend/next-app/src/app/{page.js → page.tsx} +0 -0
  36. /package/templates/frontend/next-app/src/{config.js → config.ts} +0 -0
  37. /package/templates/frontend/next-page/src/components/{cards.js → cards.tsx} +0 -0
  38. /package/templates/frontend/next-page/src/{config.js → config.ts} +0 -0
  39. /package/templates/frontend/vite-react/src/pages/{home.jsx → home.tsx} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -0,0 +1,6 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+ /// <reference path="./.next/types/routes.d.ts" />
4
+
5
+ // NOTE: This file should not be edited
6
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -12,20 +12,24 @@
12
12
  "lint": "next lint"
13
13
  },
14
14
  "dependencies": {
15
- "@near-wallet-selector/bitte-wallet": "^9.0.2",
16
- "@near-wallet-selector/core": "^9.0.2",
17
- "@near-wallet-selector/ethereum-wallets": "^9.0.2",
18
- "@near-wallet-selector/here-wallet": "^9.0.2",
19
- "@near-wallet-selector/hot-wallet": "^9.0.2",
20
- "@near-wallet-selector/ledger": "^9.0.2",
21
- "@near-wallet-selector/meteor-wallet": "^9.0.2",
22
- "@near-wallet-selector/meteor-wallet-app": "^9.0.2",
23
- "@near-wallet-selector/modal-ui": "^9.0.2",
24
- "@near-wallet-selector/my-near-wallet": "^9.0.2",
25
- "@near-wallet-selector/near-mobile-wallet": "^9.0.2",
26
- "@near-wallet-selector/react-hook": "^9.0.2",
27
- "@near-wallet-selector/sender": "^9.0.2",
28
- "@near-wallet-selector/welldone-wallet": "^9.0.2",
15
+ "@near-wallet-selector/bitget-wallet": "9.5.4",
16
+ "@near-wallet-selector/coin98-wallet": "9.5.4",
17
+ "@near-wallet-selector/core": "9.5.4",
18
+ "@near-wallet-selector/ethereum-wallets": "9.5.4",
19
+ "@near-wallet-selector/hot-wallet": "9.5.4",
20
+ "@near-wallet-selector/intear-wallet": "9.5.4",
21
+ "@near-wallet-selector/ledger": "9.5.4",
22
+ "@near-wallet-selector/math-wallet": "9.5.4",
23
+ "@near-wallet-selector/meteor-wallet": "9.5.4",
24
+ "@near-wallet-selector/meteor-wallet-app": "9.5.4",
25
+ "@near-wallet-selector/modal-ui": "9.5.4",
26
+ "@near-wallet-selector/near-mobile-wallet": "9.5.4",
27
+ "@near-wallet-selector/okx-wallet": "9.5.4",
28
+ "@near-wallet-selector/ramper-wallet": "9.5.4",
29
+ "@near-wallet-selector/react-hook": "9.5.4",
30
+ "@near-wallet-selector/sender": "9.5.4",
31
+ "@near-wallet-selector/unity-wallet": "9.5.4",
32
+ "@near-wallet-selector/welldone-wallet": "9.5.4",
29
33
  "@reown/appkit": "^1.7.7",
30
34
  "@reown/appkit-adapter-wagmi": "^1.7.7",
31
35
  "@wagmi/core": "^2.17.2",
@@ -38,9 +42,17 @@
38
42
  "viem": "^2.30.5"
39
43
  },
40
44
  "devDependencies": {
45
+ "@types/node": "^24.7.0",
46
+ "@types/react": "^19.2.2",
47
+ "@types/react-dom": "^19.2.1",
41
48
  "encoding": "^0.1.13",
42
49
  "eslint": "^9",
43
50
  "eslint-config-next": "^15",
44
- "pino-pretty": "^11.2.2"
51
+ "pino-pretty": "^11.2.2",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "overrides": {
55
+ "@wagmi/core": "^2.17.2",
56
+ "viem": "^2.30.5"
45
57
  }
46
- }
58
+ }
@@ -1,7 +1,8 @@
1
- import { useEffect, useState } from 'react';
1
+ 'use client';
2
+ import { useState, useEffect } from 'react';
2
3
 
4
+ import styles from '@/app/app.module.css';
3
5
  import { Cards } from '@/components/cards';
4
- import styles from '@/styles/app.module.css';
5
6
 
6
7
  import { HelloNearContract } from '@/config';
7
8
  import { useWalletSelector } from '@near-wallet-selector/react-hook';
@@ -12,29 +13,31 @@ const CONTRACT = HelloNearContract;
12
13
  export default function HelloNear() {
13
14
  const { signedAccountId, viewFunction, callFunction } = useWalletSelector();
14
15
 
15
- const [greeting, setGreeting] = useState('loading...');
16
+ const [greeting, setGreeting] = useState<string>('loading...');
16
17
  const [newGreeting, setNewGreeting] = useState('loading...');
17
18
  const [loggedIn, setLoggedIn] = useState(false);
18
19
  const [showSpinner, setShowSpinner] = useState(false);
19
20
 
20
- useEffect(() => {
21
- viewFunction({ contractId: CONTRACT, method: 'get_greeting' }).then((greeting) => setGreeting(greeting));
22
- }, [viewFunction]);
21
+ useEffect(() => {
22
+ viewFunction({ contractId: HelloNearContract, method: 'get_greeting' }).then((greeting) => setGreeting(greeting as string));
23
+ }, []);
23
24
 
24
25
  useEffect(() => {
25
26
  setLoggedIn(!!signedAccountId);
26
27
  }, [signedAccountId]);
27
28
 
28
29
  const saveGreeting = async () => {
29
- callFunction({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } })
30
- .catch(async () => {
31
- viewFunction({ contractId: CONTRACT, method: 'get_greeting' }).then((greeting) => setGreeting(greeting));
30
+ // Try to store greeting, revert if it fails
31
+ callFunction({ contractId: HelloNearContract, method: 'set_greeting', args: { greeting: newGreeting } })
32
+ .then(async () => {
33
+ const greeting = (await viewFunction({ contractId: HelloNearContract, method: 'get_greeting' })) as string;
34
+ setGreeting(greeting);
35
+ setShowSpinner(false);
32
36
  });
33
37
 
38
+ // Assume the transaction will be successful and update the UI optimistically
34
39
  setShowSpinner(true);
35
- await new Promise(resolve => setTimeout(resolve, 300));
36
40
  setGreeting(newGreeting);
37
- setShowSpinner(false);
38
41
  };
39
42
 
40
43
  return (
@@ -42,9 +45,10 @@ export default function HelloNear() {
42
45
  <div className={styles.description}>
43
46
  <p>
44
47
  Interacting with the contract: &nbsp;
45
- <code className={styles.code}>{CONTRACT}</code>
48
+ <code className={styles.code}>{HelloNearContract}</code>
46
49
  </p>
47
50
  </div>
51
+
48
52
  <div className={styles.center}>
49
53
  <h1 className="w-100">
50
54
  The contract says: <code>{greeting}</code>
@@ -70,4 +74,4 @@ export default function HelloNear() {
70
74
  <Cards />
71
75
  </main>
72
76
  );
73
- }
77
+ }
@@ -0,0 +1,80 @@
1
+ 'use client';
2
+
3
+ import '@/app/globals.css';
4
+ import '@near-wallet-selector/modal-ui/styles.css';
5
+
6
+ import { Navigation } from '@/components/navigation';
7
+ import { HelloNearContract, NetworkId } from '@/config';
8
+ import { WalletSelectorProvider } from '@near-wallet-selector/react-hook';
9
+
10
+ import { ReactNode } from 'react';
11
+
12
+ // Wallet setups
13
+ import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
14
+ import { setupMeteorWalletApp } from "@near-wallet-selector/meteor-wallet-app";
15
+ import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
16
+ import { setupHotWallet } from "@near-wallet-selector/hot-wallet";
17
+ import { setupLedger } from "@near-wallet-selector/ledger";
18
+ import { setupSender } from "@near-wallet-selector/sender";
19
+ import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
20
+ import { setupWelldoneWallet } from "@near-wallet-selector/welldone-wallet";
21
+ import { setupMathWallet } from "@near-wallet-selector/math-wallet";
22
+ import { setupBitgetWallet } from "@near-wallet-selector/bitget-wallet";
23
+ import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
24
+ import { setupUnityWallet } from "@near-wallet-selector/unity-wallet";
25
+ import { setupOKXWallet } from "@near-wallet-selector/okx-wallet";
26
+ import { setupCoin98Wallet } from "@near-wallet-selector/coin98-wallet";
27
+ import { setupIntearWallet } from "@near-wallet-selector/intear-wallet";
28
+
29
+ // Ethereum adapters
30
+ import { wagmiAdapter, web3Modal } from '@/wallets/web3modal';
31
+
32
+ // Types
33
+ import type { WalletModuleFactory, Network, WalletSelectorParams } from "@near-wallet-selector/core";
34
+
35
+ const walletSelectorConfig: WalletSelectorParams = {
36
+ network: NetworkId as unknown as Network,
37
+ modules: [
38
+ setupEthereumWallets({ wagmiConfig: wagmiAdapter.wagmiConfig, web3Modal }),
39
+ setupMeteorWallet(),
40
+ setupMeteorWalletApp({ contractId: HelloNearContract }),
41
+ setupHotWallet(),
42
+ setupLedger(),
43
+ setupSender(),
44
+ setupNearMobileWallet(),
45
+ setupWelldoneWallet(),
46
+ setupMathWallet(),
47
+ setupBitgetWallet(),
48
+ setupRamperWallet(),
49
+ setupUnityWallet({
50
+ projectId: "your-project-id",
51
+ metadata: {
52
+ name: "Hello NEAR",
53
+ description: "Hello NEAR Example",
54
+ url: "https://near.org",
55
+ icons: ["https://near.org/favicon.ico"],
56
+ }
57
+ }),
58
+ setupOKXWallet(),
59
+ setupCoin98Wallet(),
60
+ setupIntearWallet(),
61
+ ] as WalletModuleFactory[]
62
+ };
63
+
64
+ // Layout Component
65
+ interface RootLayoutProps {
66
+ children: ReactNode;
67
+ }
68
+
69
+ export default function RootLayout({ children }: RootLayoutProps) {
70
+ return (
71
+ <html lang="en">
72
+ <body>
73
+ <WalletSelectorProvider config={walletSelectorConfig}>
74
+ <Navigation />
75
+ {children}
76
+ </WalletSelectorProvider>
77
+ </body>
78
+ </html>
79
+ );
80
+ }
@@ -1,6 +1,5 @@
1
- import Link from 'next/link';
2
-
3
- import styles from '@/app/app.module.css';
1
+ import Link from "next/link";
2
+ import styles from "@/app/app.module.css";
4
3
 
5
4
  export const Cards = () => {
6
5
  return (
@@ -8,7 +7,7 @@ export const Cards = () => {
8
7
  <Link
9
8
  href="https://docs.near.org/build/web3-apps/quickstart"
10
9
  className={styles.card}
11
- target='_blank'
10
+ target="_blank"
12
11
  rel="noopener noreferrer"
13
12
  >
14
13
  <h2>
@@ -17,11 +16,7 @@ export const Cards = () => {
17
16
  <p>Learn how this application works, and what you can build on Near.</p>
18
17
  </Link>
19
18
 
20
- <Link
21
- href="/hello-near"
22
- className={styles.card}
23
- rel="noopener noreferrer"
24
- >
19
+ <Link href="/hello-near" className={styles.card} rel="noopener noreferrer">
25
20
  <h2>
26
21
  Near Integration <span>-&gt;</span>
27
22
  </h2>
@@ -1,14 +1,15 @@
1
1
  import Image from 'next/image';
2
2
  import Link from 'next/link';
3
3
  import { useEffect, useState } from 'react';
4
-
5
- import NearLogo from '/public/near-logo.svg';
6
4
  import { useWalletSelector } from '@near-wallet-selector/react-hook';
7
5
 
6
+ import NearLogo from '../../public/near-logo.svg';
7
+
8
8
  export const Navigation = () => {
9
+ // Type the action as a function that returns void
10
+ const [action, setAction] = useState<() => void>(() => () => {});
11
+ const [label, setLabel] = useState<string>('Loading...');
9
12
  const { signedAccountId, signIn, signOut } = useWalletSelector();
10
- const [action, setAction] = useState(() => { });
11
- const [label, setLabel] = useState('Loading...');
12
13
 
13
14
  useEffect(() => {
14
15
  if (signedAccountId) {
@@ -24,10 +25,19 @@ export const Navigation = () => {
24
25
  <nav className="navbar navbar-expand-lg">
25
26
  <div className="container-fluid">
26
27
  <Link href="/" passHref>
27
- <Image priority src={NearLogo} alt="NEAR" width="30" height="24" className="d-inline-block align-text-top" />
28
+ <Image
29
+ priority
30
+ src={NearLogo}
31
+ alt="NEAR"
32
+ width={30}
33
+ height={24}
34
+ className="d-inline-block align-text-top"
35
+ />
28
36
  </Link>
29
- <div className='navbar-nav pt-1'>
30
- <button className="btn btn-secondary" onClick={action} > {label} </button>
37
+ <div className="navbar-nav pt-1">
38
+ <button className="btn btn-secondary" onClick={action}>
39
+ {label}
40
+ </button>
31
41
  </div>
32
42
  </div>
33
43
  </nav>
@@ -1,7 +1,6 @@
1
1
  import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
2
2
  import { createAppKit } from "@reown/appkit/react";
3
3
  import { nearTestnet } from "@reown/appkit/networks";
4
- import { reconnect } from "@wagmi/core";
5
4
 
6
5
  // Get a project ID at https://cloud.reown.com
7
6
  const projectId = "30147604c5f01d0bc4482ab0665b5697";
@@ -0,0 +1,42 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
9
+ "allowJs": false,
10
+ "skipLibCheck": true,
11
+ "strict": true,
12
+ "noEmit": true,
13
+ "esModuleInterop": true,
14
+ "module": "esnext",
15
+ "moduleResolution": "bundler",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "jsx": "preserve",
19
+ "baseUrl": ".",
20
+ "paths": {
21
+ "@/*": [
22
+ "src/*"
23
+ ]
24
+ },
25
+ "incremental": true,
26
+ "plugins": [
27
+ {
28
+ "name": "next"
29
+ }
30
+ ]
31
+ },
32
+ "include": [
33
+ "next-env.d.ts",
34
+ "src/**/*.ts",
35
+ "src/**/*.tsx",
36
+ "src/app/global.d.ts",
37
+ ".next/types/**/*.ts"
38
+ ],
39
+ "exclude": [
40
+ "node_modules"
41
+ ]
42
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+ /// <reference path="./.next/types/routes.d.ts" />
4
+
5
+ // NOTE: This file should not be edited
6
+ // see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
@@ -12,20 +12,24 @@
12
12
  "lint": "next lint"
13
13
  },
14
14
  "dependencies": {
15
- "@near-wallet-selector/bitte-wallet": "^9.0.2",
16
- "@near-wallet-selector/core": "^9.0.2",
17
- "@near-wallet-selector/ethereum-wallets": "^9.0.2",
18
- "@near-wallet-selector/here-wallet": "^9.0.2",
19
- "@near-wallet-selector/hot-wallet": "^9.0.2",
20
- "@near-wallet-selector/ledger": "^9.0.2",
21
- "@near-wallet-selector/meteor-wallet": "^9.0.2",
22
- "@near-wallet-selector/meteor-wallet-app": "^9.0.2",
23
- "@near-wallet-selector/modal-ui": "^9.0.2",
24
- "@near-wallet-selector/my-near-wallet": "^9.0.2",
25
- "@near-wallet-selector/near-mobile-wallet": "^9.0.2",
26
- "@near-wallet-selector/react-hook": "^9.0.2",
27
- "@near-wallet-selector/sender": "^9.0.2",
28
- "@near-wallet-selector/welldone-wallet": "^9.0.2",
15
+ "@near-wallet-selector/bitget-wallet": "9.5.4",
16
+ "@near-wallet-selector/coin98-wallet": "9.5.4",
17
+ "@near-wallet-selector/core": "9.5.4",
18
+ "@near-wallet-selector/ethereum-wallets": "9.5.4",
19
+ "@near-wallet-selector/hot-wallet": "9.5.4",
20
+ "@near-wallet-selector/intear-wallet": "9.5.4",
21
+ "@near-wallet-selector/ledger": "9.5.4",
22
+ "@near-wallet-selector/math-wallet": "9.5.4",
23
+ "@near-wallet-selector/meteor-wallet": "9.5.4",
24
+ "@near-wallet-selector/meteor-wallet-app": "9.5.4",
25
+ "@near-wallet-selector/modal-ui": "9.5.4",
26
+ "@near-wallet-selector/near-mobile-wallet": "9.5.4",
27
+ "@near-wallet-selector/okx-wallet": "9.5.4",
28
+ "@near-wallet-selector/ramper-wallet": "9.5.4",
29
+ "@near-wallet-selector/react-hook": "9.5.4",
30
+ "@near-wallet-selector/sender": "9.5.4",
31
+ "@near-wallet-selector/unity-wallet": "9.5.4",
32
+ "@near-wallet-selector/welldone-wallet": "9.5.4",
29
33
  "@reown/appkit": "^1.7.7",
30
34
  "@reown/appkit-adapter-wagmi": "^1.7.7",
31
35
  "@wagmi/core": "^2.17.2",
@@ -38,9 +42,12 @@
38
42
  "viem": "^2.30.5"
39
43
  },
40
44
  "devDependencies": {
45
+ "@types/react": "^18.3.26",
46
+ "@types/react-dom": "^18.3.7",
41
47
  "encoding": "^0.1.13",
42
48
  "eslint": "^9",
43
49
  "eslint-config-next": "^15",
44
- "pino-pretty": "^11.2.2"
50
+ "pino-pretty": "^11.2.2",
51
+ "typescript": "^5.9.3"
45
52
  }
46
- }
53
+ }
@@ -3,12 +3,13 @@ import Link from 'next/link';
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useWalletSelector } from '@near-wallet-selector/react-hook';
5
5
 
6
- import NearLogo from '/public/near-logo.svg';
6
+ import NearLogo from '../../public/near-logo.svg';
7
7
 
8
8
  export const Navigation = () => {
9
+ // Type the action as a function that returns void
10
+ const [action, setAction] = useState<() => void>(() => () => {});
11
+ const [label, setLabel] = useState<string>('Loading...');
9
12
  const { signedAccountId, signIn, signOut } = useWalletSelector();
10
- const [action, setAction] = useState(() => { });
11
- const [label, setLabel] = useState('Loading...');
12
13
 
13
14
  useEffect(() => {
14
15
  if (signedAccountId) {
@@ -16,18 +17,27 @@ export const Navigation = () => {
16
17
  setLabel(`Logout ${signedAccountId}`);
17
18
  } else {
18
19
  setAction(() => signIn);
19
- setLabel("Login");
20
+ setLabel('Login');
20
21
  }
21
- }, [signedAccountId]);
22
+ }, [signedAccountId, signIn, signOut]);
22
23
 
23
24
  return (
24
25
  <nav className="navbar navbar-expand-lg">
25
26
  <div className="container-fluid">
26
27
  <Link href="/" passHref legacyBehavior>
27
- <Image priority src={NearLogo} alt="NEAR" width="30" height="24" className="d-inline-block align-text-top" />
28
+ <Image
29
+ priority
30
+ src={NearLogo}
31
+ alt="NEAR"
32
+ width={30}
33
+ height={24}
34
+ className="d-inline-block align-text-top"
35
+ />
28
36
  </Link>
29
- <div className='navbar-nav pt-1'>
30
- <button className="btn btn-secondary" onClick={action} > {label} </button>
37
+ <div className="navbar-nav pt-1">
38
+ <button className="btn btn-secondary" onClick={action}>
39
+ {label}
40
+ </button>
31
41
  </div>
32
42
  </div>
33
43
  </nav>
@@ -0,0 +1,68 @@
1
+ import "@/styles/globals.css";
2
+ import "@near-wallet-selector/modal-ui/styles.css";
3
+
4
+ import type { AppProps } from "next/app";
5
+ import { WalletSelectorProvider } from "@near-wallet-selector/react-hook";
6
+ import { Navigation } from "@/components/navigation";
7
+ import { HelloNearContract, NetworkId } from "@/config";
8
+
9
+ // Wallet setups
10
+ import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
11
+ import { setupMeteorWalletApp } from "@near-wallet-selector/meteor-wallet-app";
12
+ import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
13
+ import { setupHotWallet } from "@near-wallet-selector/hot-wallet";
14
+ import { setupLedger } from "@near-wallet-selector/ledger";
15
+ import { setupSender } from "@near-wallet-selector/sender";
16
+ import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
17
+ import { setupWelldoneWallet } from "@near-wallet-selector/welldone-wallet";
18
+ import { setupMathWallet } from "@near-wallet-selector/math-wallet";
19
+ import { setupBitgetWallet } from "@near-wallet-selector/bitget-wallet";
20
+ import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
21
+ import { setupUnityWallet } from "@near-wallet-selector/unity-wallet";
22
+ import { setupOKXWallet } from "@near-wallet-selector/okx-wallet";
23
+ import { setupCoin98Wallet } from "@near-wallet-selector/coin98-wallet";
24
+ import { setupIntearWallet } from "@near-wallet-selector/intear-wallet";
25
+
26
+ // Ethereum adapters
27
+ import { wagmiAdapter, web3Modal } from "@/wallets/web3modal";
28
+
29
+ // Types
30
+ import type { WalletModuleFactory } from "@near-wallet-selector/core";
31
+
32
+ const walletSelectorConfig = {
33
+ network: NetworkId,
34
+ modules: [
35
+ setupEthereumWallets({ wagmiConfig: wagmiAdapter.wagmiConfig, web3Modal }),
36
+ setupMeteorWallet(),
37
+ setupMeteorWalletApp({ contractId: HelloNearContract }),
38
+ setupHotWallet(),
39
+ setupLedger(),
40
+ setupSender(),
41
+ setupNearMobileWallet(),
42
+ setupWelldoneWallet(),
43
+ setupMathWallet(),
44
+ setupBitgetWallet(),
45
+ setupRamperWallet(),
46
+ setupUnityWallet({
47
+ projectId: "your-project-id",
48
+ metadata: {
49
+ name: "Hello NEAR",
50
+ description: "Hello NEAR Example",
51
+ url: "https://near.org",
52
+ icons: ["https://near.org/favicon.ico"],
53
+ }
54
+ }),
55
+ setupOKXWallet(),
56
+ setupCoin98Wallet(),
57
+ setupIntearWallet(),
58
+ ] as WalletModuleFactory[]
59
+ };
60
+
61
+ export default function App({ Component, pageProps }: AppProps) {
62
+ return (
63
+ <WalletSelectorProvider config={walletSelectorConfig}>
64
+ <Navigation />
65
+ <Component {...pageProps} />
66
+ </WalletSelectorProvider>
67
+ );
68
+ }
@@ -1,25 +1,23 @@
1
- import { useState, useEffect } from 'react';
2
1
 
2
+ import { Cards } from '@/components/cards';
3
+
4
+ import { useEffect, useState } from 'react';
3
5
  import styles from '@/styles/app.module.css';
6
+
4
7
  import { HelloNearContract } from '../../config';
5
- import { Cards } from '@/components/cards';
6
- import { useWalletSelector } from '@near-wallet-selector/react-hook';
7
8
 
8
- // Contract that the app will interact with
9
- const CONTRACT = HelloNearContract;
9
+ import { useWalletSelector } from '@near-wallet-selector/react-hook';
10
10
 
11
11
  export default function HelloNear() {
12
12
  const { signedAccountId, viewFunction, callFunction } = useWalletSelector();
13
13
 
14
- const [greeting, setGreeting] = useState('loading...');
15
- const [newGreeting, setNewGreeting] = useState('loading...');
14
+ const [greeting, setGreeting] = useState<string>('loading...');
15
+ const [newGreeting, setNewGreeting] = useState('');
16
16
  const [loggedIn, setLoggedIn] = useState(false);
17
17
  const [showSpinner, setShowSpinner] = useState(false);
18
18
 
19
19
  useEffect(() => {
20
- viewFunction({ contractId: CONTRACT, method: 'get_greeting' }).then(
21
- greeting => setGreeting(greeting)
22
- );
20
+ viewFunction({ contractId: HelloNearContract, method: 'get_greeting' }).then((greeting) => setGreeting(greeting as string));
23
21
  }, []);
24
22
 
25
23
  useEffect(() => {
@@ -27,11 +25,17 @@ export default function HelloNear() {
27
25
  }, [signedAccountId]);
28
26
 
29
27
  const saveGreeting = async () => {
28
+ // Try to store greeting, revert if it fails
29
+ callFunction({ contractId: HelloNearContract, method: 'set_greeting', args: { greeting: newGreeting } })
30
+ .then(async () => {
31
+ const greeting = (await viewFunction({ contractId: HelloNearContract, method: 'get_greeting' })) as string;
32
+ setGreeting(greeting);
33
+ setShowSpinner(false);
34
+ });
35
+
36
+ // Assume the transaction will be successful and update the UI optimistically
30
37
  setShowSpinner(true);
31
- await callFunction({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } });
32
- const greeting = await viewFunction({ contractId: CONTRACT, method: 'get_greeting' });
33
- setGreeting(greeting);
34
- setShowSpinner(false);
38
+ setGreeting(newGreeting);
35
39
  };
36
40
 
37
41
  return (
@@ -39,7 +43,7 @@ export default function HelloNear() {
39
43
  <div className={styles.description}>
40
44
  <p>
41
45
  Interacting with the contract: &nbsp;
42
- <code className={styles.code}>{CONTRACT}</code>
46
+ <code className={styles.code}>{HelloNearContract}</code>
43
47
  </p>
44
48
  </div>
45
49
 
@@ -52,15 +56,12 @@ export default function HelloNear() {
52
56
  type="text"
53
57
  className="form-control w-20"
54
58
  placeholder="Store a new greeting"
55
- onChange={t => setNewGreeting(t.target.value)}
59
+ onChange={(t) => setNewGreeting(t.target.value)}
56
60
  />
57
61
  <div className="input-group-append">
58
62
  <button className="btn btn-secondary" onClick={saveGreeting}>
59
63
  <span hidden={showSpinner}> Save </span>
60
- <i
61
- className="spinner-border spinner-border-sm"
62
- hidden={!showSpinner}
63
- ></i>
64
+ <i className="spinner-border spinner-border-sm" hidden={!showSpinner}></i>
64
65
  </button>
65
66
  </div>
66
67
  </div>
@@ -71,4 +72,4 @@ export default function HelloNear() {
71
72
  <Cards />
72
73
  </main>
73
74
  );
74
- }
75
+ }
@@ -1,14 +1,14 @@
1
- import Image from 'next/image';
1
+ import Image from "next/image";
2
2
 
3
- import NearLogo from '/public/near.svg';
4
- import NextLogo from '/public/next.svg';
5
- import styles from '@/styles/app.module.css';
6
- import { Cards } from '@/components/cards';
3
+ import NearLogo from "/public/near.svg";
4
+ import NextLogo from "/public/next.svg";
5
+ import { Cards } from "@/components/cards";
6
+ import styles from "@/styles/app.module.css";
7
7
 
8
8
  export default function Home() {
9
9
  return (
10
10
  <main className={styles.main}>
11
- <div className={styles.description}> </div>
11
+ <div className={styles.description}></div>
12
12
 
13
13
  <div className={styles.center}>
14
14
  <Image
@@ -24,8 +24,8 @@ export default function Home() {
24
24
  className={styles.logo}
25
25
  src={NextLogo}
26
26
  alt="Next.js Logo"
27
- width={300 * .58}
28
- height={61 * .58}
27
+ width={300 * 0.58}
28
+ height={61 * 0.58}
29
29
  priority
30
30
  />
31
31
  </div>