add linter

This commit is contained in:
Gerardo Nardelli 2020-03-20 16:14:46 -03:00
parent 0eaf700ea9
commit cb7c1f1c9a
13 changed files with 209 additions and 143 deletions

11
.editorconfig Normal file
View File

@ -0,0 +1,11 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
[*.json]
indent_size = 4

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
dist
build
node_modules

29
.eslintrc.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from @typescript-eslint/eslint-plugin
'plugin:prettier/recommended' // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off", // Reduce the use of 'any'
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"react/prop-types": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/member-delimiter-style": "off"
},
settings: {
react: {
version: "detect",
}
}
};

6
.prettierrc Normal file
View File

@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120,
"bracketSpacing": true
}

View File

@ -1,33 +1,23 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { xdai, dai, eth } from '@burner-wallet/assets';
import BurnerCore from '@burner-wallet/core';
import { InjectedSigner, LocalSigner } from '@burner-wallet/core/signers';
import { InfuraGateway, InjectedGateway, XDaiGateway, } from '@burner-wallet/core/gateways';
import Exchange, { Uniswap, XDaiBridge } from '@burner-wallet/exchange';
import ModernUI from '@burner-wallet/modern-ui';
import React from 'react'
import ReactDOM from 'react-dom'
import { xdai, dai, eth } from '@burner-wallet/assets'
import BurnerCore from '@burner-wallet/core'
import { InjectedSigner, LocalSigner } from '@burner-wallet/core/signers'
import { InfuraGateway, InjectedGateway, XDaiGateway } from '@burner-wallet/core/gateways'
import Exchange, { Uniswap, XDaiBridge } from '@burner-wallet/exchange'
import ModernUI from '@burner-wallet/modern-ui'
// import MyPlugin from 'my-plugin';
const core = new BurnerCore({
signers: [new InjectedSigner(), new LocalSigner()],
gateways: [
new InjectedGateway(),
new InfuraGateway(process.env.REACT_APP_INFURA_KEY),
new XDaiGateway(),
],
assets: [xdai, dai, eth],
});
gateways: [new InjectedGateway(), new InfuraGateway(process.env.REACT_APP_INFURA_KEY), new XDaiGateway()],
assets: [xdai, dai, eth]
})
const exchange = new Exchange({
pairs: [new XDaiBridge(), new Uniswap('dai')],
});
pairs: [new XDaiBridge(), new Uniswap('dai')]
})
const BurnerWallet = () =>
<ModernUI
title="Basic Wallet"
core={core}
plugins={[exchange]}
/>
const BurnerWallet = () => <ModernUI title="Basic Wallet" core={core} plugins={[exchange]} />
ReactDOM.render(<BurnerWallet />, document.getElementById('root'));
ReactDOM.render(<BurnerWallet />, document.getElementById('root'))

View File

@ -1,14 +1,14 @@
const axios = require('axios');
const axios = require('axios')
let id = 0;
const rpc = (url, method, ...params) => axios.post(url, { jsonrpc:"2.0", id: id++, method, params })
.then(response => response.result);
let id = 0
const rpc = (url, method, ...params) =>
axios.post(url, { jsonrpc: '2.0', id: id++, method, params }).then(response => response.result)
module.exports.testRPC = url => async () => {
try {
const response = await rpc(url, 'eth_blockNumber');
return !!response;
const response = await rpc(url, 'eth_blockNumber')
return !!response
} catch (e) {
return false;
return false
}
}

View File

