create-near-app 8.1.0 → 8.2.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 (25) hide show
  1. package/package.json +2 -1
  2. package/templates/frontend/next-app/next.config.js +1 -0
  3. package/templates/frontend/next-app/package.json +23 -18
  4. package/templates/frontend/next-app/src/app/hello-near/page.js +7 -9
  5. package/templates/frontend/next-app/src/app/layout.js +34 -9
  6. package/templates/frontend/next-app/src/components/navigation.js +7 -9
  7. package/templates/frontend/next-app/src/config.js +1 -18
  8. package/templates/frontend/next-app/src/wallets/web3modal.js +30 -39
  9. package/templates/frontend/next-page/next.config.js +1 -0
  10. package/templates/frontend/next-page/package.json +23 -18
  11. package/templates/frontend/next-page/src/components/navigation.js +7 -9
  12. package/templates/frontend/next-page/src/config.js +1 -18
  13. package/templates/frontend/next-page/src/pages/_app.js +34 -11
  14. package/templates/frontend/next-page/src/pages/hello-near/index.js +7 -9
  15. package/templates/frontend/next-page/src/wallets/web3modal.js +30 -39
  16. package/templates/frontend/vite-react/package.json +25 -26
  17. package/templates/frontend/vite-react/src/App.jsx +35 -15
  18. package/templates/frontend/vite-react/src/components/navigation.jsx +8 -10
  19. package/templates/frontend/vite-react/src/config.js +1 -18
  20. package/templates/frontend/vite-react/src/pages/hello_near.jsx +7 -9
  21. package/templates/frontend/vite-react/src/wallets/web3modal.js +30 -37
  22. package/templates/frontend/vite-react/vite.config.js +2 -15
  23. package/templates/frontend/next-app/src/wallets/near.js +0 -216
  24. package/templates/frontend/next-page/src/wallets/near.js +0 -216
  25. package/templates/frontend/vite-react/src/wallets/near.js +0 -228
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -18,6 +18,7 @@
18
18
  "build": "tsc",
19
19
  "test": "npm run build && FORCE_COLOR=1 jest --runInBand",
20
20
  "test-e2e": "npm run build && ./test/e2e.sh",
21
+ "test:update": "jest -u",
21
22
  "lint": "eslint .",
22
23
  "fix": "eslint . --fix",
23
24
  "release": "npm run build && release-it",
@@ -1,6 +1,7 @@
1
1
  /** @type {import('next').NextConfig} */
2
2
  const nextConfig = {
3
3
  reactStrictMode: true,
4
+ transpilePackages: ['reown'],
4
5
  };
5
6
 
6
7
  module.exports = nextConfig;
@@ -12,29 +12,34 @@
12
12
  "lint": "next lint"
13
13
  },
14
14
  "dependencies": {
15
- "@near-js/providers": "^1.0.0",
16
- "@near-wallet-selector/bitte-wallet": "^8.9.13",
17
- "@near-wallet-selector/core": "^8.9.13",
18
- "@near-wallet-selector/ethereum-wallets": "^8.9.13",
19
- "@near-wallet-selector/here-wallet": "^8.9.13",
20
- "@near-wallet-selector/ledger": "^8.9.13",
21
- "@near-wallet-selector/meteor-wallet": "^8.9.13",
22
- "@near-wallet-selector/modal-ui": "^8.9.13",
23
- "@near-wallet-selector/my-near-wallet": "^8.9.13",
24
- "@near-wallet-selector/sender": "^8.9.13",
25
- "@web3modal/wagmi": "^5.1.10",
15
+ "@near-wallet-selector/bitte-wallet": "^9.0.1",
16
+ "@near-wallet-selector/core": "^9.0.1",
17
+ "@near-wallet-selector/ethereum-wallets": "^9.0.1",
18
+ "@near-wallet-selector/here-wallet": "^9.0.1",
19
+ "@near-wallet-selector/hot-wallet": "^9.0.1",
20
+ "@near-wallet-selector/ledger": "^9.0.1",
21
+ "@near-wallet-selector/meteor-wallet": "^9.0.1",
22
+ "@near-wallet-selector/meteor-wallet-app": "^9.0.1",
23
+ "@near-wallet-selector/modal-ui": "^9.0.1",
24
+ "@near-wallet-selector/my-near-wallet": "^9.0.1",
25
+ "@near-wallet-selector/near-mobile-wallet": "^9.0.1",
26
+ "@near-wallet-selector/react-hook": "^9.0.1",
27
+ "@near-wallet-selector/sender": "^9.0.1",
28
+ "@near-wallet-selector/welldone-wallet": "^9.0.1",
29
+ "@reown/appkit": "^1.7.4",
30
+ "@reown/appkit-adapter-wagmi": "^1.7.4",
31
+ "@wagmi/core": "^2.17.1",
26
32
  "bootstrap": "^5",
27
33
  "bootstrap-icons": "^1.11.3",
28
- "near-api-js": "^4.0.3",
29
- "next": "14.2.13",
34
+ "near-api-js": "^5.0.0",
35
+ "next": "^15",
30
36
  "react": "^18",
31
- "react-dom": "^18",
32
- "wagmi": "^2.12.16"
37
+ "react-dom": "^18"
33
38
  },
