create-near-app 8.0.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.
- package/dist/messages.js +2 -1
- package/dist/types.js +1 -1
- package/dist/user-input.js +1 -0
- package/package.json +2 -1
- package/templates/contracts/rs/.github/workflows/deploy-production.yml +27 -0
- package/templates/contracts/rs/.github/workflows/deploy-staging.yml +56 -0
- package/templates/contracts/rs/.github/workflows/test.yml +32 -0
- package/templates/contracts/rs/.github/workflows/undeploy-staging.yml +25 -0
- package/templates/contracts/rs/Cargo.lock +973 -3244
- package/templates/contracts/rs/Cargo.toml +23 -6
- package/templates/contracts/rs/README.md +5 -7
- package/templates/contracts/rs/src/lib.rs +1 -1
- package/templates/contracts/rs/tests/test_basics.rs +11 -14
- package/templates/contracts/ts/package.json +1 -1
- package/templates/frontend/next-app/next.config.js +1 -0
- package/templates/frontend/next-app/package.json +23 -23
- package/templates/frontend/next-app/src/app/hello-near/page.js +7 -9
- package/templates/frontend/next-app/src/app/layout.js +34 -9
- package/templates/frontend/next-app/src/components/navigation.js +7 -9
- package/templates/frontend/next-app/src/config.js +1 -18
- package/templates/frontend/next-app/src/wallets/web3modal.js +30 -39
- package/templates/frontend/next-page/next.config.js +1 -0
- package/templates/frontend/next-page/package.json +23 -23
- package/templates/frontend/next-page/src/components/navigation.js +7 -9
- package/templates/frontend/next-page/src/config.js +1 -18
- package/templates/frontend/next-page/src/pages/_app.js +34 -11
- package/templates/frontend/next-page/src/pages/hello-near/index.js +7 -9
- package/templates/frontend/next-page/src/wallets/web3modal.js +30 -39
- package/templates/frontend/vite-react/eslint.config.js +38 -0
- package/templates/frontend/vite-react/index.html +13 -0
- package/templates/frontend/vite-react/package.json +49 -0
- package/templates/frontend/vite-react/public/favicon.ico +0 -0
- package/templates/frontend/vite-react/src/App.jsx +56 -0
- package/templates/frontend/vite-react/src/assets/near-logo.svg +43 -0
- package/templates/frontend/vite-react/src/assets/near.svg +1 -0
- package/templates/frontend/vite-react/src/assets/react.svg +1 -0
- package/templates/frontend/vite-react/src/components/cards.jsx +27 -0
- package/templates/frontend/vite-react/src/components/navigation.jsx +37 -0
- package/templates/frontend/vite-react/src/config.js +7 -0
- package/templates/frontend/vite-react/src/main.jsx +11 -0
- package/templates/frontend/vite-react/src/pages/hello_near.jsx +73 -0
- package/templates/frontend/vite-react/src/pages/home.jsx +31 -0
- package/templates/frontend/vite-react/src/styles/app.module.css +226 -0
- package/templates/frontend/vite-react/src/styles/globals.css +88 -0
- package/templates/frontend/vite-react/src/wallets/web3modal.js +35 -0
- package/templates/frontend/vite-react/vite.config.js +14 -0
- package/dist/package-json.js +0 -130
- package/templates/frontend/next-app/src/wallets/near.js +0 -216
- package/templates/frontend/next-page/src/wallets/near.js +0 -216
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
.main {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
align-items: center;
|
|
6
|
+
padding: 6rem;
|
|
7
|
+
min-height: 100vh;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.description {
|
|
11
|
+
display: inherit;
|
|
12
|
+
justify-content: inherit;
|
|
13
|
+
align-items: inherit;
|
|
14
|
+
font-size: 0.85rem;
|
|
15
|
+
max-width: var(--max-width);
|
|
16
|
+
width: 100%;
|
|
17
|
+
z-index: 2;
|
|
18
|
+
font-family: var(--font-mono);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.description a {
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: 0.5rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.description p {
|
|
29
|
+
position: relative;
|
|
30
|
+
margin: 0;
|
|
31
|
+
padding: 1rem;
|
|
32
|
+
background-color: rgba(var(--callout-rgb), 0.5);
|
|
33
|
+
border: 1px solid rgba(var(--callout-border-rgb), 0.3);
|
|
34
|
+
border-radius: var(--border-radius);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.code {
|
|
38
|
+
font-weight: 700;
|
|
39
|
+
font-family: var(--font-mono);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.grid {
|
|
43
|
+
display: grid;
|
|
44
|
+
grid-template-columns: repeat(2, minmax(25%, auto));
|
|
45
|
+
max-width: 100%;
|
|
46
|
+
width: var(--max-width);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.card {
|
|
50
|
+
padding: 1rem 1.2rem;
|
|
51
|
+
border-radius: var(--border-radius);
|
|
52
|
+
background: rgba(var(--card-rgb), 0);
|
|
53
|
+
border: 1px solid rgba(var(--card-border-rgb), 0);
|
|
54
|
+
transition:
|
|
55
|
+
background 200ms,
|
|
56
|
+
border 200ms;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.card span {
|
|
60
|
+
display: inline-block;
|
|
61
|
+
transition: transform 200ms;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.card h2 {
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
margin-bottom: 0.7rem;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.card p {
|
|
70
|
+
margin: 0;
|
|
71
|
+
opacity: 0.6;
|
|
72
|
+
font-size: 0.9rem;
|
|
73
|
+
line-height: 1.5;
|
|
74
|
+
max-width: 30ch;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.center {
|
|
78
|
+
display: flex;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
align-items: center;
|
|
81
|
+
position: relative;
|
|
82
|
+
padding: 4rem 0;
|
|
83
|
+
width: 100%;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.center::before {
|
|
87
|
+
background: var(--secondary-glow);
|
|
88
|
+
border-radius: 50%;
|
|
89
|
+
width: 480px;
|
|
90
|
+
height: 360px;
|
|
91
|
+
margin-left: -400px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.center::after {
|
|
95
|
+
background: var(--primary-glow);
|
|
96
|
+
width: 240px;
|
|
97
|
+
height: 180px;
|
|
98
|
+
z-index: -1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.center::before,
|
|
102
|
+
.center::after {
|
|
103
|
+
content: '';
|
|
104
|
+
left: 50%;
|
|
105
|
+
position: absolute;
|
|
106
|
+
filter: blur(45px);
|
|
107
|
+
transform: translateZ(0);
|
|
108
|
+
opacity: 0.3;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.logo {
|
|
112
|
+
position: relative;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Enable hover only on non-touch devices */
|
|
116
|
+
@media (hover: hover) and (pointer: fine) {
|
|
117
|
+
.card:hover {
|
|
118
|
+
background: rgba(var(--card-rgb), 0.1);
|
|
119
|
+
border: 1px solid rgba(var(--card-border-rgb), 0.15);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.card:hover span {
|
|
123
|
+
transform: translateX(4px);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@media (prefers-reduced-motion) {
|
|
128
|
+
.card:hover span {
|
|
129
|
+
transform: none;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* Mobile */
|
|
134
|
+
@media (max-width: 700px) {
|
|
135
|
+
.content {
|
|
136
|
+
padding: 4rem;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.grid {
|
|
140
|
+
grid-template-columns: 1fr;
|
|
141
|
+
margin-bottom: 120px;
|
|
142
|
+
max-width: 320px;
|
|
143
|
+
text-align: center;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.card {
|
|
147
|
+
padding: 1rem 2.5rem;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.card h2 {
|
|
151
|
+
margin-bottom: 0.5rem;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.center {
|
|
155
|
+
padding: 8rem 0 6rem;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.center::before {
|
|
159
|
+
transform: none;
|
|
160
|
+
height: 300px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.description {
|
|
164
|
+
font-size: 0.8rem;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.description a {
|
|
168
|
+
padding: 1rem;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.description p,
|
|
172
|
+
.description div {
|
|
173
|
+
display: flex;
|
|
174
|
+
justify-content: center;
|
|
175
|
+
width: 100%;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.description p {
|
|
179
|
+
align-items: center;
|
|
180
|
+
inset: 0 0 auto;
|
|
181
|
+
padding: 2rem 1rem 1.4rem;
|
|
182
|
+
border-radius: 0;
|
|
183
|
+
border: none;
|
|
184
|
+
border-bottom: 1px solid rgba(var(--callout-border-rgb), 0.25);
|
|
185
|
+
background: linear-gradient(to bottom, rgba(var(--background-start-rgb), 1), rgba(var(--callout-rgb), 0.5));
|
|
186
|
+
background-clip: padding-box;
|
|
187
|
+
backdrop-filter: blur(24px);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.description div {
|
|
191
|
+
align-items: flex-end;
|
|
192
|
+
pointer-events: none;
|
|
193
|
+
inset: auto 0 0;
|
|
194
|
+
padding: 2rem;
|
|
195
|
+
height: 200px;
|
|
196
|
+
background: linear-gradient(to bottom, transparent 0%, rgb(var(--background-end-rgb)) 40%);
|
|
197
|
+
z-index: 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* Tablet and Smaller Desktop */
|
|
202
|
+
@media (min-width: 701px) and (max-width: 1120px) {
|
|
203
|
+
.grid {
|
|
204
|
+
grid-template-columns: repeat(2, 50%);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@media (prefers-color-scheme: dark) {
|
|
209
|
+
.reactLogo {
|
|
210
|
+
filter: drop-shadow(0 0 0.3rem #ffffff70);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.logo {
|
|
214
|
+
filter: invert(1) drop-shadow(0 0 0.3rem #ffffff70);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@keyframes rotate {
|
|
219
|
+
from {
|
|
220
|
+
transform: rotate(360deg);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
to {
|
|
224
|
+
transform: rotate(0deg);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@import 'bootstrap';
|
|
2
|
+
@import 'bootstrap-icons';
|
|
3
|
+
|
|
4
|
+
:root {
|
|
5
|
+
--max-width: 1100px;
|
|
6
|
+
--border-radius: 12px;
|
|
7
|
+
|
|
8
|
+
--foreground-rgb: 0, 0, 0;
|
|
9
|
+
--background-start-rgb: 214, 219, 220;
|
|
10
|
+
--background-end-rgb: 255, 255, 255;
|
|
11
|
+
|
|
12
|
+
--primary-glow: conic-gradient(
|
|
13
|
+
from 180deg at 50% 50%,
|
|
14
|
+
#16abff33 0deg,
|
|
15
|
+
#0885ff33 55deg,
|
|
16
|
+
#54d6ff33 120deg,
|
|
17
|
+
#0071ff33 160deg,
|
|
18
|
+
transparent 360deg
|
|
19
|
+
);
|
|
20
|
+
--secondary-glow: radial-gradient(rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
|
|
21
|
+
|
|
22
|
+
--tile-start-rgb: 239, 245, 249;
|
|
23
|
+
--tile-end-rgb: 228, 232, 233;
|
|
24
|
+
--tile-border: conic-gradient(#00000080, #00000040, #00000030, #00000020, #00000010, #00000010, #00000080);
|
|
25
|
+
|
|
26
|
+
--callout-rgb: 238, 240, 241;
|
|
27
|
+
--callout-border-rgb: 172, 175, 176;
|
|
28
|
+
--card-rgb: 180, 185, 188;
|
|
29
|
+
--card-border-rgb: 131, 134, 135;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@media (prefers-color-scheme: dark) {
|
|
33
|
+
:root {
|
|
34
|
+
--foreground-rgb: 255, 255, 255;
|
|
35
|
+
--background-start-rgb: 0, 0, 0;
|
|
36
|
+
--background-end-rgb: 0, 0, 0;
|
|
37
|
+
|
|
38
|
+
--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
|
|
39
|
+
--secondary-glow: linear-gradient(to bottom right, rgba(1, 65, 255, 0), rgba(1, 65, 255, 0), rgba(1, 65, 255, 0.3));
|
|
40
|
+
|
|
41
|
+
--tile-start-rgb: 2, 13, 46;
|
|
42
|
+
--tile-end-rgb: 2, 5, 19;
|
|
43
|
+
--tile-border: conic-gradient(#ffffff80, #ffffff40, #ffffff30, #ffffff20, #ffffff10, #ffffff10, #ffffff80);
|
|
44
|
+
|
|
45
|
+
--callout-rgb: 20, 20, 20;
|
|
46
|
+
--callout-border-rgb: 108, 108, 108;
|
|
47
|
+
--card-rgb: 100, 100, 100;
|
|
48
|
+
--card-border-rgb: 200, 200, 200;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
* {
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
padding: 0;
|
|
55
|
+
margin: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
html,
|
|
59
|
+
body {
|
|
60
|
+
max-width: 100vw;
|
|
61
|
+
overflow-x: hidden;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
body {
|
|
65
|
+
color: rgb(var(--foreground-rgb));
|
|
66
|
+
background: linear-gradient(to bottom, transparent, rgb(var(--background-end-rgb))) rgb(var(--background-start-rgb));
|
|
67
|
+
font-family:
|
|
68
|
+
-apple-system,
|
|
69
|
+
BlinkMacSystemFont,
|
|
70
|
+
Segoe UI,
|
|
71
|
+
Roboto,
|
|
72
|
+
Noto Sans,
|
|
73
|
+
Ubuntu,
|
|
74
|
+
Droid Sans,
|
|
75
|
+
Helvetica Neue,
|
|
76
|
+
sans-serif;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
a {
|
|
80
|
+
color: inherit;
|
|
81
|
+
text-decoration: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media (prefers-color-scheme: dark) {
|
|
85
|
+
html {
|
|
86
|
+
color-scheme: dark;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
6
|
+
// Get a project ID at https://cloud.reown.com
|
|
7
|
+
const projectId = "30147604c5f01d0bc4482ab0665b5697";
|
|
8
|
+
|
|
9
|
+
export const wagmiAdapter = new WagmiAdapter({
|
|
10
|
+
projectId,
|
|
11
|
+
networks: [nearTestnet],
|
|
12
|
+
});
|
|
13
|
+
|
|
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
|
+
});
|
|
29
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
|
|
4
|
+
|
|
5
|
+
// https://vite.dev/config/
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [nodePolyfills(), react()],
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
'@': '/src',
|
|
11
|
+
buffer: 'buffer',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
})
|
package/dist/package-json.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPackagetson = void 0;
|
|
4
|
-
function buildPackagetson({ contract, frontend, tests, projectName }) {
|
|
5
|
-
const result = basePackage({
|
|
6
|
-
contract, frontend, tests, projectName,
|
|
7
|
-
});
|
|
8
|
-
return result;
|
|
9
|
-
}
|
|
10
|
-
exports.buildPackagetson = buildPackagetson;
|
|
11
|
-
function basePackage({ contract, frontend, tests, projectName }) {
|
|
12
|
-
const hasFrontend = frontend !== 'none';
|
|
13
|
-
return {
|
|
14
|
-
'name': projectName,
|
|
15
|
-
'version': '1.0.0',
|
|
16
|
-
'license': '(MIT AND Apache-2.0)',
|
|
17
|
-
'scripts': {
|
|
18
|
-
...startScript(hasFrontend),
|
|
19
|
-
...deployScript(contract),
|
|
20
|
-
...buildScript(hasFrontend),
|
|
21
|
-
...buildContractScript(contract),
|
|
22
|
-
'test': 'npm run test:unit && npm run test:integration',
|
|
23
|
-
...unitTestScripts(contract),
|
|
24
|
-
...integrationTestScripts(contract, tests),
|
|
25
|
-
...npmInstallScript(contract, hasFrontend, tests),
|
|
26
|
-
},
|
|
27
|
-
'devDependencies': {
|
|
28
|
-
'near-cli': '^3.3.0',
|
|
29
|
-
},
|
|
30
|
-
'dependencies': {}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const startScript = (hasFrontend) => hasFrontend ? {
|
|
34
|
-
'start': 'cd frontend && npm run dev'
|
|
35
|
-
} : {};
|
|
36
|
-
const buildScript = (hasFrontend) => hasFrontend ? {
|
|
37
|
-
'build': 'npm run build:contract && npm run build:web',
|
|
38
|
-
'build:web': 'cd frontend && npm run build',
|
|
39
|
-
} : {
|
|
40
|
-
'build': 'npm run build:contract',
|
|
41
|
-
};
|
|
42
|
-
const buildContractScriptName = 'build:contract';
|
|
43
|
-
const buildContractScript = (contract) => {
|
|
44
|
-
switch (contract) {
|
|
45
|
-
case 'ts':
|
|
46
|
-
return {
|
|
47
|
-
[buildContractScriptName]: 'cd contract && npm run build',
|
|
48
|
-
};
|
|
49
|
-
case 'rs':
|
|
50
|
-
return {
|
|
51
|
-
[buildContractScriptName]: 'cd contract && ./build.sh',
|
|
52
|
-
};
|
|
53
|
-
case 'none':
|
|
54
|
-
return {
|
|
55
|
-
[buildContractScriptName]: 'echo "No contract to build"',
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const deployScript = (contract) => {
|
|
60
|
-
switch (contract) {
|
|
61
|
-
case 'ts':
|
|
62
|
-
return {
|
|
63
|
-
'deploy': 'cd contract && npm run deploy',
|
|
64
|
-
};
|
|
65
|
-
case 'rs':
|
|
66
|
-
return {
|
|
67
|
-
'deploy': 'cd contract && ./deploy.sh',
|
|
68
|
-
};
|
|
69
|
-
case 'none':
|
|
70
|
-
return {
|
|
71
|
-
'deploy': 'echo "No contract to deploy"',
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const unitTestScripts = (contract) => {
|
|
76
|
-
switch (contract) {
|
|
77
|
-
case 'ts':
|
|
78
|
-
return { 'test:unit': 'cd contract && npm test' };
|
|
79
|
-
case 'rs':
|
|
80
|
-
return { 'test:unit': 'cd contract && cargo test' };
|
|
81
|
-
case 'none':
|
|
82
|
-
return { 'test:unit': 'echo "No contract to test"' };
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const integrationTestScripts = (contract, tests) => {
|
|
86
|
-
if (contract === 'none') {
|
|
87
|
-
return { 'test:integration': 'echo "No contract to test"' };
|
|
88
|
-
}
|
|
89
|
-
let wasm_path = '';
|
|
90
|
-
switch (contract) {
|
|
91
|
-
case 'ts':
|
|
92
|
-
wasm_path = 'contract/build/hello_near.wasm';
|
|
93
|
-
break;
|
|
94
|
-
case 'rs':
|
|
95
|
-
wasm_path = 'contract/target/wasm32-unknown-unknown/release/hello_near.wasm';
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
let run_test = '';
|
|
99
|
-
switch (tests) {
|
|
100
|
-
case 'ts':
|
|
101
|
-
run_test = `npm test -- -- "./${wasm_path}"`;
|
|
102
|
-
break;
|
|
103
|
-
case 'rs':
|
|
104
|
-
run_test = `cargo run --example integration-tests "../${wasm_path}"`;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
'test:integration': `npm run ${buildContractScriptName} && cd integration-tests && ${run_test}`,
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
const npmInstallScript = (contract, hasFrontend, tests) => {
|
|
112
|
-
const frontend_install = hasFrontend ? 'cd frontend && npm install && cd ..' : 'echo no frontend';
|
|
113
|
-
const test_install = (contract !== 'none' && tests === 'ts') ? 'cd integration-tests && npm install && cd ..' : 'echo no ts test';
|
|
114
|
-
let contract_install = '';
|
|
115
|
-
switch (contract) {
|
|
116
|
-
case 'ts':
|
|
117
|
-
contract_install = 'cd contract && npm install';
|
|
118
|
-
break;
|
|
119
|
-
case 'rs':
|
|
120
|
-
contract_install = 'echo rs contract';
|
|
121
|
-
break;
|
|
122
|
-
case 'none':
|
|
123
|
-
contract_install = 'echo no contract';
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
'postinstall': `${frontend_install} && ${test_install} && ${contract_install}`
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
//# sourceMappingURL=package-json.js.map
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
// near api js
|
|
4
|
-
import { providers, utils } from 'near-api-js';
|
|
5
|
-
|
|
6
|
-
// wallet selector
|
|
7
|
-
import '@near-wallet-selector/modal-ui/styles.css';
|
|
8
|
-
import { setupModal } from '@near-wallet-selector/modal-ui';
|
|
9
|
-
import { setupWalletSelector } from '@near-wallet-selector/core';
|
|
10
|
-
import { setupHereWallet } from '@near-wallet-selector/here-wallet';
|
|
11
|
-
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
|
|
12
|
-
import { setupLedger } from '@near-wallet-selector/ledger';
|
|
13
|
-
import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
|
|
14
|
-
import { setupSender } from '@near-wallet-selector/sender';
|
|
15
|
-
import { setupBitteWallet } from '@near-wallet-selector/bitte-wallet';
|
|
16
|
-
|
|
17
|
-
// ethereum wallets
|
|
18
|
-
import { wagmiConfig, web3Modal } from '@/wallets/web3modal';
|
|
19
|
-
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
|
|
20
|
-
|
|
21
|
-
const THIRTY_TGAS = '30000000000000';
|
|
22
|
-
const NO_DEPOSIT = '0';
|
|
23
|
-
|
|
24
|
-
export class Wallet {
|
|
25
|
-
/**
|
|
26
|
-
* @constructor
|
|
27
|
-
* @param {Object} options - the options for the wallet
|
|
28
|
-
* @param {string} options.networkId - the network id to connect to
|
|
29
|
-
* @param {string} options.createAccessKeyFor - the contract to create an access key for
|
|
30
|
-
* @example
|
|
31
|
-
* const wallet = new Wallet({ networkId: 'testnet', createAccessKeyFor: 'contractId' });
|
|
32
|
-
* wallet.startUp((signedAccountId) => console.log(signedAccountId));
|
|
33
|
-
*/
|
|
34
|
-
constructor({ networkId = 'testnet', createAccessKeyFor = undefined }) {
|
|
35
|
-
this.createAccessKeyFor = createAccessKeyFor;
|
|
36
|
-
this.networkId = networkId;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* To be called when the website loads
|
|
41
|
-
* @param {Function} accountChangeHook - a function that is called when the user signs in or out#
|
|
42
|
-
* @returns {Promise<string>} - the accountId of the signed-in user
|
|
43
|
-
*/
|
|
44
|
-
startUp = async (accountChangeHook) => {
|
|
45
|
-
this.selector = setupWalletSelector({
|
|
46
|
-
network: this.networkId,
|
|
47
|
-
modules: [
|
|
48
|
-
setupMyNearWallet(),
|
|
49
|
-
setupHereWallet(),
|
|
50
|
-
setupLedger(),
|
|
51
|
-
setupMeteorWallet(),
|
|
52
|
-
setupSender(),
|
|
53
|
-
setupBitteWallet(),
|
|
54
|
-
setupEthereumWallets({ wagmiConfig, web3Modal, alwaysOnboardDuringSignIn: true }),
|
|
55
|
-
],
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const walletSelector = await this.selector;
|
|
59
|
-
const isSignedIn = walletSelector.isSignedIn();
|
|
60
|
-
const accountId = isSignedIn ? walletSelector.store.getState().accounts[0].accountId : '';
|
|
61
|
-
|
|
62
|
-
walletSelector.store.observable.subscribe(async (state) => {
|
|
63
|
-
const signedAccount = state?.accounts.find(account => account.active)?.accountId;
|
|
64
|
-
accountChangeHook(signedAccount || '');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return accountId;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Displays a modal to login the user
|
|
72
|
-
*/
|
|
73
|
-
signIn = async () => {
|
|
74
|
-
const modal = setupModal(await this.selector, { contractId: this.createAccessKeyFor });
|
|
75
|
-
modal.show();
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Logout the user
|
|
80
|
-
*/
|
|
81
|
-
signOut = async () => {
|
|
82
|
-
const selectedWallet = await (await this.selector).wallet();
|
|
83
|
-
selectedWallet.signOut();
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Makes a read-only call to a contract
|
|
88
|
-
* @param {Object} options - the options for the call
|
|
89
|
-
* @param {string} options.contractId - the contract's account id
|
|
90
|
-
* @param {string} options.method - the method to call
|
|
91
|
-
* @param {Object} options.args - the arguments to pass to the method
|
|
92
|
-
* @returns {Promise<JSON.value>} - the result of the method call
|
|
93
|
-
*/
|
|
94
|
-
viewMethod = async ({ contractId, method, args = {} }) => {
|
|
95
|
-
const url = `https://rpc.${this.networkId}.near.org`;
|
|
96
|
-
const provider = new providers.JsonRpcProvider({ url });
|
|
97
|
-
|
|
98
|
-
const res = await provider.query({
|
|
99
|
-
request_type: 'call_function',
|
|
100
|
-
account_id: contractId,
|
|
101
|
-
method_name: method,
|
|
102
|
-
args_base64: Buffer.from(JSON.stringify(args)).toString('base64'),
|
|
103
|
-
finality: 'optimistic',
|
|
104
|
-
});
|
|
105
|
-
return JSON.parse(Buffer.from(res.result).toString());
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Makes a call to a contract
|
|
110
|
-
* @param {Object} options - the options for the call
|
|
111
|
-
* @param {string} options.contractId - the contract's account id
|
|
112
|
-
* @param {string} options.method - the method to call
|
|
113
|
-
* @param {Object} options.args - the arguments to pass to the method
|
|
114
|
-
* @param {string} options.gas - the amount of gas to use
|
|
115
|
-
* @param {string} options.deposit - the amount of yoctoNEAR to deposit
|
|
116
|
-
* @returns {Promise<Transaction>} - the resulting transaction
|
|
117
|
-
*/
|
|
118
|
-
callMethod = async ({ contractId, method, args = {}, gas = THIRTY_TGAS, deposit = NO_DEPOSIT }) => {
|
|
119
|
-
// Sign a transaction with the "FunctionCall" action
|
|
120
|
-
const selectedWallet = await (await this.selector).wallet();
|
|
121
|
-
const outcome = await selectedWallet.signAndSendTransaction({
|
|
122
|
-
receiverId: contractId,
|
|
123
|
-
actions: [
|
|
124
|
-
{
|
|
125
|
-
type: 'FunctionCall',
|
|
126
|
-
params: {
|
|
127
|
-
methodName: method,
|
|
128
|
-
args,
|
|
129
|
-
gas,
|
|
130
|
-
deposit,
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
return providers.getTransactionLastResult(outcome);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Makes a call to a contract
|
|
141
|
-
* @param {string} txhash - the transaction hash
|
|
142
|
-
* @returns {Promise<JSON.value>} - the result of the transaction
|
|
143
|
-
*/
|
|
144
|
-
getTransactionResult = async (txhash) => {
|
|
145
|
-
const walletSelector = await this.selector;
|
|
146
|
-
const { network } = walletSelector.options;
|
|
147
|
-
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
148
|
-
|
|
149
|
-
// Retrieve transaction result from the network
|
|
150
|
-
const transaction = await provider.txStatus(txhash, 'unnused');
|
|
151
|
-
return providers.getTransactionLastResult(transaction);
|
|
152
|
-
};
|
|
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
|
-
*/
|
|
160
|
-
getBalance = async (accountId) => {
|
|
161
|
-
const walletSelector = await this.selector;
|
|
162
|
-
const { network } = walletSelector.options;
|
|
163
|
-
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
164
|
-
|
|
165
|
-
// Retrieve account state from the network
|
|
166
|
-
const account = await provider.query({
|
|
167
|
-
request_type: 'view_account',
|
|
168
|
-
account_id: accountId,
|
|
169
|
-
finality: 'final',
|
|
170
|
-
});
|
|
171
|
-
// return amount on NEAR
|
|
172
|
-
return account.amount ? Number(utils.format.formatNearAmount(account.amount)) : 0;
|
|
173
|
-
};
|
|
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
|
-
*/
|
|
181
|
-
signAndSendTransactions = async ({ transactions }) => {
|
|
182
|
-
const selectedWallet = await (await this.selector).wallet();
|
|
183
|
-
return selectedWallet.signAndSendTransactions({ transactions });
|
|
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
|
-
};
|
|
204
|
-
}
|
|
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>} */
|
|
213
|
-
export const NearContext = createContext({
|
|
214
|
-
wallet: undefined,
|
|
215
|
-
signedAccountId: '',
|
|
216
|
-
});
|