@ -1,88 +1,89 @@
const { spawn } = require('child_process');
const fs = require('fs');
const Web3 = require('web3');
const { testRPC } = require('./run-local-lib');
const utils = require('ethereumjs-util');
const { spawn } = require('child_process')
const fs = require('fs')
const Web3 = require('web3')
const { testRPC } = require('./run-local-lib')
const utils = require('ethereumjs-util')
process.on('unhandledRejection', e => console.error(e));
process.on('unhandledRejection', e => console.error(e))
const RPC = 'http://localhost:8545';
const PK_USER = '0xecb2222da7cbca080201acf6a7bbda53a3b2bcb22e3004b83ab8c69a884becb9';
const RPC = 'http://localhost:8545'
const PK_USER = '0xecb2222da7cbca080201acf6a7bbda53a3b2bcb22e3004b83ab8c69a884becb9'
const DEPLOYER_PK = '0x13179885a8731284475aa2317a35a292131772bb5aa33734a1290b8b13944409';
const DEPLOYER_ADDRESS = utils.bufferToHex(utils.privateToAddress(DEPLOYER_PK));
const DEPLOYER_PK = '0x13179885a8731284475aa2317a35a292131772bb5aa33734a1290b8b13944409'
const DEPLOYER_ADDRESS = utils.bufferToHex(utils.privateToAddress(DEPLOYER_PK))
const ERC20_ADDRESS = utils.bufferToHex(utils.generateAddress(DEPLOYER_ADDRESS, '0'));
const ERC20_ADDRESS = utils.bufferToHex(utils.generateAddress(DEPLOYER_ADDRESS, '0'))
const getAccount = async web3 => {
const [defaultAccount] = await web3.eth.getAccounts();
const [defaultAccount] = await web3.eth.getAccounts()
if (!defaultAccount) {
throw new Error('Can not find an unlocked account');
throw new Error('Can not find an unlocked account')
}
return defaultAccount;
return defaultAccount
}
(async function() {
if (!await testRPC(RPC)) {
throw new Error('Ganache not found on port 8545');
;(async function() {
if (!(await testRPC(RPC))) {
throw new Error('Ganache not found on port 8545')
}
const web3 = new Web3(new Web3.providers.HttpProvider(RPC), null, {
transactionConfirmationBlocks: 1,
});
transactionConfirmationBlocks: 1
})
const user = web3.eth.accounts.privateKeyToAccount(PK_USER);
const deployer = web3.eth.accounts.privateKeyToAccount(DEPLOYER_PK);
const user = web3.eth.accounts.privateKeyToAccount(PK_USER)
const deployer = web3.eth.accounts.privateKeyToAccount(DEPLOYER_PK)
const balance = await web3.eth.getBalance(user.address);
console.log(balance, 'bal');
const balance = await web3.eth.getBalance(user.address)
console.log(balance, 'bal')
if (balance === '0') {
const defaultAccount = await getAccount(web3);
const defaultAccount = await getAccount(web3)
console.log(`Sending 1 ETH from ${defaultAccount} to ${user.address}`);
console.log(`Sending 1 ETH from ${defaultAccount} to ${user.address}`)
await web3.eth.sendTransaction({
from: defaultAccount,
to: user.address,
value: web3.utils.toWei('1', 'ether'),
});
value: web3.utils.toWei('1', 'ether')
})
}
const collectableCode = await web3.eth.getCode(ERC20_ADDRESS);
const collectableCode = await web3.eth.getCode(ERC20_ADDRESS)
if (collectableCode === '0x') {
console.log('ERC20 contract not found, deploying');
const defaultAccount = await getAccount(web3);
console.log('ERC20 contract not found, deploying')
const defaultAccount = await getAccount(web3)
await web3.eth.sendTransaction({
from: defaultAccount,
to: deployer.address,
value: web3.utils.toWei('.2', 'ether'),
});
value: web3.utils.toWei('.2', 'ether')
})
// Deploy ERC20
const erc20Bytecode = fs.readFileSync(`${__dirname}/erc20bytecode.txt`, 'utf8');
const erc20Bytecode = fs.readFileSync(`${__dirname}/erc20bytecode.txt`, 'utf8')
const { rawTransaction: deployTx } = await deployer.signTransaction({
gas: '5000000',
data: erc20Bytecode,
data: erc20Bytecode
})
await web3.eth.sendSignedTransaction(deployTx);
await web3.eth.sendSignedTransaction(deployTx)
// Transfer tokens to user
console.log('Transfering tokens');
console.log('Transfering tokens')
const { rawTransaction: transferTx } = await deployer.signTransaction({
to: ERC20_ADDRESS,
gas: '5000000',
data: `0xa9059cbb000000000000000000000000${user.address.substr(2)}0000000000000000000000000000000000000000000000056bc75e2d63100000`,
data: `0xa9059cbb000000000000000000000000${user.address.substr(
2
)}0000000000000000000000000000000000000000000000056bc75e2d63100000`
})
await web3.eth.sendSignedTransaction(transferTx);
await web3.eth.sendSignedTransaction(transferTx)
}
spawn('yarn', ['start-wallet'], {
env: {
...process.env,
REACT_APP_PK: PK_USER,
REACT_APP_ERC20_ADDRESS: ERC20_ADDRESS,
REACT_APP_ERC20_ADDRESS: ERC20_ADDRESS
},
stdio: 'inherit',
});
})();
stdio: 'inherit'
})
})()

