-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from near-projects/dev
Initial Release (dev -> main)
- Loading branch information
Showing
89 changed files
with
59,269 additions
and
366 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
lib/ | ||
example/ |
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,91 @@ | ||
module.exports = { | ||
env: { | ||
commonjs: true, | ||
browser: true, | ||
es6: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: ["tsconfig.json"], | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true, | ||
}, | ||
ecmaVersion: 6, | ||
sourceType: "module", | ||
}, | ||
plugins: [ | ||
"@typescript-eslint", | ||
"prettier", | ||
"react", | ||
"react-hooks" | ||
], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react/recommended", | ||
"prettier", | ||
], | ||
rules: { | ||
"prettier/prettier": ["error", require("./prettier.config")], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-non-null-asserted-optional-chain": "off", | ||
"@typescript-eslint/naming-convention": ["error", { | ||
"selector": "variableLike", | ||
"format": ["camelCase", "PascalCase", "UPPER_CASE"] | ||
}], | ||
"@typescript-eslint/no-explicit-any": "error", | ||
"@typescript-eslint/no-empty-interface": "error", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-var-requires": "warn", | ||
"@typescript-eslint/no-use-before-define": "error", | ||
"@typescript-eslint/type-annotation-spacing": "error", | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/ban-ts-ignore": "off", | ||
"eqeqeq": ["error", "smart"], | ||
"default-case": "off", | ||
"no-caller": "error", | ||
"no-case-declarations": "off", | ||
"no-console": "error", | ||
"no-debugger": "error", | ||
"no-eval": "error", | ||
"no-fallthrough": "error", | ||
"no-labels": "warn", | ||
"no-redeclare": "error", | ||
"no-shadow": "off", | ||
"@typescript-eslint/no-shadow": "error", | ||
"no-unused-expressions": "error", | ||
"radix": ["error", "as-needed"], | ||
"no-restricted-syntax": [ | ||
"error", | ||
{ | ||
"selector": "CallExpression[callee.name!='parseInt'] > Identifier[name='parseInt']", | ||
"message": "Call parseInt directly to guarantee radix param is not incorrectly provided" | ||
}, | ||
"error", | ||
{ | ||
"selector": "CallExpression[callee.name!='parseFloat'] > Identifier[name='parseFloat']", | ||
"message": "Call parseFloat directly to guarantee radix param is not incorrectly provided" | ||
} | ||
], | ||
"strict": ["error", "global"], | ||
"valid-jsdoc": "error", | ||
"react/jsx-uses-react": "error", | ||
"react/react-in-jsx-scope": "error", | ||
"react/jsx-no-target-blank": "off", | ||
"react/no-unescaped-entities": "off", | ||
"react/prop-types": "off", | ||
"react-hooks/rules-of-hooks": "error", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"react/display-name": "off", | ||
}, | ||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
} |
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 @@ | ||
* text=auto |
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,35 @@ | ||
name: PR Actions | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
env: | ||
CI: true | ||
|
||
jobs: | ||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "16.x" | ||
- name: Install NPM Dependencies | ||
run: npm install | ||
- name: Run Build | ||
run: npm run build | ||
- name: Run Linting | ||
run: npm run lint | ||
- name: Run Unit & Integration Tests | ||
run: npm test | ||
# - name: Install Playwright Dependencies | ||
# run: sudo npx playwright install-deps | ||
# - name: Run End-to-End Tests | ||
# run: npm run test:e2e |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
/node_modules | ||
/lib | ||
/lib | ||
/.jest | ||
|
||
# IDEs and editors | ||
/.idea | ||
/.vscode |
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 @@ | ||
example/ |
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 |
---|---|---|
@@ -1 +1,153 @@ | ||
# near-walletselector | ||
# NEAR Wallet Selector | ||
|
||
The NEAR Wallet Selector makes it easy for users to interact with your dApp. This package presents a modal to switch between a number of supported wallet types: | ||
|
||
- [NEAR Wallet](https://wallet.near.org/) - Web wallet. | ||
- [Sender Wallet](https://chrome.google.com/webstore/detail/sender-wallet/epapihdplajcdnnkdeiahlgigofloibg) - Browser extension wallet. | ||
- [Ledger](https://www.ledger.com/) - Hardware wallet. | ||
|
||
## Installation and Usage | ||
|
||
The easiest way to use `near-wallet-selector` is to install it from NPM: | ||
|
||
```bash | ||
npm install near-wallet-selector | ||
``` | ||
|
||
Then use it in your dApp: | ||
|
||
```ts | ||
import NearWalletSelector from "near-wallet-selector"; | ||
|
||
const near = new NearWalletSelector({ | ||
wallets: ["near-wallet", "sender-wallet", "ledger-wallet"], | ||
networkId: "testnet", | ||
theme: "light", | ||
contract: { | ||
accountId: "guest-book.testnet", | ||
viewMethods: ["getMessages"], | ||
changeMethods: ["addMessage"], | ||
}, | ||
walletSelectorUI: { | ||
description: "Please select a wallet to connect to this dApp:", | ||
explanation: [ | ||
"Wallets are used to send, receive, and store digital assets.", | ||
"There are different types of wallets. They can be an extension", | ||
"added to your browser, a hardware device plugged into your", | ||
"computer, web-based, or as an app on your phone.", | ||
].join(" "), | ||
} | ||
}); | ||
``` | ||
|
||
## API Reference | ||
|
||
Init: | ||
|
||
```ts | ||
await near.init(); | ||
``` | ||
|
||
Show modal: | ||
|
||
```ts | ||
near.show(); | ||
``` | ||
|
||
Hide modal: | ||
|
||
```ts | ||
near.hide(); | ||
``` | ||
|
||
Sign in (programmatically): | ||
|
||
```ts | ||
await near.signIn("near-wallet"); | ||
``` | ||
|
||
Sign out: | ||
|
||
```ts | ||
await near.signOut(); | ||
``` | ||
|
||
Is signed in: | ||
|
||
```ts | ||
await near.isSignedIn(); | ||
``` | ||
|
||
Get account: | ||
|
||
```ts | ||
const account = await near.getAccount(); | ||
``` | ||
|
||
Add event listeners: | ||
|
||
```ts | ||
near.on("signIn", () => { | ||
// your code | ||
}); | ||
|
||
near.on("signOut", () => { | ||
// your code | ||
}); | ||
``` | ||
|
||
Remove event listeners: | ||
|
||
```ts | ||
// Method 1: | ||
const subscription = near.on("signIn", () => { | ||
// your code | ||
}); | ||
|
||
subscription.remove(); | ||
|
||
// Method 2: | ||
const handleSignIn = () => { | ||
// your code | ||
} | ||
|
||
near.on("signIn", handleSignIn); | ||
near.off("signIn", handleSignIn); | ||
``` | ||
|
||
Interact with the Smart Contract: | ||
|
||
```ts | ||
// Retrieve messages via RPC endpoint (view method). | ||
const messages = await near.contract.view({ methodName: "getMessages" }); | ||
|
||
// Send a message, modifying the blockchain (change method). | ||
await near.contract.call({ | ||
actions: [{ | ||
methodName: "addMessage", | ||
args: { text: message.value }, | ||
gas: "30000000000000", | ||
deposit: "10000000000000000000000" | ||
}] | ||
}); | ||
|
||
// Retrieve contract accountId. | ||
const accountId = near.contract.getAccountId(); | ||
``` | ||
|
||
## Example Integration | ||
|
||
A variation of the [guest-book](https://github.com/near-examples/guest-book/) example project can be found in the `example` directory. You can use this to gain a concrete understanding of how to integrate this package into your own dApp. | ||
|
||
Contributors to this package may also find this integration useful as it provides a quick and consistent way of manually testing new changes and/or bugs. Below is a common workflow you can use: | ||
|
||
- Navigate to the `example` directory. | ||
- Execute `npm link ../` to create a symlink locally. | ||
- Execute `npm install`. | ||
- Execute `npm run watch` to watch both `src` directories and automatically recompile. | ||
|
||
## Editor Setup | ||
|
||
This project uses [ESLint](https://eslint.org/) (with [Prettier](https://prettier.io/)) to enforce a consistent coding style. It's important that you configure your editor correctly to avoid issues when you're ready to open a Pull Request. | ||
|
||
Although this project uses Prettier, it's simply an "internal" dependency to our ESLint configuration. This is because we want Prettier to handle code styling while avoiding conflicts with ESLint which specifically focuses on potentially problematic code. As a result, **it's important that you switch off Prettier in your editor and ensure only ESLint is enabled**. |
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,13 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
|
||
it("works", () => { | ||
const component = render( | ||
<div> | ||
<span>Hello World!</span> | ||
</div> | ||
); | ||
const text = component.getByText("Hello World!"); | ||
|
||
expect(text).toBeInTheDocument(); | ||
}); |
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,7 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test("basic test", async ({ page }) => { | ||
await page.goto("https://playwright.dev/"); | ||
await page.locator("text=Get started").click(); | ||
await expect(page).toHaveTitle(/Getting started/); | ||
}); |
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,5 @@ | ||
# https://EditorConfig.org | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 |
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,3 @@ | ||
node_modules/ | ||
out/ | ||
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,13 @@ | ||
env: | ||
es2021: true | ||
node: true | ||
extends: | ||
- 'eslint:recommended' | ||
- 'plugin:@typescript-eslint/recommended' | ||
parser: '@typescript-eslint/parser' | ||
parserOptions: | ||
ecmaVersion: 12 | ||
sourceType: module | ||
plugins: | ||
- '@typescript-eslint' | ||
rules: {} |
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,13 @@ | ||
.cache/ | ||
dist/ | ||
node_modules/ | ||
out/ | ||
|
||
# ignore accounts generated by tests | ||
neardev/shared-test/* | ||
# but not the original test.near.json account | ||
!neardev/shared-test/test.near.json | ||
|
||
# ignore any default network private keys and dev-account | ||
neardev/default/* | ||
neardev/dev-account* |
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 @@ | ||
Copyright 2020 NEAR Inc | ||
|
||
Permission is hereby granted, free of charge, to any | ||
person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the | ||
Software without restriction, including without | ||
limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software | ||
is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice | ||
shall be included in all copies or substantial portions | ||
of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.