34
39
  "devDependencies": {
35
40
  "encoding": "^0.1.13",
36
- "eslint": "^8",
37
- "eslint-config-next": "14.2.13",
41
+ "eslint": "^9",
42
+ "eslint-config-next": "^15",
38
43
  "pino-pretty": "^11.2.2"
39
44
  }
40
- }
45
+ }
@@ -1,17 +1,17 @@
1
1
  'use client';
2
- import { useState, useEffect, useContext } from 'react';
2
+ import { useState, useEffect } from 'react';
3
3
 
4
4
  import styles from '@/app/app.module.css';
5
5
  import { Cards } from '@/components/cards';
6
6
 
7
- import { NearContext } from '@/wallets/near';
8
7
  import { HelloNearContract } from '@/config';
8
+ import { useWalletSelector } from '@near-wallet-selector/react-hook';
9
9
 
10
10
  // Contract that the app will interact with
11
11
  const CONTRACT = HelloNearContract;
12
12
 
13
13
  export default function HelloNear() {
14
- const { signedAccountId, wallet } = useContext(NearContext);
14
+ const { signedAccountId, viewFunction, callFunction } = useWalletSelector();
15
15
 
16
16
  const [greeting, setGreeting] = useState('loading...');
17
17
  const [newGreeting, setNewGreeting] = useState('loading...');
@@ -19,11 +19,9 @@ export default function HelloNear() {
19
19
  const [showSpinner, setShowSpinner] = useState(false);
20
20
 
21
21
  useEffect(() => {
22
- if (!wallet) return;
23
-
24
- wallet.viewMethod({ contractId: CONTRACT, method: 'get_greeting' })
22
+ viewFunction({ contractId: CONTRACT, method: 'get_greeting' })
25
23
  .then(greeting => setGreeting(greeting));
26
- }, [wallet]);
24
+ }, [viewFunction]);
27
25
 