View File

@ -1,47 +1,36 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { NativeAsset, ERC20Asset } from '@burner-wallet/assets';
import BurnerCore from '@burner-wallet/core';
import { InjectedSigner, LocalSigner } from '@burner-wallet/core/signers';
import { HTTPGateway } from '@burner-wallet/core/gateways';
import ModernUI from '@burner-wallet/modern-ui';
import Exchange, { Uniswap, XDaiBridge } from '@burner-wallet/exchange';
import React from 'react'
import ReactDOM from 'react-dom'
import { NativeAsset, ERC20Asset } from '@burner-wallet/assets'
import BurnerCore from '@burner-wallet/core'
import { InjectedSigner, LocalSigner } from '@burner-wallet/core/signers'
import { HTTPGateway } from '@burner-wallet/core/gateways'
import ModernUI from '@burner-wallet/modern-ui'
import Exchange, { Uniswap, XDaiBridge } from '@burner-wallet/exchange'
// import MyPlugin from 'my-plugin';
const core = new BurnerCore({
signers: [
new InjectedSigner(),
new LocalSigner({ privateKey: process.env.REACT_APP_PK, saveKey: false }),
],
gateways: [
new HTTPGateway('http://localhost:8545', '5777'),
],
signers: [new InjectedSigner(), new LocalSigner({ privateKey: process.env.REACT_APP_PK, saveKey: false })],
gateways: [new HTTPGateway('http://localhost:8545', '5777')],
assets: [
new ERC20Asset({
id: 'localerc20',
name: 'Local Token',
network: '5777',
// @ts-ignore
address: process.env.REACT_APP_ERC20_ADDRESS,
address: process.env.REACT_APP_ERC20_ADDRESS
}),
new NativeAsset({
id: 'geth',
name: 'Ganache ETH',
network: '5777',
}),
],
});
network: '5777'
})
]
})
const exchange = new Exchange({
pairs: [new XDaiBridge(), new Uniswap('dai')],
});
pairs: [new XDaiBridge(), new Uniswap('dai')]
})
const BurnerWallet = () =>
<ModernUI
title="Local Wallet"
core={core}
plugins={[exchange]}
/>
const BurnerWallet = () => <ModernUI title="Local Wallet" core={core} plugins={[exchange]} />
ReactDOM.render(<BurnerWallet />, document.getElementById('root'));
ReactDOM.render(<BurnerWallet />, document.getElementById('root'))

View File

@ -1,35 +1,35 @@
import { BurnerPluginContext, Plugin, Actions } from '@burner-wallet/types';
import MyPage from './ui/MyPage';
import MyElement from './ui/MyElement';
import { BurnerPluginContext, Plugin, Actions } from '@burner-wallet/types'
import MyPage from './ui/MyPage'
import MyElement from './ui/MyElement'
interface PluginActionContext {
actions: Actions;
actions: Actions
}
export default class MyPlugin implements Plugin {
private pluginContext?: BurnerPluginContext;
private pluginContext?: BurnerPluginContext
initializePlugin(pluginContext: BurnerPluginContext) {
this.pluginContext = pluginContext;
this.pluginContext = pluginContext
pluginContext.addPage('/my-page', MyPage);
pluginContext.addPage('/my-page', MyPage)
pluginContext.addButton('apps', 'My Plugin', '/my-page', {
description: 'Sample plugin page',
});
pluginContext.addElement('home-middle', MyElement);
description: 'Sample plugin page'
})
pluginContext.addElement('home-middle', MyElement)
onQRScanned: ((scan: string, ctx: PluginActionContext) => {
onQRScanned: (scan: string, ctx: PluginActionContext) => {
if (scan === 'My Plugin') {
ctx.actions.navigateTo('/my-page');
return true;
ctx.actions.navigateTo('/my-page')
return true
}
});
}
}
async getBlockNum() {
const assets = this.pluginContext!.getAssets();
const web3 = this.pluginContext!.getWeb3(assets[0].network);
const blockNum = web3.eth.getBlockNumber();
return blockNum;
const assets = this.pluginContext!.getAssets()
const web3 = this.pluginContext!.getWeb3(assets[0].network)
const blockNum = web3.eth.getBlockNumber()
return blockNum
}
}

