create-near-app 7.0.2 → 7.0.3
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 +0 -5
- package/dist/messages.js +1 -1
- package/dist/user-input.js +14 -4
- package/package.json +1 -1
- package/templates/contracts/rs/Cargo.lock +6619 -0
- package/templates/contracts/rs/Cargo.toml +3 -3
- package/templates/contracts/rs/src/lib.rs +1 -1
- package/templates/contracts/rs/tests/test_basics.rs +6 -5
- package/templates/contracts/ts/package.json +4 -2
- package/templates/contracts/ts/src/contract.ts +5 -0
- package/templates/contracts/ts/yarn.lock +3290 -0
- package/templates/frontend/next-app/package.json +11 -7
- package/templates/frontend/next-app/src/wallets/near.js +42 -5
- package/templates/frontend/next-page/package.json +11 -7
- package/templates/frontend/next-page/src/wallets/near.js +42 -5
|
@@ -12,19 +12,23 @@
|
|
|
12
12
|
"lint": "next lint"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@near-wallet-selector/core": "^8.9.
|
|
16
|
-
"@near-wallet-selector/here-wallet": "^8.9.
|
|
17
|
-
"@near-wallet-selector/
|
|
18
|
-
"@near-wallet-selector/
|
|
15
|
+
"@near-wallet-selector/core": "^8.9.12",
|
|
16
|
+
"@near-wallet-selector/here-wallet": "^8.9.12",
|
|
17
|
+
"@near-wallet-selector/ledger": "^8.9.12",
|
|
18
|
+
"@near-wallet-selector/meteor-wallet": "^8.9.12",
|
|
19
|
+
"@near-wallet-selector/modal-ui": "^8.9.12",
|
|
20
|
+
"@near-wallet-selector/my-near-wallet": "^8.9.12",
|
|
21
|
+
"@near-wallet-selector/bitte-wallet": "^8.9.12",
|
|
22
|
+
"@near-wallet-selector/sender": "^8.9.12",
|
|
19
23
|
"bootstrap": "^5",
|
|
20
24
|
"bootstrap-icons": "^1.11.3",
|
|
21
|
-
"near-api-js": "^
|
|
25
|
+
"near-api-js": "^4.0.3",
|
|
22
26
|
"next": "14.2.3",
|
|
23
27
|
"react": "^18",
|
|
24
28
|
"react-dom": "^18"
|
|
25
29
|
},
|
|
26
|
-
"
|
|
27
|
-
"near-api-js": "
|
|
30
|
+
"resolutions": {
|
|
31
|
+
"near-api-js": "4.0.4"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"eslint": "^8",
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { distinctUntilChanged, map } from 'rxjs';
|
|
3
|
+
|
|
1
4
|
// near api js
|
|
2
5
|
import { providers } from 'near-api-js';
|
|
3
6
|
|
|
4
7
|
// wallet selector
|
|
5
|
-
import { distinctUntilChanged, map } from 'rxjs';
|
|
6
8
|
import '@near-wallet-selector/modal-ui/styles.css';
|
|
7
9
|
import { setupModal } from '@near-wallet-selector/modal-ui';
|
|
8
10
|
import { setupWalletSelector } from '@near-wallet-selector/core';
|
|
9
11
|
import { setupHereWallet } from '@near-wallet-selector/here-wallet';
|
|
10
12
|
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
|
|
13
|
+
import { setupLedger } from '@near-wallet-selector/ledger';
|
|
14
|
+
import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
|
|
15
|
+
import { setupSender } from '@near-wallet-selector/sender';
|
|
16
|
+
import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
|
|
11
17
|
|
|
12
18
|
const THIRTY_TGAS = '30000000000000';
|
|
13
19
|
const NO_DEPOSIT = '0';
|
|
@@ -35,7 +41,14 @@ export class Wallet {
|
|
|
35
41
|
startUp = async (accountChangeHook) => {
|
|
36
42
|
this.selector = setupWalletSelector({
|
|
37
43
|
network: this.networkId,
|
|
38
|
-
modules: [
|
|
44
|
+
modules: [
|
|
45
|
+
setupMyNearWallet(),
|
|
46
|
+
setupHereWallet(),
|
|
47
|
+
setupLedger(),
|
|
48
|
+
setupMeteorWallet(),
|
|
49
|
+
setupSender(),
|
|
50
|
+
setupBitteWallet(),
|
|
51
|
+
],
|
|
39
52
|
});
|
|
40
53
|
|
|
41
54
|
const walletSelector = await this.selector;
|
|
@@ -83,7 +96,7 @@ export class Wallet {
|
|
|
83
96
|
const url = `https://rpc.${this.networkId}.near.org`;
|
|
84
97
|
const provider = new providers.JsonRpcProvider({ url });
|
|
85
98
|
|
|
86
|
-
|
|
99
|
+
const res = await provider.query({
|
|
87
100
|
request_type: 'call_function',
|
|
88
101
|
account_id: contractId,
|
|
89
102
|
method_name: method,
|
|
@@ -93,7 +106,6 @@ export class Wallet {
|
|
|
93
106
|
return JSON.parse(Buffer.from(res.result).toString());
|
|
94
107
|
};
|
|
95
108
|
|
|
96
|
-
|
|
97
109
|
/**
|
|
98
110
|
* Makes a call to a contract
|
|
99
111
|
* @param {Object} options - the options for the call
|
|
@@ -139,4 +151,29 @@ export class Wallet {
|
|
|
139
151
|
const transaction = await provider.txStatus(txhash, 'unnused');
|
|
140
152
|
return providers.getTransactionLastResult(transaction);
|
|
141
153
|
};
|
|
142
|
-
|
|
154
|
+
|
|
155
|
+
getBalance = async (accountId) => {
|
|
156
|
+
const walletSelector = await this.selector;
|
|
157
|
+
const { network } = walletSelector.options;
|
|
158
|
+
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
159
|
+
|
|
160
|
+
// Retrieve account state from the network
|
|
161
|
+
const account = await provider.query({
|
|
162
|
+
request_type: 'view_account',
|
|
163
|
+
account_id: accountId,
|
|
164
|
+
finality: 'final',
|
|
165
|
+
});
|
|
166
|
+
// return amount on NEAR
|
|
167
|
+
return account.amount ? Number(utils.format.formatNearAmount(account.amount)) : 0;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
signAndSendTransactions = async ({ transactions }) => {
|
|
171
|
+
const selectedWallet = await (await this.selector).wallet();
|
|
172
|
+
return selectedWallet.signAndSendTransactions({ transactions });
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const NearContext = createContext({
|
|
177
|
+
wallet: undefined,
|
|
178
|
+
signedAccountId: '',
|
|
179
|
+
});
|
|
@@ -12,19 +12,23 @@
|
|
|
12
12
|
"lint": "next lint"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@near-wallet-selector/core": "^8.9.
|
|
16
|
-
"@near-wallet-selector/here-wallet": "^8.9.
|
|
17
|
-
"@near-wallet-selector/
|
|
18
|
-
"@near-wallet-selector/
|
|
15
|
+
"@near-wallet-selector/core": "^8.9.12",
|
|
16
|
+
"@near-wallet-selector/here-wallet": "^8.9.12",
|
|
17
|
+
"@near-wallet-selector/ledger": "^8.9.12",
|
|
18
|
+
"@near-wallet-selector/meteor-wallet": "^8.9.12",
|
|
19
|
+
"@near-wallet-selector/modal-ui": "^8.9.12",
|
|
20
|
+
"@near-wallet-selector/my-near-wallet": "^8.9.12",
|
|
21
|
+
"@near-wallet-selector/bitte-wallet": "^8.9.12",
|
|
22
|
+
"@near-wallet-selector/sender": "^8.9.12",
|
|
19
23
|
"bootstrap": "^5",
|
|
20
24
|
"bootstrap-icons": "^1.11.3",
|
|
21
|
-
"near-api-js": "^
|
|
25
|
+
"near-api-js": "^4.0.3",
|
|
22
26
|
"next": "14.2.3",
|
|
23
27
|
"react": "^18",
|
|
24
28
|
"react-dom": "^18"
|
|
25
29
|
},
|
|
26
|
-
"
|
|
27
|
-
"near-api-js": "
|
|
30
|
+
"resolutions": {
|
|
31
|
+
"near-api-js": "4.0.4"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"eslint": "^8",
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { distinctUntilChanged, map } from 'rxjs';
|
|
3
|
+
|
|
1
4
|
// near api js
|
|
2
5
|
import { providers } from 'near-api-js';
|
|
3
6
|
|
|
4
7
|
// wallet selector
|
|
5
|
-
import { distinctUntilChanged, map } from 'rxjs';
|
|
6
8
|
import '@near-wallet-selector/modal-ui/styles.css';
|
|
7
9
|
import { setupModal } from '@near-wallet-selector/modal-ui';
|
|
8
10
|
import { setupWalletSelector } from '@near-wallet-selector/core';
|
|
9
11
|
import { setupHereWallet } from '@near-wallet-selector/here-wallet';
|
|
10
12
|
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
|
|
13
|
+
import { setupLedger } from '@near-wallet-selector/ledger';
|
|
14
|
+
import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
|
|
15
|
+
import { setupSender } from '@near-wallet-selector/sender';
|
|
16
|
+
import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
|
|
11
17
|
|
|
12
18
|
const THIRTY_TGAS = '30000000000000';
|
|
13
19
|
const NO_DEPOSIT = '0';
|
|
@@ -35,7 +41,14 @@ export class Wallet {
|
|
|
35
41
|
startUp = async (accountChangeHook) => {
|
|
36
42
|
this.selector = setupWalletSelector({
|
|
37
43
|
network: this.networkId,
|
|
38
|
-
modules: [
|
|
44
|
+
modules: [
|
|
45
|
+
setupMyNearWallet(),
|
|
46
|
+
setupHereWallet(),
|
|
47
|
+
setupLedger(),
|
|
48
|
+
setupMeteorWallet(),
|
|
49
|
+
setupSender(),
|
|
50
|
+
setupBitteWallet(),
|
|
51
|
+
],
|
|
39
52
|
});
|
|
40
53
|
|
|
41
54
|
const walletSelector = await this.selector;
|
|
@@ -83,7 +96,7 @@ export class Wallet {
|
|
|
83
96
|
const url = `https://rpc.${this.networkId}.near.org`;
|
|
84
97
|
const provider = new providers.JsonRpcProvider({ url });
|
|
85
98
|
|
|
86
|
-
|
|
99
|
+
const res = await provider.query({
|
|
87
100
|
request_type: 'call_function',
|
|
88
101
|
account_id: contractId,
|
|
89
102
|
method_name: method,
|
|
@@ -93,7 +106,6 @@ export class Wallet {
|
|
|
93
106
|
return JSON.parse(Buffer.from(res.result).toString());
|
|
94
107
|
};
|
|
95
108
|
|
|
96
|
-
|
|
97
109
|
/**
|
|
98
110
|
* Makes a call to a contract
|
|
99
111
|
* @param {Object} options - the options for the call
|
|
@@ -139,4 +151,29 @@ export class Wallet {
|
|
|
139
151
|
const transaction = await provider.txStatus(txhash, 'unnused');
|
|
140
152
|
return providers.getTransactionLastResult(transaction);
|
|
141
153
|
};
|
|
142
|
-
|
|
154
|
+
|
|
155
|
+
getBalance = async (accountId) => {
|
|
156
|
+
const walletSelector = await this.selector;
|
|
157
|
+
const { network } = walletSelector.options;
|
|
158
|
+
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
159
|
+
|
|
160
|
+
// Retrieve account state from the network
|
|
161
|
+
const account = await provider.query({
|
|
162
|
+
request_type: 'view_account',
|
|
163
|
+
account_id: accountId,
|
|
164
|
+
finality: 'final',
|
|
165
|
+
});
|
|
166
|
+
// return amount on NEAR
|
|
167
|
+
return account.amount ? Number(utils.format.formatNearAmount(account.amount)) : 0;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
signAndSendTransactions = async ({ transactions }) => {
|
|
171
|
+
const selectedWallet = await (await this.selector).wallet();
|
|
172
|
+
return selectedWallet.signAndSendTransactions({ transactions });
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const NearContext = createContext({
|
|
177
|
+
wallet: undefined,
|
|
178
|
+
signedAccountId: '',
|
|
179
|
+
});
|