create-near-app 1.3.6 → 3.0.0-pre.7.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 (146) hide show
  1. package/README.md +3 -3
  2. package/{common/contracts → contracts}/assemblyscript/README.md +2 -3
  3. package/{common/contracts → contracts}/assemblyscript/as-pect.config.js +0 -0
  4. package/{common/contracts → contracts}/assemblyscript/asconfig.json +0 -0
  5. package/{common/contracts → contracts}/assemblyscript/assembly/__tests__/as-pect.d.ts +0 -0
  6. package/contracts/assemblyscript/assembly/__tests__/main.spec.ts +11 -0
  7. package/{common/contracts → contracts}/assemblyscript/assembly/as_types.d.ts +0 -0
  8. package/contracts/assemblyscript/assembly/index.ts +23 -0
  9. package/{common/contracts → contracts}/assemblyscript/assembly/tsconfig.json +0 -0
  10. package/{common/contracts → contracts}/assemblyscript/package.json +2 -6
  11. package/{common/contracts → contracts}/rust/.cargo/config +0 -0
  12. package/{common/contracts → contracts}/rust/Cargo.toml +4 -5
  13. package/{common/contracts → contracts}/rust/README.md +2 -3
  14. package/contracts/rust/src/lib.rs +72 -0
  15. package/index.js +74 -77
  16. package/integration-tests/rs/Cargo.toml +22 -0
  17. package/integration-tests/rs/src/tests.rs +66 -0
  18. package/integration-tests/ts/ava.config.cjs +9 -0
  19. package/integration-tests/ts/package.json +16 -0
  20. package/integration-tests/ts/src/main.ava.ts +44 -0
  21. package/package.json +24 -23
  22. package/templates/react/README.md +2 -2
  23. package/templates/react/ava.config.cjs +9 -0
  24. package/templates/react/{src → frontend}/App.js +35 -30
  25. package/templates/react/{src → frontend}/__mocks__/fileMock.js +0 -0
  26. package/{common/frontend → templates/react/frontend/assets/css}/global.css +4 -3
  27. package/{common/frontend/assets → templates/react/frontend/assets/img}/favicon.ico +0 -0
  28. package/{common/frontend/assets → templates/react/frontend/assets/img}/logo-black.svg +0 -0
  29. package/{common/frontend/assets → templates/react/frontend/assets/img}/logo-white.svg +0 -0
  30. package/templates/react/{src → frontend/assets/js/near}/config.js +1 -1
  31. package/templates/{vue/src → react/frontend/assets/js/near}/utils.js +14 -4
  32. package/templates/react/{src → frontend}/index.html +3 -3
  33. package/templates/react/frontend/index.js +14 -0
  34. package/templates/react/near.gitignore +6 -3
  35. package/templates/react/package.json +29 -43
  36. package/templates/vanilla/README.md +2 -2
  37. package/templates/vanilla/frontend/assets/css/global.css +189 -0
  38. package/templates/vanilla/frontend/assets/img/favicon.ico +0 -0
  39. package/templates/vanilla/frontend/assets/img/logo-black.svg +1 -0
  40. package/templates/vanilla/frontend/assets/img/logo-white.svg +1 -0
  41. package/templates/vanilla/frontend/assets/js/index.js +74 -0
  42. package/templates/vanilla/{src → frontend/assets/js/near}/config.js +1 -1
  43. package/templates/{angular/src → vanilla/frontend/assets/js/near}/utils.js +14 -4
  44. package/templates/vanilla/{src → frontend}/index.html +25 -30
  45. package/templates/vanilla/near.gitignore +1 -1
  46. package/templates/vanilla/package.json +25 -31
  47. package/utils/rust-setup.js +102 -0
  48. package/utils/tracking.js +29 -0
  49. package/LICENSE-APACHE +0 -176
  50. package/common/.npmignore +0 -2
  51. package/common/contracts/.gitignore +0 -1
  52. package/common/contracts/assemblyscript/.gitignore +0 -4
  53. package/common/contracts/assemblyscript/assembly/__tests__/main.spec.ts +0 -9
  54. package/common/contracts/assemblyscript/assembly/index.ts +0 -40
  55. package/common/contracts/assemblyscript/compile.js +0 -51
  56. package/common/contracts/rust/.gitignore +0 -1
  57. package/common/contracts/rust/Cargo.lock +0 -472
  58. package/common/contracts/rust/compile.js +0 -55
  59. package/common/contracts/rust/res/.gitkeep +0 -0
  60. package/common/contracts/rust/src/lib.rs +0 -115
  61. package/common/contracts/rust/target/.gitkeep +0 -0
  62. package/templates/.npmignore +0 -3
  63. package/templates/angular/.gitignore +0 -26
  64. package/templates/angular/.gitpod.yml +0 -6
  65. package/templates/angular/README.md +0 -102
  66. package/templates/angular/angular.json +0 -126
  67. package/templates/angular/contract +0 -1
  68. package/templates/angular/extra-webpack.config.ts +0 -7
  69. package/templates/angular/karma.conf.js +0 -40
  70. package/templates/angular/near.gitignore +0 -46
  71. package/templates/angular/neardev/.gitignore +0 -2
  72. package/templates/angular/neardev/shared-test/test.near.json +0 -1
  73. package/templates/angular/neardev/shared-test-staging/test.near.json +0 -1
  74. package/templates/angular/package.json +0 -63
  75. package/templates/angular/set-contract-name.js +0 -16
  76. package/templates/angular/src/app/app.component.html +0 -87
  77. package/templates/angular/src/app/app.component.spec.ts +0 -107
  78. package/templates/angular/src/app/app.component.ts +0 -88
  79. package/templates/angular/src/app/app.module.ts +0 -21
  80. package/templates/angular/src/app/components/notification/notification.component.html +0 -12
  81. package/templates/angular/src/app/components/notification/notification.component.spec.ts +0 -25
  82. package/templates/angular/src/app/components/notification/notification.component.ts +0 -23
  83. package/templates/angular/src/app/services/window.service.ts +0 -47
  84. package/templates/angular/src/assets +0 -1
  85. package/templates/angular/src/config.d.ts +0 -13
  86. package/templates/angular/src/config.js +0 -62
  87. package/templates/angular/src/contract-name.js +0 -1
  88. package/templates/angular/src/environments/environment.prod.ts +0 -3
  89. package/templates/angular/src/environments/environment.ts +0 -16
  90. package/templates/angular/src/global.css +0 -1
  91. package/templates/angular/src/index.html +0 -15
  92. package/templates/angular/src/main.ts +0 -15
  93. package/templates/angular/src/polyfills.ts +0 -64
  94. package/templates/angular/src/styles.scss +0 -1
  95. package/templates/angular/src/test.ts +0 -25
  96. package/templates/angular/src/utils.d.ts +0 -3
  97. package/templates/angular/src/window.d.ts +0 -15
  98. package/templates/angular/tsconfig.app.json +0 -15
  99. package/templates/angular/tsconfig.json +0 -21
  100. package/templates/angular/tsconfig.spec.json +0 -18
  101. package/templates/angular/tslint.json +0 -149
  102. package/templates/react/.gitignore +0 -28
  103. package/templates/react/babel.config.js +0 -3
  104. package/templates/react/contract +0 -1
  105. package/templates/react/neardev/.gitignore +0 -2
  106. package/templates/react/neardev/shared-test-staging/test.near.json +0 -1
  107. package/templates/react/src/assets +0 -1
  108. package/templates/react/src/global.css +0 -1
  109. package/templates/react/src/index.js +0 -13
  110. package/templates/react/src/jest.init.js +0 -1
  111. package/templates/react/src/main.test.js +0 -28
  112. package/templates/react/src/utils.js +0 -39
  113. package/templates/react/src/wallet/login/index.html +0 -28
  114. package/templates/vanilla/.gitignore +0 -26
  115. package/templates/vanilla/contract +0 -1
  116. package/templates/vanilla/neardev/.gitignore +0 -2
  117. package/templates/vanilla/neardev/shared-test-staging/test.near.json +0 -1
  118. package/templates/vanilla/src/assets +0 -1
  119. package/templates/vanilla/src/global.css +0 -1
  120. package/templates/vanilla/src/index.js +0 -113
  121. package/templates/vanilla/src/main.test.js +0 -15
  122. package/templates/vanilla/src/utils.js +0 -39
  123. package/templates/vanilla/src/wallet/login/index.html +0 -28
  124. package/templates/vue/.gitignore +0 -26
  125. package/templates/vue/.gitpod.yml +0 -6
  126. package/templates/vue/README.md +0 -101
  127. package/templates/vue/babel.config.js +0 -5
  128. package/templates/vue/contract +0 -1
  129. package/templates/vue/copy-dev-account.js +0 -7
  130. package/templates/vue/jest.config.js +0 -7
  131. package/templates/vue/near.gitignore +0 -46
  132. package/templates/vue/neardev/shared-test/test.near.json +0 -1
  133. package/templates/vue/neardev/shared-test-staging/test.near.json +0 -1
  134. package/templates/vue/package.json +0 -86
  135. package/templates/vue/src/App.vue +0 -37
  136. package/templates/vue/src/assets +0 -1
  137. package/templates/vue/src/components/Notification.vue +0 -38
  138. package/templates/vue/src/components/SignedIn.vue +0 -179
  139. package/templates/vue/src/components/SignedOut.vue +0 -34
  140. package/templates/vue/src/config.js +0 -63
  141. package/templates/vue/src/favicon.ico +0 -1
  142. package/templates/vue/src/global.css +0 -1
  143. package/templates/vue/src/main.js +0 -16
  144. package/templates/vue/tests/unit/Notification.spec.js +0 -26
  145. package/templates/vue/tests/unit/SignedIn.spec.js +0 -24
  146. package/templates/vue/tests/unit/SignedOut.spec.js +0 -17
