create-near-app 7.0.3 → 8.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/dist/app.js +1 -2
- package/dist/make.js +3 -7
- package/dist/messages.js +1 -1
- package/dist/tracking.js +32 -15
- package/dist/user-input.js +9 -20
- package/package.json +3 -4
- package/templates/frontend/next-app/package.json +21 -13
- package/templates/frontend/next-app/src/app/hello-near/page.js +1 -1
- package/templates/frontend/next-app/src/app/layout.js +3 -4
- package/templates/frontend/next-app/src/components/navigation.js +1 -1
- package/templates/frontend/next-app/src/config.js +18 -1
- package/templates/frontend/next-app/src/wallets/near.js +48 -11
- package/templates/frontend/next-app/src/wallets/web3modal.js +44 -0
- package/templates/frontend/next-page/package.json +21 -13
- package/templates/frontend/next-page/src/components/navigation.js +1 -1
- package/templates/frontend/next-page/src/config.js +18 -1
- package/templates/frontend/next-page/src/pages/_app.js +3 -4
- package/templates/frontend/next-page/src/pages/hello-near/index.js +1 -1
- package/templates/frontend/next-page/src/wallets/near.js +48 -11
- package/templates/frontend/next-page/src/wallets/web3modal.js +44 -0
- package/templates/frontend/components/next-app/package.json +0 -42
- package/templates/frontend/components/next-app/src/app/hello-components/page.js +0 -46
- package/templates/frontend/components/next-app/src/components/cards.js +0 -43
- package/templates/frontend/components/next-app/src/components/vm.js +0 -31
- package/templates/frontend/components/next-app/src/config.js +0 -23
- package/templates/frontend/components/next-app/src/wallets/eth.ts +0 -289
- package/templates/frontend/components/next-page/package.json +0 -42
- package/templates/frontend/components/next-page/src/components/cards.js +0 -43
- package/templates/frontend/components/next-page/src/components/vm.js +0 -29
- package/templates/frontend/components/next-page/src/config.js +0 -23
- package/templates/frontend/components/next-page/src/pages/hello-components/index.js +0 -46
- package/templates/frontend/components/next-page/src/wallets/eth.ts +0 -289
- package/templates/frontend/next-app/src/context.js +0 -13
- package/templates/frontend/next-page/src/context.js +0 -13
package/dist/app.js
CHANGED
|
@@ -39,14 +39,13 @@ const show = __importStar(require("./messages"));
|
|
|
39
39
|
const prompt = await (0, user_input_1.promptAndGetConfig)();
|
|
40
40
|
if (prompt === undefined)
|
|
41
41
|
return;
|
|
42
|
-
const { config: { projectName, contract, frontend,
|
|
42
|
+
const { config: { projectName, contract, frontend, install, }, projectPath, } = prompt;
|
|
43
43
|
show.creatingApp();
|
|
44
44
|
let createSuccess;
|
|
45
45
|
try {
|
|
46
46
|
createSuccess = await (0, make_1.createProject)({
|
|
47
47
|
contract,
|
|
48
48
|
frontend,
|
|
49
|
-
components,
|
|
50
49
|
templatesDir: path_1.default.resolve(__dirname, '../templates'),
|
|
51
50
|
projectPath,
|
|
52
51
|
});
|
package/dist/make.js
CHANGED
|
@@ -32,12 +32,12 @@ const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
33
33
|
const ncp_1 = require("ncp");
|
|
34
34
|
const path_1 = __importDefault(require("path"));
|
|
35
|
-
async function createProject({ contract, frontend,
|
|
35
|
+
async function createProject({ contract, frontend, projectPath, templatesDir }) {
|
|
36
36
|
if (contract !== 'none') {
|
|
37
37
|
await createContract({ contract, projectPath, templatesDir });
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
await createGateway({ frontend,
|
|
40
|
+
await createGateway({ frontend, projectPath, templatesDir });
|
|
41
41
|
}
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
@@ -48,14 +48,10 @@ async function createContract({ contract, projectPath, templatesDir }) {
|
|
|
48
48
|
fs_1.default.mkdirSync(projectPath, { recursive: true });
|
|
49
49
|
await copyDir(sourceContractDir, projectPath);
|
|
50
50
|
}
|
|
51
|
-
async function createGateway({ frontend,
|
|
51
|
+
async function createGateway({ frontend, projectPath, templatesDir }) {
|
|
52
52
|
const sourceFrontendDir = path_1.default.resolve(`${templatesDir}/frontend/${frontend}`);
|
|
53
53
|
fs_1.default.mkdirSync(projectPath, { recursive: true });
|
|
54
54
|
await copyDir(sourceFrontendDir, projectPath);
|
|
55
|
-
if (components) {
|
|
56
|
-
const sourceComponentsDir = path_1.default.resolve(`${templatesDir}/frontend/components/${frontend}`);
|
|
57
|
-
await copyDir(sourceComponentsDir, projectPath);
|
|
58
|
-
}
|
|
59
55
|
}
|
|
60
56
|
// Wrap `ncp` tool to wait for the copy to finish when using `await`
|
|
61
57
|
function copyDir(source, dest) {
|
package/dist/messages.js
CHANGED
|
@@ -16,7 +16,7 @@ const welcome = () => (0, exports.show)((0, chalk_1.default) `
|
|
|
16
16
|
👋 {bold {green Welcome to Near!}} Learn more: https://docs.near.org/
|
|
17
17
|
🔧 Let's get your project ready.
|
|
18
18
|
{blue ======================================================}
|
|
19
|
-
(${tracking_1.trackingMessage})`);
|
|
19
|
+
(${tracking_1.trackingMessage})\n`);
|
|
20
20
|
exports.welcome = welcome;
|
|
21
21
|
const setupFailed = () => (0, exports.show)((0, chalk_1.default) `{bold {red ==========================================}}
|
|
22
22
|
{red ⛔️ There was a problem during the project setup}.
|
package/dist/tracking.js
CHANGED
|
@@ -5,27 +5,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.trackUsage = exports.trackingMessage = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
exports.trackingMessage = (0, chalk_1.default) `Near collects anonymous information on the commands used. No personal information that could identify you is shared`;
|
|
8
|
+
const POSTHOG_API_KEY = 'phc_95PGQnbyatmj2TBRPWYfhbHfqB6wgZj5QRL8WY9gW20';
|
|
9
|
+
const POSTHOG_API_URL = 'https://eu.i.posthog.com/capture';
|
|
10
|
+
exports.trackingMessage = chalk_1.default.italic('Near collects anonymous information on the commands used. No personal information that could identify you is shared');
|
|
12
11
|
// TODO: track different failures & install usage
|
|
13
|
-
const trackUsage = async (frontend,
|
|
12
|
+
const trackUsage = async (frontend, contract) => {
|
|
14
13
|
// prevents logging from CI
|
|
15
14
|
if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') {
|
|
16
|
-
console.log('
|
|
15
|
+
console.log('PostHog logging is skipped in CI env');
|
|
17
16
|
return;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const payload = {
|
|
19
|
+
distinct_id: 'create-near-app',
|
|
20
|
+
event: 'error',
|
|
21
|
+
properties: {
|
|
22
|
+
engine: process.versions.node,
|
|
24
23
|
os: process.platform,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
},
|
|
25
|
+
timestamp: new Date(),
|
|
26
|
+
};
|
|
27
|
+
if (contract !== 'none') {
|
|
28
|
+
payload.event = 'contract';
|
|
29
|
+
payload.properties.language = contract;
|
|
30
|
+
}
|
|
31
|
+
if (frontend !== 'none') {
|
|
32
|
+
payload.event = 'frontend';
|
|
33
|
+
payload.properties.framework = frontend;
|
|
34
|
+
}
|
|
35
|
+
const headers = new Headers();
|
|
36
|
+
headers.append('Content-Type', 'application/json');
|
|
37
|
+
try {
|
|
38
|
+
await fetch(POSTHOG_API_URL, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
api_key: POSTHOG_API_KEY,
|
|
42
|
+
...payload,
|
|
43
|
+
}),
|
|
44
|
+
headers,
|
|
45
|
+
});
|
|
29
46
|
}
|
|
30
47
|
catch (e) {
|
|
31
48
|
console.error('Warning: problem while sending tracking data. Error: ', e);
|
package/dist/user-input.js
CHANGED
|
@@ -39,14 +39,13 @@ async function getUserArgs() {
|
|
|
39
39
|
.argument('[projectName]')
|
|
40
40
|
.option('--frontend [next-page|next-app|none]')
|
|
41
41
|
.option('--contract [ts|rs|none]')
|
|
42
|
-
.option('--components')
|
|
43
42
|
.option('--install')
|
|
44
43
|
.addHelpText('after', 'You can create a frontend or a contract with tests');
|
|
45
44
|
commander_1.program.parse();
|
|
46
45
|
const options = commander_1.program.opts();
|
|
47
46
|
const [projectName] = commander_1.program.args;
|
|
48
|
-
const { contract, frontend, install
|
|
49
|
-
return { contract, frontend,
|
|
47
|
+
const { contract, frontend, install } = options;
|
|
48
|
+
return { contract, frontend, projectName, install, error: undefined };
|
|
50
49
|
}
|
|
51
50
|
exports.getUserArgs = getUserArgs;
|
|
52
51
|
const appChoices = [
|
|
@@ -63,10 +62,6 @@ const frontendChoices = [
|
|
|
63
62
|
{ title: 'NextJs (Classic)', description: 'A web-app built using Next.js Page Router', value: 'next-page' },
|
|
64
63
|
{ title: 'NextJS (App Router)', description: 'A web-app built using Next.js new App Router', value: 'next-app' },
|
|
65
64
|
];
|
|
66
|
-
const componentChoices = [
|
|
67
|
-
{ title: 'No', value: false },
|
|
68
|
-
{ title: 'Yes', value: true },
|
|
69
|
-
];
|
|
70
65
|
const appPrompt = {
|
|
71
66
|
type: 'select',
|
|
72
67
|
name: 'app',
|
|
@@ -79,12 +74,6 @@ const frontendPrompt = {
|
|
|
79
74
|
message: 'Select a framework for your frontend',
|
|
80
75
|
choices: frontendChoices,
|
|
81
76
|
};
|
|
82
|
-
const componentsPrompt = {
|
|
83
|
-
type: 'select',
|
|
84
|
-
name: 'components',
|
|
85
|
-
message: 'Are you planning in using on-chain NEAR Components (aka BOS Components)?',
|
|
86
|
-
choices: componentChoices,
|
|
87
|
-
};
|
|
88
77
|
const contractPrompt = [
|
|
89
78
|
{
|
|
90
79
|
type: 'select',
|
|
@@ -114,19 +103,19 @@ async function getUserAnswers() {
|
|
|
114
103
|
const { app } = await promptUser(appPrompt);
|
|
115
104
|
if (app === 'gateway') {
|
|
116
105
|
// If gateway, ask for the framework to use
|
|
117
|
-
const { frontend,
|
|
118
|
-
return { frontend,
|
|
106
|
+
const { frontend, projectName, install } = await promptUser([frontendPrompt, namePrompts, npmPrompt]);
|
|
107
|
+
return { frontend, contract: 'none', projectName, install, error: undefined };
|
|
119
108
|
}
|
|
120
109
|
else {
|
|
121
110
|
// If platform is Window, return the error
|
|
122
111
|
if (process.platform === 'win32') {
|
|
123
|
-
return { frontend: 'none',
|
|
112
|
+
return { frontend: 'none', contract: 'none', projectName: '', install: false, error: show.windowsWarning };
|
|
124
113
|
}
|
|
125
114
|
// If contract, ask for the language for the contract
|
|
126
115
|
let { contract } = await promptUser(contractPrompt);
|
|
127
116
|
const { projectName } = await promptUser(namePrompts);
|
|
128
117
|
const install = contract === 'ts' ? (await promptUser(npmPrompt)).install : false;
|
|
129
|
-
return { frontend: 'none',
|
|
118
|
+
return { frontend: 'none', contract, projectName, install, error: undefined };
|
|
130
119
|
}
|
|
131
120
|
}
|
|
132
121
|
exports.getUserAnswers = getUserAnswers;
|
|
@@ -139,7 +128,7 @@ async function promptAndGetConfig() {
|
|
|
139
128
|
args = await getUserAnswers();
|
|
140
129
|
}
|
|
141
130
|
if (args.error) {
|
|
142
|
-
(0, tracking_1.trackUsage)('none',
|
|
131
|
+
(0, tracking_1.trackUsage)('none', 'none');
|
|
143
132
|
return args.error();
|
|
144
133
|
}
|
|
145
134
|
// Homogenizing terminal args with prompt args
|
|
@@ -148,8 +137,8 @@ async function promptAndGetConfig() {
|
|
|
148
137
|
if (!validateUserArgs(args))
|
|
149
138
|
return;
|
|
150
139
|
// track user input
|
|
151
|
-
const { frontend,
|
|
152
|
-
(0, tracking_1.trackUsage)(frontend,
|
|
140
|
+
const { frontend, contract } = args;
|
|
141
|
+
(0, tracking_1.trackUsage)(frontend, contract);
|
|
153
142
|
let path = (0, exports.projectPath)(args.projectName);
|
|
154
143
|
if (fs_1.default.existsSync(path)) {
|
|
155
144
|
return show.directoryExists(path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-near-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Quickly scaffold your dApp on NEAR Blockchain",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -27,16 +27,15 @@
|
|
|
27
27
|
"chalk": "^4.1.2",
|
|
28
28
|
"commander": "^11.0.0",
|
|
29
29
|
"cross-spawn": "^7.0.3",
|
|
30
|
-
"mixpanel": "^0.18.0",
|
|
31
30
|
"ncp": "^2.0.0",
|
|
32
31
|
"prompts": "^2.4.2",
|
|
33
32
|
"semver": "^7.5.3"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@babel/eslint-parser": "^7.22.5",
|
|
37
35
|
"@babel/core": "^7.23.2",
|
|
38
|
-
"@babel/
|
|
36
|
+
"@babel/eslint-parser": "^7.22.5",
|
|
39
37
|
"@babel/plugin-syntax-flow": "^7.22.5",
|
|
38
|
+
"@babel/plugin-transform-react-jsx": "^7.22.15",
|
|
40
39
|
"@commitlint/cli": "^17.6.6",
|
|
41
40
|
"@commitlint/config-conventional": "^17.6.6",
|
|
42
41
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
@@ -12,26 +12,34 @@
|
|
|
12
12
|
"lint": "next lint"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@near-
|
|
16
|
-
"@near-wallet-selector/
|
|
17
|
-
"@near-wallet-selector/
|
|
18
|
-
"@near-wallet-selector/
|
|
19
|
-
"@near-wallet-selector/
|
|
20
|
-
"@near-wallet-selector/
|
|
21
|
-
"@near-wallet-selector/
|
|
22
|
-
"@near-wallet-selector/
|
|
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",
|
|
23
26
|
"bootstrap": "^5",
|
|
24
27
|
"bootstrap-icons": "^1.11.3",
|
|
25
28
|
"near-api-js": "^4.0.3",
|
|
26
|
-
"next": "14.2.
|
|
29
|
+
"next": "14.2.13",
|
|
27
30
|
"react": "^18",
|
|
28
|
-
"react-dom": "^18"
|
|
31
|
+
"react-dom": "^18",
|
|
32
|
+
"wagmi": "^2.12.16"
|
|
29
33
|
},
|
|
30
|
-
"
|
|
31
|
-
"near-
|
|
34
|
+
"overrides": {
|
|
35
|
+
"@near-wallet-selector/ethereum-wallets": {
|
|
36
|
+
"near-api-js": "4.0.3"
|
|
37
|
+
}
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
40
|
+
"encoding": "^0.1.13",
|
|
34
41
|
"eslint": "^8",
|
|
35
|
-
"eslint-config-next": "14.2.
|
|
42
|
+
"eslint-config-next": "14.2.13",
|
|
43
|
+
"pino-pretty": "^11.2.2"
|
|
36
44
|
}
|
|
37
45
|
}
|
|
@@ -4,7 +4,7 @@ import { useState, useEffect, useContext } from 'react';
|
|
|
4
4
|
import styles from '@/app/app.module.css';
|
|
5
5
|
import { Cards } from '@/components/cards';
|
|
6
6
|
|
|
7
|
-
import { NearContext } from '@/
|
|
7
|
+
import { NearContext } from '@/wallets/near';
|
|
8
8
|
import { HelloNearContract } from '@/config';
|
|
9
9
|
|
|
10
10
|
// Contract that the app will interact with
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import '@/app/globals.css';
|
|
6
|
-
import { NearContext } from '@/context';
|
|
7
6
|
import { Navigation } from '@/components/navigation';
|
|
8
|
-
import { NetworkId
|
|
7
|
+
import { NetworkId } from '@/config';
|
|
9
8
|
|
|
10
|
-
import { Wallet } from '@/wallets/near';
|
|
9
|
+
import { NearContext, Wallet } from '@/wallets/near';
|
|
11
10
|
|
|
12
|
-
const wallet = new Wallet({ networkId: NetworkId
|
|
11
|
+
const wallet = new Wallet({ networkId: NetworkId });
|
|
13
12
|
|
|
14
13
|
// Layout Component
|
|
15
14
|
export default function RootLayout({ children }) {
|
|
@@ -2,7 +2,7 @@ import Image from 'next/image';
|
|
|
2
2
|
import Link from 'next/link';
|
|
3
3
|
import { useEffect, useState, useContext } from 'react';
|
|
4
4
|
|
|
5
|
-
import { NearContext } from '@/
|
|
5
|
+
import { NearContext } from '@/wallets/near';
|
|
6
6
|
import NearLogo from '/public/near-logo.svg';
|
|
7
7
|
|
|
8
8
|
export const Navigation = () => {
|
|
@@ -3,5 +3,22 @@ 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
|
+
|
|
6
22
|
export const NetworkId = 'testnet';
|
|
7
|
-
export const HelloNearContract = contractPerNetwork[NetworkId];
|
|
23
|
+
export const HelloNearContract = contractPerNetwork[NetworkId];
|
|
24
|
+
export const EVMWalletChain = evmWalletChains[NetworkId];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
import { distinctUntilChanged, map } from 'rxjs';
|
|
3
2
|
|
|
4
3
|
// near api js
|
|
5
|
-
import { providers } from 'near-api-js';
|
|
4
|
+
import { providers, utils } from 'near-api-js';
|
|
6
5
|
|
|
7
6
|
// wallet selector
|
|
8
7
|
import '@near-wallet-selector/modal-ui/styles.css';
|
|
@@ -15,6 +14,10 @@ import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
|
|
|
15
14
|
import { setupSender } from '@near-wallet-selector/sender';
|
|
16
15
|
import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
|
|
17
16
|
|
|
17
|
+
// ethereum wallets
|
|
18
|
+
import { wagmiConfig, web3Modal } from '@/wallets/web3modal';
|
|
19
|
+
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
|
|
20
|
+
|
|
18
21
|
const THIRTY_TGAS = '30000000000000';
|
|
19
22
|
const NO_DEPOSIT = '0';
|
|
20
23
|
|
|
@@ -48,6 +51,7 @@ export class Wallet {
|
|
|
48
51
|
setupMeteorWallet(),
|
|
49
52
|
setupSender(),
|
|
50
53
|
setupBitteWallet(),
|
|
54
|
+
setupEthereumWallets({ wagmiConfig, web3Modal, alwaysOnboardDuringSignIn: true }),
|
|
51
55
|
],
|
|
52
56
|
});
|
|
53
57
|
|
|
@@ -55,15 +59,10 @@ export class Wallet {
|
|
|
55
59
|
const isSignedIn = walletSelector.isSignedIn();
|
|
56
60
|
const accountId = isSignedIn ? walletSelector.store.getState().accounts[0].accountId : '';
|
|
57
61
|
|
|
58
|
-
walletSelector.store.observable
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
.subscribe(accounts => {
|
|
64
|
-
const signedAccount = accounts.find((account) => account.active)?.accountId;
|
|
65
|
-
accountChangeHook(signedAccount);
|
|
66
|
-
});
|
|
62
|
+
walletSelector.store.observable.subscribe(async (state) => {
|
|
63
|
+
const signedAccount = state?.accounts.find(account => account.active)?.accountId;
|
|
64
|
+
accountChangeHook(signedAccount || '');
|
|
65
|
+
});
|
|
67
66
|
|
|
68
67
|
return accountId;
|
|
69
68
|
};
|
|
@@ -152,6 +151,12 @@ export class Wallet {
|
|
|
152
151
|
return providers.getTransactionLastResult(transaction);
|
|
153
152
|
};
|
|
154
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Gets the balance of an account
|
|
156
|
+
* @param {string} accountId - the account id to get the balance of
|
|
157
|
+
* @returns {Promise<number>} - the balance of the account
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
155
160
|
getBalance = async (accountId) => {
|
|
156
161
|
const walletSelector = await this.selector;
|
|
157
162
|
const { network } = walletSelector.options;
|
|
@@ -167,12 +172,44 @@ export class Wallet {
|
|
|
167
172
|
return account.amount ? Number(utils.format.formatNearAmount(account.amount)) : 0;
|
|
168
173
|
};
|
|
169
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Signs and sends transactions
|
|
177
|
+
* @param {Object[]} transactions - the transactions to sign and send
|
|
178
|
+
* @returns {Promise<Transaction[]>} - the resulting transactions
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
170
181
|
signAndSendTransactions = async ({ transactions }) => {
|
|
171
182
|
const selectedWallet = await (await this.selector).wallet();
|
|
172
183
|
return selectedWallet.signAndSendTransactions({ transactions });
|
|
173
184
|
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param {string} accountId
|
|
189
|
+
* @returns {Promise<Object[]>} - the access keys for the
|
|
190
|
+
*/
|
|
191
|
+
getAccessKeys = async (accountId) => {
|
|
192
|
+
const walletSelector = await this.selector;
|
|
193
|
+
const { network } = walletSelector.options;
|
|
194
|
+
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
195
|
+
|
|
196
|
+
// Retrieve account state from the network
|
|
197
|
+
const keys = await provider.query({
|
|
198
|
+
request_type: 'view_access_key_list',
|
|
199
|
+
account_id: accountId,
|
|
200
|
+
finality: 'final',
|
|
201
|
+
});
|
|
202
|
+
return keys.keys;
|
|
203
|
+
};
|
|
174
204
|
}
|
|
175
205
|
|
|
206
|
+
/**
|
|
207
|
+
* @typedef NearContext
|
|
208
|
+
* @property {import('./wallets/near').Wallet} wallet Current wallet
|
|
209
|
+
* @property {string} signedAccountId The AccountId of the signed user
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
/** @type {import ('react').Context<NearContext>} */
|
|
176
213
|
export const NearContext = createContext({
|
|
177
214
|
wallet: undefined,
|
|
178
215
|
signedAccountId: '',
|
|
@@ -0,0 +1,44 @@
|
|
|
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";
|
|
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
|
+
};
|
|
27
|
+
|
|
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
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Preserve login state on page reload
|
|
41
|
+
reconnect(wagmiConfig);
|
|
42
|
+
|
|
43
|
+
// Modal for login
|
|
44
|
+
export const web3Modal = createWeb3Modal({ wagmiConfig, projectId });
|
|
@@ -12,26 +12,34 @@
|
|
|
12
12
|
"lint": "next lint"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@near-
|
|
16
|
-
"@near-wallet-selector/
|
|
17
|
-
"@near-wallet-selector/
|
|
18
|
-
"@near-wallet-selector/
|
|
19
|
-
"@near-wallet-selector/
|
|
20
|
-
"@near-wallet-selector/
|
|
21
|
-
"@near-wallet-selector/
|
|
22
|
-
"@near-wallet-selector/
|
|
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",
|
|
23
26
|
"bootstrap": "^5",
|
|
24
27
|
"bootstrap-icons": "^1.11.3",
|
|
25
28
|
"near-api-js": "^4.0.3",
|
|
26
|
-
"next": "14.2.
|
|
29
|
+
"next": "14.2.13",
|
|
27
30
|
"react": "^18",
|
|
28
|
-
"react-dom": "^18"
|
|
31
|
+
"react-dom": "^18",
|
|
32
|
+
"wagmi": "^2.12.16"
|
|
29
33
|
},
|
|
30
|
-
"
|
|
31
|
-
"near-
|
|
34
|
+
"overrides": {
|
|
35
|
+
"@near-wallet-selector/ethereum-wallets": {
|
|
36
|
+
"near-api-js": "4.0.3"
|
|
37
|
+
}
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
40
|
+
"encoding": "^0.1.13",
|
|
34
41
|
"eslint": "^8",
|
|
35
|
-
"eslint-config-next": "14.2.
|
|
42
|
+
"eslint-config-next": "14.2.13",
|
|
43
|
+
"pino-pretty": "^11.2.2"
|
|
36
44
|
}
|
|
37
45
|
}
|
|
@@ -2,7 +2,7 @@ import Image from 'next/image';
|
|
|
2
2
|
import Link from 'next/link';
|
|
3
3
|
import { useEffect, useState, useContext } from 'react';
|
|
4
4
|
|
|
5
|
-
import { NearContext } from '@/
|
|
5
|
+
import { NearContext } from '@/wallets/near';
|
|
6
6
|
import NearLogo from '/public/near-logo.svg';
|
|
7
7
|
|
|
8
8
|
export const Navigation = () => {
|
|
@@ -3,5 +3,22 @@ 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
|
+
|
|
6
22
|
export const NetworkId = 'testnet';
|
|
7
|
-
export const HelloNearContract = contractPerNetwork[NetworkId];
|
|
23
|
+
export const HelloNearContract = contractPerNetwork[NetworkId];
|
|
24
|
+
export const EVMWalletChain = evmWalletChains[NetworkId];
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import '@/styles/globals.css';
|
|
4
|
-
import { NearContext } from '@/context';
|
|
5
4
|
import { Navigation } from '@/components/navigation';
|
|
6
5
|
|
|
7
|
-
import { Wallet } from '@/wallets/near';
|
|
8
|
-
import { NetworkId
|
|
6
|
+
import { Wallet, NearContext } from '@/wallets/near';
|
|
7
|
+
import { NetworkId } from '@/config';
|
|
9
8
|
|
|
10
|
-
const wallet = new Wallet({
|
|
9
|
+
const wallet = new Wallet({ networkId: NetworkId });
|
|
11
10
|
|
|
12
11
|
export default function MyApp({ Component, pageProps }) {
|
|
13
12
|
const [signedAccountId, setSignedAccountId] = useState('');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useContext } from 'react';
|
|
2
2
|
|
|
3
|
-
import { NearContext } from '@/
|
|
3
|
+
import { NearContext } from '@/wallets/near';
|
|
4
4
|
import styles from '@/styles/app.module.css';
|
|
5
5
|
import { HelloNearContract } from '../../config';
|
|
6
6
|
import { Cards } from '@/components/cards';
|