28
26
  useEffect(() => {
29
27
  setLoggedIn(!!signedAccountId);
@@ -31,8 +29,8 @@ export default function HelloNear() {
31
29
 
32
30
  const storeGreeting = async () => {
33
31
  setShowSpinner(true);
34
- await wallet.callMethod({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } });
35
- const greeting = await wallet.viewMethod({ contractId: CONTRACT, method: 'get_greeting' });
32
+ await callFunction({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } });
33
+ const greeting = await viewFunction({ contractId: CONTRACT, method: 'get_greeting' });
36
34
  setGreeting(greeting);
37
35
  setShowSpinner(false);
38
36
  };
@@ -4,25 +4,50 @@ import { useEffect, useState } from 'react';
4
4
 
5
5
  import '@/app/globals.css';
6
6
  import { Navigation } from '@/components/navigation';
7
- import { NetworkId } from '@/config';
7
+ import '@near-wallet-selector/modal-ui/styles.css';
8
+ import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
9
+ import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
10
+ import { setupMeteorWalletApp } from '@near-wallet-selector/meteor-wallet-app';
11
+ import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
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 { setupHereWallet } from '@near-wallet-selector/here-wallet';
17
+ import { setupNearMobileWallet } from '@near-wallet-selector/near-mobile-wallet';
18
+ import { setupWelldoneWallet } from '@near-wallet-selector/welldone-wallet';
19
+ import { HelloNearContract, NetworkId } from '@/config';
20
+ import { WalletSelectorProvider } from '@near-wallet-selector/react-hook';
21
+ import { wagmiAdapter, web3Modal } from '@/wallets/web3modal';
8
22
 
9
- import { NearContext, Wallet } from '@/wallets/near';
10
-
11
- const wallet = new Wallet({ networkId: NetworkId });
23
+ const walletSelectorConfig = {
24
+ network: NetworkId,
25
+ // createAccessKeyFor: HelloNearContract,
26
+ modules: [
27
+ setupMeteorWallet(),
28
+ setupEthereumWallets({ wagmiConfig: wagmiAdapter.wagmiConfig, web3Modal }),
29
+ setupBitteWallet(),
30
+ setupMeteorWalletApp({ contractId: HelloNearContract }),
31
+ setupHotWallet(),
32
+ setupLedger(),
33
+ setupSender(),
34
+ setupHereWallet(),
35
+ setupNearMobileWallet(),
36
+ setupWelldoneWallet(),
37
+ setupMyNearWallet(),
38
+ ],
39
+ }
12
40
 
13
41
  // Layout Component
14
42
  export default function RootLayout({ children }) {
15
- const [signedAccountId, setSignedAccountId] = useState('');
16
-
17
- useEffect(() => { wallet.startUp(setSignedAccountId); }, []);
18
43
 
19
44
  return (
20
45
  <html lang="en">
21
46
  <body>
22
- <NearContext.Provider value={{ wallet, signedAccountId }}>
47
+ <WalletSelectorProvider config={walletSelectorConfig}>
23
48
  <Navigation />
24
49
  {children}
25
- </NearContext.Provider>
50
+ </WalletSelectorProvider>
26
51
  </body>
27
52
  </html>
28
53
  );
@@ -1,31 +1,29 @@
1
1
  import Image from 'next/image';
2
2
  import Link from 'next/link';
3
- import { useEffect, useState, useContext } from 'react';
3
+ import { useEffect, useState } from 'react';
4
4
 
5
- import { NearContext } from '@/wallets/near';
6
5
  import NearLogo from '/public/near-logo.svg';
6
+ import { useWalletSelector } from '@near-wallet-selector/react-hook';
7
7
 
8
8
  export const Navigation = () => {
9
- const { signedAccountId, wallet } = useContext(NearContext);
9
+ const { signedAccountId, signIn, signOut } = useWalletSelector();
10
10
  const [action, setAction] = useState(() => { });
11
11
  const [label, setLabel] = useState('Loading...');
12
12
 
13
13
  useEffect(() => {
14
- if (!wallet) return;
15
-
16
14
  if (signedAccountId) {
17
- setAction(() => wallet.signOut);
15
+ setAction(() => signOut);
18
16
  setLabel(`Logout ${signedAccountId}`);
19
17
  } else {
20
- setAction(() => wallet.signIn);
18
+ setAction(() => signIn);
21
19
  setLabel('Login');
22
20
  }
23
- }, [signedAccountId, wallet]);
21
+ }, [signedAccountId, signIn, signOut]);
24
22
 
25
23
  return (
26
24
  <nav className="navbar navbar-expand-lg">
27
25
  <div className="container-fluid">
28
- <Link href="/" passHref legacyBehavior>
26
+ <Link href="/" passHref>
29
27
  <Image priority src={NearLogo} alt="NEAR" width="30" height="24" className="d-inline-block align-text-top" />
30
28
  </Link>
31
29
  <div className='navbar-nav pt-1'>
@@ -3,22 +3,5 @@ const contractPerNetwork = {
3
3
  testnet: 'hello.near-examples.testnet',
4
4
  };
5
5
 
6
- // Chains for EVM Wallets
7
- const evmWalletChains = {
8
- mainnet: {
9
- chainId: 397,
10
- name: "Near Mainnet",
11
- explorer: "https://eth-explorer.near.org",
12
- rpc: "https://eth-rpc.mainnet.near.org",
13
- },
14
- testnet: {
15
- chainId: 398,
16
- name: "Near Testnet",
17
- explorer: "https://eth-explorer-testnet.near.org",
18
- rpc: "https://eth-rpc.testnet.near.org",
19
- },
20
- }
21
-
22
6
  export const NetworkId = 'testnet';
23
- export const HelloNearContract = contractPerNetwork[NetworkId];
24
- export const EVMWalletChain = evmWalletChains[NetworkId];
7
+ export const HelloNearContract = contractPerNetwork[NetworkId];
@@ -1,44 +1,35 @@
1
- import { NetworkId, EVMWalletChain } from '@/config';
2
- import { reconnect, http, createConfig } from "@wagmi/core";
3
- import { walletConnect, injected } from "@wagmi/connectors";
4
- import { createWeb3Modal } from "@web3modal/wagmi";
1
+ import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
2
+ import { createAppKit } from "@reown/appkit/react";
3
+ import { nearTestnet } from "@reown/appkit/networks";
4
+ import { reconnect } from "@wagmi/core";
5
5
 
6
- // Config
7
- const near = {
8
- id: EVMWalletChain.chainId,
9
- name: EVMWalletChain.name,
10
- nativeCurrency: {
11
- decimals: 18,
12
- name: "NEAR",
13
- symbol: "NEAR",
14
- },
15
- rpcUrls: {
16
- default: { http: [EVMWalletChain.rpc] },
17
- public: { http: [EVMWalletChain.rpc] },
18
- },
19
- blockExplorers: {
20
- default: {
21
- name: "NEAR Explorer",
22
- url: EVMWalletChain.explorer,
23
- },
24
- },
25
- testnet: NetworkId === "testnet",
26
- };
6
+ // Get a project ID at https://cloud.reown.com
7
+ const projectId = "30147604c5f01d0bc4482ab0665b5697";
27
8
 
28
- // Get your projectId at https://cloud.reown.com
29
- const projectId = '5bb0fe33763b3bea40b8d69e4269b4ae';
30
-
31
- export const wagmiConfig = createConfig({
32
- chains: [near],
33
- transports: { [near.id]: http() },
34
- connectors: [
35
- walletConnect({ projectId, showQrModal: false }),
36
- injected({ shimDisconnect: true }),
37
- ],
9
+ export const wagmiAdapter = new WagmiAdapter({
10
+ projectId,
11
+ networks: [nearTestnet],
38
12
  });
39
13
 
40
- // Preserve login state on page reload
41
- reconnect(wagmiConfig);
14
+ export const web3Modal = createAppKit({
15
+ adapters: [wagmiAdapter],
16
+ projectId,
17
+ networks: [nearTestnet],
18
+ enableWalletConnect: true,
19
+ features: {
20
+ analytics: true,
21
+ swaps: false,
22
+ onramp: false,
23
+ email: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
24
+ socials: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
25
+ },
26
+ coinbasePreference: "eoaOnly", // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
27
+ allWallets: "SHOW",
28
+ });
42
29
 
43
- // Modal for login
44
- export const web3Modal = createWeb3Modal({ wagmiConfig, projectId });
30
+ // force reconnecting if the user has already signed in with an ethereum wallet
31
+ // this is a workaround until `ethereum-wallets` supports the `reconnect` method
32
+ if (typeof window !== "undefined") {
33
+ const recentWallets = localStorage.getItem("near-wallet-selector:recentlySignedInWallets");
34
+ recentWallets && recentWallets.includes("ethereum-wallets") && reconnect(wagmiAdapter.wagmiConfig)
35
+ }
@@ -1,6 +1,7 @@
1
1
  /** @type {import('next').NextConfig} */
2
2
  const nextConfig = {
3
3
  reactStrictMode: true,
4
+ transpilePackages: ['reown'],
4
5
  };
5
6
 
6
7
  module.exports = nextConfig;
@@ -12,29 +12,34 @@
12
12
  "lint": "next lint"
13
13
  },
14
14
  "dependencies": {
15
- "@near-js/providers": "^1.0.0",
16
- "@near-wallet-selector/bitte-wallet": "^8.9.13",
17
- "@near-wallet-selector/core": "^8.9.13",
18
- "@near-wallet-selector/ethereum-wallets": "^8.9.13",
19
- "@near-wallet-selector/here-wallet": "^8.9.13",
20
- "@near-wallet-selector/ledger": "^8.9.13",
21
- "@near-wallet-selector/meteor-wallet": "^8.9.13",
22
- "@near-wallet-selector/modal-ui": "^8.9.13",
23
- "@near-wallet-selector/my-near-wallet": "^8.9.13",
24
- "@near-wallet-selector/sender": "^8.9.13",
25
- "@web3modal/wagmi": "^5.1.10",
15
+ "@near-wallet-selector/bitte-wallet": "^9.0.1",
16
+ "@near-wallet-selector/core": "^9.0.1",
17
+ "@near-wallet-selector/ethereum-wallets": "^9.0.1",
18
+ "@near-wallet-selector/here-wallet": "^9.0.1",
19
+ "@near-wallet-selector/hot-wallet": "^9.0.1",
20
+ "@near-wallet-selector/ledger": "^9.0.1",
21
+ "@near-wallet-selector/meteor-wallet": "^9.0.1",
22
+ "@near-wallet-selector/meteor-wallet-app": "^9.0.1",
23
+ "@near-wallet-selector/modal-ui": "^9.0.1",
24
+ "@near-wallet-selector/my-near-wallet": "^9.0.1",
25
+ "@near-wallet-selector/near-mobile-wallet": "^9.0.1",
26
+ "@near-wallet-selector/react-hook": "^9.0.1",
27
+ "@near-wallet-selector/sender": "^9.0.1",
28
+ "@near-wallet-selector/welldone-wallet": "^9.0.1",
29
+ "@reown/appkit": "^1.7.4",
30
+ "@reown/appkit-adapter-wagmi": "^1.7.4",
31
+ "@wagmi/core": "^2.17.1",
26
32
  "bootstrap": "^5",
27
33
  "bootstrap-icons": "^1.11.3",
28
- "near-api-js": "^4.0.3",
29
- "next": "14.2.13",
34
+ "near-api-js": "^5.0.0",
35
+ "next": "^15",
30
36
  "react": "^18",
31
- "react-dom": "^18",
32
- "wagmi": "^2.12.16"
37
+ "react-dom": "^18"
33
38
  },
34
39
  "devDependencies": {
35
40
  "encoding": "^0.1.13",
36
- "eslint": "^8",
37
- "eslint-config-next": "14.2.13",
41
+ "eslint": "^9",
42
+ "eslint-config-next": "^15",
38
43
  "pino-pretty": "^11.2.2"
39
44
  }
40
- }
45
+ }
@@ -1,26 +1,24 @@
1
1
  import Image from 'next/image';
2
2
  import Link from 'next/link';
3
- import { useEffect, useState, useContext } from 'react';
3
+ import { useEffect, useState } from 'react';
4
+ import { useWalletSelector } from '@near-wallet-selector/react-hook';
4
5
 
5
- import { NearContext } from '@/wallets/near';
6
6
  import NearLogo from '/public/near-logo.svg';
7
7
 
8
8
  export const Navigation = () => {
9
- const { signedAccountId, wallet } = useContext(NearContext);
9
+ const { signedAccountId, signIn, signOut } = useWalletSelector();
10
10
  const [action, setAction] = useState(() => { });
11
11
  const [label, setLabel] = useState('Loading...');
12
12
 
13
13
  useEffect(() => {
14
- if (!wallet) return;
15
-
16
14
  if (signedAccountId) {
17
- setAction(() => wallet.signOut);
15
+ setAction(() => signOut);
18
16
  setLabel(`Logout ${signedAccountId}`);
19
17
  } else {
20
- setAction(() => wallet.signIn);
21
- setLabel('Login');
18
+ setAction(() => signIn);
19
+ setLabel("Login");
22
20
  }
23
- }, [signedAccountId, wallet]);
21
+ }, [signedAccountId]);
24
22
 