@@ -1,149 +0,0 @@
1
- {
2
- "extends": "tslint:recommended",
3
- "rules": {
4
- "align": {
5
- "options": [
6
- "parameters",
7
- "statements"
8
- ]
9
- },
10
- "array-type": false,
11
- "arrow-return-shorthand": true,
12
- "curly": true,
13
- "deprecation": {
14
- "severity": "warning"
15
- },
16
- "component-class-suffix": true,
17
- "contextual-lifecycle": true,
18
- "directive-class-suffix": true,
19
- "directive-selector": [
20
- true,
21
- "attribute",
22
- "app",
23
- "camelCase"
24
- ],
25
- "component-selector": [
26
- true,
27
- "element",
28
- "app",
29
- "kebab-case"
30
- ],
31
- "eofline": true,
32
- "import-blacklist": [
33
- true,
34
- "rxjs/Rx"
35
- ],
36
- "import-spacing": true,
37
- "indent": {
38
- "options": [
39
- "spaces",
40
- 2
41
- ]
42
- },
43
- "max-classes-per-file": false,
44
- "max-line-length": [
45
- true,
46
- 140
47
- ],
48
- "member-ordering": [
49
- true,
50
- {
51
- "order": [
52
- "static-field",
53
- "instance-field",
54
- "static-method",
55
- "instance-method"
56
- ]
57
- }
58
- ],
59
- "no-console": false,
60
- "no-empty": false,
61
- "no-inferrable-types": [
62
- true,
63
- "ignore-params"
64
- ],
65
- "no-non-null-assertion": true,
66
- "no-redundant-jsdoc": true,
67
- "no-switch-case-fall-through": true,
68
- "no-var-requires": false,
69
- "object-literal-key-quotes": [
70
- true,
71
- "as-needed"
72
- ],
73
- "quotemark": [
74
- true,
75
- "single"
76
- ],
77
- "semicolon": {
78
- "options": [
79
- "never"
80
- ]
81
- },
82
- "space-before-function-paren": {
83
- "options": {
84
- "anonymous": "never",
85
- "asyncArrow": "always",
86
- "constructor": "never",
87
- "method": "never",
88
- "named": "never"
89
- }
90
- },
91
- "typedef": [
92
- true,
93
- "call-signature"
94
- ],
95
- "typedef-whitespace": {
96
- "options": [
97
- {
98
- "call-signature": "nospace",
99
- "index-signature": "nospace",
100
- "parameter": "nospace",
101
- "property-declaration": "nospace",
102
- "variable-declaration": "nospace"
103
- },
104
- {
105
- "call-signature": "onespace",
106
- "index-signature": "onespace",
107
- "parameter": "onespace",
108
- "property-declaration": "onespace",
109
- "variable-declaration": "onespace"
110
- }
111
- ]
112
- },
113
- "variable-name": {
114
- "options": [
115
- "ban-keywords",
116
- "check-format",
117
- "allow-pascal-case"
118
- ]
119
- },
120
- "whitespace": {
121
- "options": [
122
- "check-branch",
123
- "check-decl",
124
- "check-operator",
125
- "check-separator",
126
- "check-type",
127
- "check-typecast",
128
- "check-module",
129
- "check-rest-spread",
130
- "check-preblock"
131
- ]
132
- },
133
- "no-conflicting-lifecycle": true,
134
- "no-host-metadata-property": true,
135
- "no-input-rename": true,
136
- "no-inputs-metadata-property": true,
137
- "no-output-native": true,
138
- "no-output-on-prefix": true,
139
- "no-output-rename": true,
140
- "no-outputs-metadata-property": true,
141
- "template-banana-in-box": true,
142
- "template-no-negated-async": true,
143
- "use-lifecycle-interface": true,
144
- "use-pipe-transform-interface": true
145
- },
146
- "rulesDirectory": [
147
- "codelyzer"
148
- ]
149
- }
@@ -1,28 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
-
3
- # dependencies
4
- package-lock.json
5
- /node_modules
6
- /.pnp
7
- .pnp.js
8
-
9
- # build
10
- /out
11
-
12
- # testing
13
- /coverage
14
-
15
- # production
16
- /dist
17
- /.cache
18
-
19
- # misc
20
- .DS_Store
21
- .env.local
22
- .env.development.local
23
- .env.test.local
24
- .env.production.local
25
-
26
- npm-debug.log*
27
- yarn-debug.log*
28
- yarn-error.log*
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: ['@babel/preset-env', '@babel/preset-react'],
3
- }
@@ -1 +0,0 @@
1
- ../../common/contracts/assemblyscript
@@ -1,2 +0,0 @@
1
- **.json
2
- !**/test.near.json
@@ -1 +0,0 @@
1
- {"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"}
@@ -1 +0,0 @@
1
- ../../../common/frontend/assets
@@ -1 +0,0 @@
1
- ../../../common/frontend/global.css
@@ -1,13 +0,0 @@
1
- import React from 'react'
2
- import ReactDOM from 'react-dom'
3
- import App from './App'
4
- import { initContract } from './utils'
5
-
6
- window.nearInitPromise = initContract()
7
- .then(() => {
8
- ReactDOM.render(
9
- <App />,
10
- document.querySelector('#root')
11
- )
12
- })
13
- .catch(console.error)
@@ -1 +0,0 @@
1
- import 'regenerator-runtime/runtime'
@@ -1,28 +0,0 @@
1
- beforeAll(async function () {
2
- // NOTE: nearlib and nearConfig are made available by near-cli/test_environment
3
- const near = await nearlib.connect(nearConfig)
4
- window.accountId = nearConfig.contractName
5
- window.contract = await near.loadContract(nearConfig.contractName, {
6
- viewMethods: ['getGreeting'],
7
- changeMethods: [],
8
- sender: window.accountId
9
- })
10
-
11
- window.walletConnection = {
12
- requestSignIn() {
13
- },
14
- signOut() {
15
- },
16
- isSignedIn() {
17
- return true
18
- },
19
- getAccountId() {
20
- return window.accountId
21
- }
22
- }
23
- })
24
-
25
- test('getGreeting', async () => {
26
- const message = await window.contract.getGreeting({ accountId: window.accountId })
27
- expect(message).toEqual('Hello')
28
- })
@@ -1,39 +0,0 @@
1
- import { connect, Contract, keyStores, WalletConnection } from 'near-api-js'
2
- import getConfig from './config'
3
-
4
- const nearConfig = getConfig(process.env.NODE_ENV || 'development')
5
-
6
- // Initialize contract & set global variables
7
- export async function initContract() {
8
- // Initialize connection to the NEAR testnet
9
- const near = await connect(Object.assign({ deps: { keyStore: new keyStores.BrowserLocalStorageKeyStore() } }, nearConfig))
10
-
11
- // Initializing Wallet based Account. It can work with NEAR testnet wallet that
12
- // is hosted at https://wallet.testnet.near.org
13
- window.walletConnection = new WalletConnection(near)
14
-
15
- // Getting the Account ID. If still unauthorized, it's just empty string
16
- window.accountId = window.walletConnection.getAccountId()
17
-
18
- // Initializing our contract APIs by contract name and configuration
19
- window.contract = await new Contract(window.walletConnection.account(), nearConfig.contractName, {
20
- // View methods are read only. They don't modify the state, but usually return some value.
21
- viewMethods: ['getGreeting'],
22
- // Change methods can modify the state. But you don't receive the returned value when called.
23
- changeMethods: ['setGreeting'],
24
- })
25
- }
26
-
27
- export function logout() {
28
- window.walletConnection.signOut()
29
- // reload page
30
- window.location.replace(window.location.origin + window.location.pathname)
31
- }
32
-
33
- export function login() {
34
- // Allow the current app to make calls to the specified contract on the
35
- // user's behalf.
36
- // This works by creating a new access key for the user's account and storing
37
- // the private key in localStorage.
38
- window.walletConnection.requestSignIn(nearConfig.contractName)
39
- }
@@ -1,28 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
6
- </head>
7
- <body style="background: #fff; margin-top: 3em">
8
- <div>For local account login, Please run the following command in NEAR CLI, then enter account id here.
9
- </div>
10
- <div>
11
- <code id="shell-command"></code>
12
- </div>
13
- <input type="text" id="accountId" name="accountId" placeholder="Account id"></input>
14
- <button type="button" onClick="done()">done</button>
15
- <script>
16
- const currentUrl = new URL(window.location.href);
17
- const message = `NODE_ENV=local near create_account {newAccountId} --masterAccount {masterAccountId} --publicKey ${currentUrl.searchParams.get('public_key')} --initialAmount 10000000000000000000`;
18
- document.getElementById('shell-command').innerText = message;
19
-
20
- function done() {
21
- const successUrl = new URL(currentUrl.searchParams.get('success_url'));
22
- successUrl.searchParams.set('account_id', document.getElementById('accountId').value);
23
- successUrl.searchParams.set('public_key', currentUrl.searchParams.get('public_key'));
24
- window.location.assign(successUrl.toString());
25
- }
26
- </script>
27
- </body>
28
- </html>
@@ -1,26 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
-
3
- # dependencies
4
- package-lock.json
5
- /node_modules
6
- /.pnp
7
- .pnp.js
8
- /out
9
-
10
- # testing
11
- /coverage
12
-
13
- # production
14
- /.cache
15
- /dist
16
-
17
- # misc
18
- .DS_Store
19
- .env.local
20
- .env.development.local
21
- .env.test.local
22
- .env.production.local
23
-
24
- npm-debug.log*
25
- yarn-debug.log*
26
- yarn-error.log*
@@ -1 +0,0 @@
1
- ../../common/contracts/assemblyscript
@@ -1,2 +0,0 @@
1
- **.json
2
- !**/test.near.json
@@ -1 +0,0 @@
1
- {"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"}
@@ -1 +0,0 @@
1
- ../../../common/frontend/assets
@@ -1 +0,0 @@
1
- ../../../common/frontend/global.css
@@ -1,113 +0,0 @@
1
- import 'regenerator-runtime/runtime'
2
-
3
- import { initContract, login, logout } from './utils'
4
-
5
- import getConfig from './config'
6
- const { networkId } = getConfig(process.env.NODE_ENV || 'development')
7
-
8
- // global variable used throughout
9
- let currentGreeting
10
-
11
- const submitButton = document.querySelector('form button')
12
-
13
- document.querySelector('form').onsubmit = async (event) => {
14
- event.preventDefault()
15
-
16
- // get elements from the form using their id attribute
17
- const { fieldset, greeting } = event.target.elements
18
-
19
- // disable the form while the value gets updated on-chain
20
- fieldset.disabled = true
21
-
22
- try {
23
- // make an update call to the smart contract
24
- await window.contract.setGreeting({
25
- // pass the value that the user entered in the greeting field
26
- message: greeting.value
27
- })
28
- } catch (e) {
29
- alert(
30
- 'Something went wrong! ' +
31
- 'Maybe you need to sign out and back in? ' +
32
- 'Check your browser console for more info.'
33
- )
34
- throw e
35
- } finally {
36
- // re-enable the form, whether the call succeeded or failed
37
- fieldset.disabled = false
38
- }
39
-
40
- // disable the save button, since it now matches the persisted value
41
- submitButton.disabled = true
42
-
43
- // update the greeting in the UI
44
- await fetchGreeting()
45
-
46
- // show notification
47
- document.querySelector('[data-behavior=notification]').style.display = 'block'
48
-
49
- // remove notification again after css animation completes
50
- // this allows it to be shown again next time the form is submitted
51
- setTimeout(() => {
52
- document.querySelector('[data-behavior=notification]').style.display = 'none'
53
- }, 11000)
54
- }
55
-
56
- document.querySelector('input#greeting').oninput = (event) => {
57
- if (event.target.value !== currentGreeting) {
58
- submitButton.disabled = false
59
- } else {
60
- submitButton.disabled = true
61
- }
62
- }
63
-
64
- document.querySelector('#sign-in-button').onclick = login
65
- document.querySelector('#sign-out-button').onclick = logout
66
-
67
- // Display the signed-out-flow container
68
- function signedOutFlow() {
69
- document.querySelector('#signed-out-flow').style.display = 'block'
70
- }
71
-
72
- // Displaying the signed in flow container and fill in account-specific data
73
- function signedInFlow() {
74
- document.querySelector('#signed-in-flow').style.display = 'block'
75
-
76
- document.querySelectorAll('[data-behavior=account-id]').forEach(el => {
77
- el.innerText = window.accountId
78
- })
79
-
80
- // populate links in the notification box
81
- const accountLink = document.querySelector('[data-behavior=notification] a:nth-of-type(1)')
82
- accountLink.href = accountLink.href + window.accountId
83
- accountLink.innerText = '@' + window.accountId
84
- const contractLink = document.querySelector('[data-behavior=notification] a:nth-of-type(2)')
85
- contractLink.href = contractLink.href + window.contract.contractId
86
- contractLink.innerText = '@' + window.contract.contractId
87
-
88
- // update with selected networkId
89
- accountLink.href = accountLink.href.replace('testnet', networkId)
90
- contractLink.href = contractLink.href.replace('testnet', networkId)
91
-
92
- fetchGreeting()
93
- }
94
-
95
- // update global currentGreeting variable; update DOM with it
96
- async function fetchGreeting() {
97
- currentGreeting = await contract.getGreeting({ accountId: window.accountId })
98
- document.querySelectorAll('[data-behavior=greeting]').forEach(el => {
99
- // set divs, spans, etc
100
- el.innerText = currentGreeting
101
-
102
- // set input elements
103
- el.value = currentGreeting
104
- })
105
- }
106
-
107
- // `nearInitPromise` gets called on page load
108
- window.nearInitPromise = initContract()
109
- .then(() => {
110
- if (window.walletConnection.isSignedIn()) signedInFlow()
111
- else signedOutFlow()
112
- })
113
- .catch(console.error)
@@ -1,15 +0,0 @@
1
- beforeAll(async function () {
2
- // NOTE: nearlib and nearConfig are made available by near-cli/test_environment
3
- const near = await nearlib.connect(nearConfig)
4
- window.accountId = nearConfig.contractName
5
- window.contract = await near.loadContract(nearConfig.contractName, {
6
- viewMethods: ['getGreeting'],
7
- changeMethods: [],
8
- sender: window.accountId
9
- })
10
- })
11
-
12
- test('getGreeting', async () => {
13
- const message = await window.contract.getGreeting({ accountId: window.accountId })
14
- expect(message).toEqual('Hello')
15
- })
@@ -1,39 +0,0 @@
1
- import { connect, Contract, keyStores, WalletConnection } from 'near-api-js'
2
- import getConfig from './config'
3
-
4
- const nearConfig = getConfig(process.env.NODE_ENV || 'development')
5
-
6
- // Initialize contract & set global variables
7
- export async function initContract() {
8
- // Initialize connection to the NEAR testnet
9
- const near = await connect(Object.assign({ deps: { keyStore: new keyStores.BrowserLocalStorageKeyStore() } }, nearConfig))
10
-
11
- // Initializing Wallet based Account. It can work with NEAR testnet wallet that
12
- // is hosted at https://wallet.testnet.near.org
13
- window.walletConnection = new WalletConnection(near)
14
-
15
- // Getting the Account ID. If still unauthorized, it's just empty string
16
- window.accountId = window.walletConnection.getAccountId()
17
-
18
- // Initializing our contract APIs by contract name and configuration
19
- window.contract = await new Contract(window.walletConnection.account(), nearConfig.contractName, {
20
- // View methods are read only. They don't modify the state, but usually return some value.
21
- viewMethods: ['getGreeting'],
22
- // Change methods can modify the state. But you don't receive the returned value when called.
23
- changeMethods: ['setGreeting'],
24
- })
25
- }
26
-
27
- export function logout() {
28
- window.walletConnection.signOut()
29
- // reload page
30
- window.location.replace(window.location.origin + window.location.pathname)
31
- }
32
-
33
- export function login() {
34
- // Allow the current app to make calls to the specified contract on the
35
- // user's behalf.
36
- // This works by creating a new access key for the user's account and storing
37
- // the private key in localStorage.
38
- window.walletConnection.requestSignIn(nearConfig.contractName)
39
- }
@@ -1,28 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
6
- </head>
7
- <body style="background: #fff; margin-top: 3em">
8
- <div>Please run the following command in NEAR CLI, then enter account id here. masterAccountId default: test.near
9
- </div>
10
- <div>
11
- <code id="shell-command"></code>
12
- </div>
13
- <input type="text" id="accountId" name="accountId" placeholder="Account id"></input>
14
- <button type="button" onClick="done()">done</button>
15
- <script>
16
- const currentUrl = new URL(window.location.href);
17
- const message = `NODE_ENV=local near create_account {newAccountId} --masterAccount {masterAccountId} --publicKey ${currentUrl.searchParams.get('public_key')} --initialAmount 10000000000000000000`;
18
- document.getElementById('shell-command').innerText = message;
19
-
20
- function done() {
21
- const successUrl = new URL(currentUrl.searchParams.get('success_url'));
22
- successUrl.searchParams.set('account_id', document.getElementById('accountId').value);
23
- successUrl.searchParams.set('public_key', currentUrl.searchParams.get('public_key'));
24
- window.location.assign(successUrl.toString());
25
- }
26
- </script>
27
- </body>
28
- </html>
@@ -1,26 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
-
3
- # dependencies
4
- package-lock.json
5
- /node_modules
6
- /.pnp
7
- .pnp.js
8
- /out
9
-
10
- # testing
11
- /coverage
12
-
13
- # production
14
- /.cache
15
- /dist
16
-
17
- # misc
18
- .DS_Store
19
- .env.local
20
- .env.development.local
21
- .env.test.local
22
- .env.production.local
23
-
24
- npm-debug.log*
25
- yarn-debug.log*
26
- yarn-error.log*
@@ -1,6 +0,0 @@
1
- tasks:
2
- - init: yarn
3
- command: yarn dev
4
- ports:
5
- - port: 8080
6
- onOpen: open-browser