Skip to content

Commit

Permalink
Merge pull request decentraland#19 from NodeFactoryIo/beroburny/impro…
Browse files Browse the repository at this point in the history
…vements

Code improvements
  • Loading branch information
BeroBurny authored Feb 18, 2021
2 parents 030f16b + e27663f commit 53b2fb0
Show file tree
Hide file tree
Showing 20 changed files with 649 additions and 537 deletions.
146 changes: 74 additions & 72 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,79 @@
module.exports = {
"root": true,
"env": {
"mocha": true,
"node": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier",
"eslint-plugin-import"
root: true,
env: {
mocha: true,
node: true,
es6: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-import', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
},
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
"rules": {
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": ["error", {
"varsIgnorePattern": "^_"
}],
"@typescript-eslint/explicit-function-return-type": ["error", {
"allowExpressions": true
}],
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-use-before-define": "off",
"prefer-const": "error",
"no-consecutive-blank-lines": 0,
"no-console": "error",
"@typescript-eslint/naming-convention": ["error",
{selector: "default", format: ['camelCase']},
{
selector: [
"classProperty", "parameterProperty", "objectLiteralProperty",
"classMethod", "parameter"
],
format: ['camelCase'], leadingUnderscore: "allow"
},
//variable must be in camel or upper case
{selector: "variable", format: ["camelCase"], leadingUnderscore: "allow"},
{selector: "variable", modifiers: ["global"], format: ["PascalCase", "UPPER_CASE"]},
//classes and types must be in PascalCase
{selector: ["typeLike", "enum"], format: ['PascalCase']},
{selector: "enumMember", format: null},
{selector: "typeProperty", format: ['PascalCase', 'camelCase']},
//ignore rules on destructured params
{
selector: "variable",
modifiers: ["destructured"],
format: null
}
],
"import/order": [
"error",
{
"groups": ["builtin", "external", "parent", "internal", "sibling"],
"newlines-between": "always",
"alphabetize": {
order: 'asc'
}
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'prefer-const': 'error',
'no-consecutive-blank-lines': 0,
'no-console': 'error',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'default', format: ['camelCase'] },
{
selector: ['classProperty', 'parameterProperty', 'objectLiteralProperty', 'classMethod', 'parameter'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
//variable must be in camel or upper case
{ selector: 'variable', format: ['camelCase', 'UPPER_CASE'], leadingUnderscore: 'allow' },
// {selector: "variable", modifiers: ["global"], format: ["PascalCase", "UPPER_CASE"]},
//classes and types must be in PascalCase
{ selector: ['typeLike', 'enum'], format: ['PascalCase'] },
{ selector: 'enumMember', format: null },
{ selector: 'typeProperty', format: ['PascalCase', 'camelCase'] },
//ignore rules on destructured params
{
selector: 'variable',
modifiers: ['destructured'],
format: null,
},
],
'import/order': [
'error',
{
groups: ['builtin', 'external', 'parent', 'internal', 'sibling'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
]
},
],
},
overrides: [
{
files: ['**/test/**/*.ts'],
rules: {
'no-console': 'off',
},
},
"overrides": [
{
"files": ["**/test/**/*.ts"],
"rules": {
"no-console": "off",
}
},
]
}
],
};
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test/server/data.js
build
dist
.vscode/
*metamask
metamask
.idea
*.log
test/dapp/data.js
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 120,
arrowParens: "always",
};
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,40 @@ $ yarn add @nodefactory/dappeteer
## Usage

```js
import puppeteer from 'puppeteer'
import dappeteer from 'dappeteer'
import puppeteer from 'puppeteer';
import dappeteer from '@nodefactory/dappeteer';

async function main() {
const browser = await dappeteer.launch(puppeteer)
const metamask = await dappeteer.getMetamask(browser)
const browser = await dappeteer.launch(puppeteer);
const metamask = await dappeteer.setupMetamask(browser);

// create or import an account
// await metamask.createAccount()
await metamask.importAccount('already turtle birth enroll since...')
await metamask.importAccount('already turtle birth enroll since...');

// you can change the network if you want
await metamask.switchNetwork('ropsten')
await metamask.switchNetwork('ropsten');

// go to a dapp and do something that prompts MetaMask to confirm a transaction
const page = await browser.newPage()
await page.goto('http://my-dapp.com')
const payButton = await page.$('#pay-with-eth')
await payButton.click()
const page = await browser.newPage();
await page.goto('http://my-dapp.com');
const payButton = await page.$('#pay-with-eth');
await payButton.click();

// 🏌
await metamask.confirmTransaction()
await metamask.confirmTransaction();
}

main()
main();
```

## API

- `dappeteer.launch(puppeteer[, launchOptions])`: returns an instance of `browser`, same as `puppeteer.launch`, but it also installs the MetaMask extension. It supports all the regular `puppeteer.launch` options as a second argument with the addition of two extra ones:
- `dappeteer.launch(puppeteer[, launchOptions])`: returns an instance of `browser`, same as `puppeteer.launch`, but it also installs the MetaMask extension. It supports all the regular `puppeteer.launch` options as a second argument with the addition of:

- `metamaskPath`: Path to the MetaMask extension (by default it uses the one bundled)
- `metamaskVersion`: Metamask plugin version (by default it uses latest)

- `extensionUrl`: URL of the MetaMask extension, by default it is `chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/popup.html` but if you use a different version you might need to change it use the right extension id.

- `dappeteer.getMetaMask(browser)`: returns a promise that resolves to an object that allows you to interact with MetaMask by using the following methods:
- `dappeteer.setupMetamask(browser)`: returns a promise that resolves to an object that allows you to interact with MetaMask by using the following methods:

- `metamask.createAccount([password])`: it commands MetaMask to create a new account, it resolves when it's done. It can only be used while you haven't signed in yet, otherwise it throws. The password is optional, it defaults to `password1234`.

Expand Down
Loading

0 comments on commit 53b2fb0

Please sign in to comment.