25
23
  return (
26
24
  <nav className="navbar navbar-expand-lg">
@@ -3,22 +3,5 @@ const contractPerNetwork = {
3
3
  testnet: 'hello.near-examples.testnet',
4
4
  };
5
5
 
6
- // Chains for EVM Wallets
7
- const evmWalletChains = {
8
- mainnet: {
9
- chainId: 397,
10
- name: "Near Mainnet",
11
- explorer: "https://eth-explorer.near.org",
12
- rpc: "https://eth-rpc.mainnet.near.org",
13
- },
14
- testnet: {
15
- chainId: 398,
16
- name: "Near Testnet",
17
- explorer: "https://eth-explorer-testnet.near.org",
18
- rpc: "https://eth-rpc.testnet.near.org",
19
- },
20
- }
21
-
22
6
  export const NetworkId = 'testnet';
23
- export const HelloNearContract = contractPerNetwork[NetworkId];
24
- export const EVMWalletChain = evmWalletChains[NetworkId];
7
+ export const HelloNearContract = contractPerNetwork[NetworkId];
@@ -1,22 +1,45 @@
1
- import { useEffect, useState } from 'react';
2
-
3
1
  import '@/styles/globals.css';
4
2
  import { Navigation } from '@/components/navigation';
5
3
 
6
- import { Wallet, NearContext } from '@/wallets/near';
7
- import { NetworkId } from '@/config';
4
+ import '@near-wallet-selector/modal-ui/styles.css';
5
+ import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
6
+ import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
7
+ import { setupMeteorWalletApp } from '@near-wallet-selector/meteor-wallet-app';
8
+ import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
9
+ import { setupEthereumWallets } from '@near-wallet-selector/ethereum-wallets';
10
+ import { setupHotWallet } from '@near-wallet-selector/hot-wallet';
11
+ import { setupLedger } from '@near-wallet-selector/ledger';
12
+ import { setupSender } from '@near-wallet-selector/sender';
13
+ import { setupHereWallet } from '@near-wallet-selector/here-wallet';
14
+ import { setupNearMobileWallet } from '@near-wallet-selector/near-mobile-wallet';
15
+ import { setupWelldoneWallet } from '@near-wallet-selector/welldone-wallet';
16
+ import { HelloNearContract, NetworkId } from '@/config';
17
+ import { WalletSelectorProvider } from '@near-wallet-selector/react-hook';
18
+ import { wagmiAdapter, web3Modal } from '@/wallets/web3modal';
8
19
 
9
- const wallet = new Wallet({ networkId: NetworkId });
20
+ const walletSelectorConfig = {
21
+ network: NetworkId,
22
+ // createAccessKeyFor: HelloNearContract,
23
+ modules: [
24
+ setupMeteorWallet(),
25
+ setupEthereumWallets({ wagmiConfig: wagmiAdapter.wagmiConfig, web3Modal }),
26
+ setupBitteWallet(),
27
+ setupMeteorWalletApp({ contractId: HelloNearContract }),
28
+ setupHotWallet(),
29
+ setupLedger(),
30
+ setupSender(),
31
+ setupHereWallet(),
32
+ setupNearMobileWallet(),
33
+ setupWelldoneWallet(),
34
+ setupMyNearWallet(),
35
+ ],
36
+ }
10
37
 
11
38
  export default function MyApp({ Component, pageProps }) {
12
- const [signedAccountId, setSignedAccountId] = useState('');
13
-
14
- useEffect(() => { wallet.startUp(setSignedAccountId) }, []);
15
-
16
39
  return (
17
- <NearContext.Provider value={{ wallet, signedAccountId }}>
40
+ <WalletSelectorProvider config={walletSelectorConfig}>
18
41
  <Navigation />
19
42
  <Component {...pageProps} />
20
- </NearContext.Provider>
43
+ </WalletSelectorProvider>
21
44
  );
22
45
  }
@@ -1,15 +1,15 @@
1
- import { useState, useEffect, useContext } from 'react';
1
+ import { useState, useEffect } from 'react';
2
2
 
3
- import { NearContext } from '@/wallets/near';
4
3
  import styles from '@/styles/app.module.css';
5
4
  import { HelloNearContract } from '../../config';
6
5
  import { Cards } from '@/components/cards';
6
+ import { useWalletSelector } from '@near-wallet-selector/react-hook';
7
7
 
8
8
  // Contract that the app will interact with
9
9
  const CONTRACT = HelloNearContract;
10
10
 
11
11
  export default function HelloNear() {
12
- const { signedAccountId, wallet } = useContext(NearContext);
12
+ const { signedAccountId, viewFunction, callFunction } = useWalletSelector();
13
13
 
14
14
  const [greeting, setGreeting] = useState('loading...');
15
15
  const [newGreeting, setNewGreeting] = useState('loading...');
@@ -17,12 +17,10 @@ export default function HelloNear() {
17
17
  const [showSpinner, setShowSpinner] = useState(false);
18
18
 
19
19
  useEffect(() => {
20
- if (!wallet) return;
21
-
22
- wallet.viewMethod({ contractId: CONTRACT, method: 'get_greeting' }).then(
20
+ viewFunction({ contractId: CONTRACT, method: 'get_greeting' }).then(
23
21
  greeting => setGreeting(greeting)
24
22
  );
25
- }, [wallet]);
23
+ }, []);
26
24
 
27
25
  useEffect(() => {
28
26
  setLoggedIn(!!signedAccountId);
@@ -30,8 +28,8 @@ export default function HelloNear() {
30
28
 
31
29
  const saveGreeting = async () => {
32
30
  setShowSpinner(true);
33
- await wallet.callMethod({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } });
34
- const greeting = await wallet.viewMethod({ contractId: CONTRACT, method: 'get_greeting' });
31
+ await callFunction({ contractId: CONTRACT, method: 'set_greeting', args: { greeting: newGreeting } });
32
+ const greeting = await viewFunction({ contractId: CONTRACT, method: 'get_greeting' });
35
33
  setGreeting(greeting);
36
34
  setShowSpinner(false);
37
35
  };
@@ -1,44 +1,35 @@
1
- import { NetworkId, EVMWalletChain } from '@/config';
2
- import { reconnect, http, createConfig } from "@wagmi/core";
3
- import { walletConnect, injected } from "@wagmi/connectors";
4
- import { createWeb3Modal } from "@web3modal/wagmi";
1
+ import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
2
+ import { createAppKit } from "@reown/appkit/react";
3
+ import { nearTestnet } from "@reown/appkit/networks";
4
+ import { reconnect } from "@wagmi/core";
5
5
 
6
- // Config
7
- const near = {
8
- id: EVMWalletChain.chainId,
9
- name: EVMWalletChain.name,
10
- nativeCurrency: {
11
- decimals: 18,
12
- name: "NEAR",
13
- symbol: "NEAR",
14
- },
15
- rpcUrls: {
16
- default: { http: [EVMWalletChain.rpc] },
17
- public: { http: [EVMWalletChain.rpc] },
18
- },
19
- blockExplorers: {
20
- default: {
21
- name: "NEAR Explorer",
22
- url: EVMWalletChain.explorer,
23
- },
24
- },
25
- testnet: NetworkId === "testnet",
26
- };
6
+ // Get a project ID at https://cloud.reown.com
7
+ const projectId = "30147604c5f01d0bc4482ab0665b5697";
27
8
 
28
- // Get your projectId at https://cloud.reown.com
29
- const projectId = '5bb0fe33763b3bea40b8d69e4269b4ae';
30
-
31
- export const wagmiConfig = createConfig({
32
- chains: [near],
33
- transports: { [near.id]: http() },
34
- connectors: [
35
- walletConnect({ projectId, showQrModal: false }),
36
- injected({ shimDisconnect: true }),
37
- ],
9
+ export const wagmiAdapter = new WagmiAdapter({
10
+ projectId,
11
+ networks: [nearTestnet],
38
12
  });
39
13
 
40
- // Preserve login state on page reload
41
- reconnect(wagmiConfig);
14
+ export const web3Modal = createAppKit({
15
+ adapters: [wagmiAdapter],
16
+ projectId,
17
+ networks: [nearTestnet],
18
+ enableWalletConnect: true,
19
+ features: {
20
+ analytics: true,
21
+ swaps: false,
22
+ onramp: false,
23
+ email: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
24
+ socials: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
25
+ },
26
+ coinbasePreference: "eoaOnly", // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
27
+ allWallets: "SHOW",
28
+ });
42
29
 
43
- // Modal for login
44
- export const web3Modal = createWeb3Modal({ wagmiConfig, projectId });
30
+ // force reconnecting if the user has already signed in with an ethereum wallet
31
+ // this is a workaround until `ethereum-wallets` supports the `reconnect` method
32
+ if (typeof window !== "undefined") {
33
+ const recentWallets = localStorage.getItem("near-wallet-selector:recentlySignedInWallets");
34
+ recentWallets && recentWallets.includes("ethereum-wallets") && reconnect(wagmiAdapter.wagmiConfig)
35
+ }