forked from near/nearcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning-up nearlib for release (take 1) (near#452)
* Re-hash nearlib imports so that only one `require` is needed * Enable eslint and apply auto fixes * Apply manual ESLint fixes * Rename exports.js -> browser-exports.js * Add dev subpackage in browser library (based on https://github.com/nearprotocol/NEARStudio/pull/70/files) * Add dist/ to repo to allow serving via jsDelivr * window.nearLib -> window.nearlib * nearlib.dev.initDefault -> nearlib.dev.connect * Create user if needed when connecting to near in dev env * Remove superagent dependency
- Loading branch information
Showing
22 changed files
with
5,746 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,6 @@ core/wasm/**/Cargo.lock | |
# Python env | ||
.env | ||
|
||
# JS build | ||
nearlib/dist/ | ||
|
||
# Integration tests | ||
tmp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
env: | ||
es6: true | ||
node: true | ||
extends: 'eslint:recommended' | ||
parserOptions: | ||
ecmaVersion: 2018 | ||
rules: | ||
indent: | ||
- error | ||
- 4 | ||
linebreak-style: | ||
- error | ||
- unix | ||
quotes: | ||
- error | ||
- single | ||
semi: | ||
- error | ||
- always | ||
no-console: off | ||
globals: | ||
window: true | ||
fetch: true | ||
Headers: true | ||
document: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
window.nearlib = require('./index'); | ||
window.nearlib.dev = require('./dev'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const nearlib = require('./'); | ||
const sendJson = require('./internal/send-json'); | ||
|
||
const localStorageAccountIdKey = 'dev_near_user'; | ||
module.exports = { | ||
getConfig: async function() { | ||
return JSON.parse(decodeURIComponent(getCookie('fiddleConfig'))); | ||
}, | ||
connect: async function(nodeUrl) { | ||
const studioConfig = await this.getConfig(); | ||
const near = nearlib.Near.createDefaultConfig(nodeUrl || studioConfig.nodeUrl); | ||
await this.getOrCreateDevUser(); | ||
return near; | ||
}, | ||
getOrCreateDevUser: async function () { | ||
let tempUserAccountId = window.localStorage.getItem(localStorageAccountIdKey); | ||
if (tempUserAccountId) { | ||
return tempUserAccountId; | ||
} | ||
|
||
tempUserAccountId = 'devuser' + Date.now(); | ||
const keypair = await nearlib.KeyPair.fromRandomSeed(); | ||
const nearConfig = await this.getConfig(); | ||
await sendJson('POST', `${nearConfig.baseUrl}/account`, { | ||
newAccountId: tempUserAccountId, | ||
newAccountPublicKey: keypair.getPublicKey() | ||
}); | ||
const keyStore = new nearlib.BrowserLocalStorageKeystore(); | ||
keyStore.setKey(tempUserAccountId, keypair); | ||
window.localStorage.setItem(localStorageAccountIdKey, tempUserAccountId); | ||
return tempUserAccountId; | ||
}, | ||
get myAccountId() { | ||
return window.localStorage.getItem(localStorageAccountIdKey); | ||
} | ||
}; | ||
|
||
function getCookie(name) { | ||
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)'); | ||
return v ? v[2] : null; | ||
} |
Oops, something went wrong.