View File

@ -1,23 +1,21 @@
import React, { useEffect, useState } from 'react';
import { PluginElementContext } from '@burner-wallet/types';
import MyPlugin from '../MyPlugin';
import React, { useEffect, useState } from 'react'
import { PluginElementContext } from '@burner-wallet/types'
import MyPlugin from '../MyPlugin'
const MyElement: React.FC<PluginElementContext> = ({ plugin }) => {
const [block, setBlock] = useState<string | null>(null);
const _plugin = plugin as MyPlugin;
const [block, setBlock] = useState<string | null>(null)
const _plugin = plugin as MyPlugin
useEffect(() => {
_plugin.getBlockNum().then((num: number) => setBlock(num.toString()))
}, []);
}, [])
return (
<div>
<div>Injected plugin element</div>
{block && (
<div>Current block number: {block}</div>
)}
{block && <div>Current block number: {block}</div>}
</div>
);
};
)
}
export default MyElement;
export default MyElement

View File

@ -1,15 +1,15 @@
import React from 'react';
import { PluginPageContext } from '@burner-wallet/types';
import { Asset } from '@burner-wallet/assets';
import React from 'react'
import { PluginPageContext } from '@burner-wallet/types'
import { Asset } from '@burner-wallet/assets'
const MyPage: React.FC<PluginPageContext> = ({ burnerComponents, assets, defaultAccount }) => {
const { Page } = burnerComponents;
const { Page } = burnerComponents
return (
<Page title="My Page">
<div>Account: {defaultAccount}</div>
<div>Assets: {assets.map((asset: Asset) => asset.name).join(', ')}</div>
</Page>
);
};
)
}
export default MyPage;
export default MyPage

View File

@ -20,8 +20,11 @@
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.16.0",
"lerna": "^3.16.4"
"lerna": "^3.16.4",
"prettier": "^1.19.1"
},
"dependencies": {
"typescript": "^3.6.3"

View File

@ -5690,6 +5690,13 @@ escodegen@^1.11.0, escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"
eslint-config-prettier@^6.10.0:
version "6.10.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.10.0.tgz#7b15e303bf9c956875c948f6b21500e48ded6a7f"
integrity sha512-AtndijGte1rPILInUdHjvKEGbIV06NuvPrqlIEaEaWtbtvJh464mDeyGMdZEQMsGvC0ZVkiex1fSNcC4HAbRGg==
dependencies:
get-stdin "^6.0.0"
eslint-config-react-app@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-5.0.2.tgz#df40d73a1402986030680c040bbee520db5a32a4"
@ -5763,6 +5770,13 @@ eslint-plugin-jsx-a11y@6.2.3:
has "^1.0.3"
jsx-ast-utils "^2.2.1"
eslint-plugin-prettier@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz#432e5a667666ab84ce72f945c72f77d996a5c9ba"
integrity sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA==
dependencies:
prettier-linter-helpers "^1.0.0"
eslint-plugin-react-hooks@^1.6.1:
version "1.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04"
@ -6528,6 +6542,11 @@ fast-deep-equal@^2.0.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
fast-glob@^2.0.2, fast-glob@^2.2.6:
version "2.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.7.tgz#6953857c3afa475fff92ee6015d52da70a4cd39d"
@ -6967,6 +6986,11 @@ get-stdin@^4.0.1:
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=
get-stdin@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
get-stream@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-2.3.1.tgz#5f38f93f346009666ee0150a054167f91bdd95de"
@ -11601,6 +11625,18 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
prettier-linter-helpers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
dependencies:
fast-diff "^1.1.2"
prettier@^1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
pretty-bytes@^5.1.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.3.0.tgz#f2849e27db79fb4d6cfe24764fc4134f165989f2"