1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

web3 1.2.2 & truffle-hd-wallet updates, simplify types

This commit is contained in:
Matthias Kretschmann 2019-10-29 14:26:39 +01:00
parent fe4f2233f0
commit aec1f78257
Signed by: m
GPG Key ID: 606EEEF3C479A91F
14 changed files with 2615 additions and 1708 deletions

View File

@ -31,12 +31,13 @@
"env": {
"es6": true,
"browser": true,
"node": true,
"jest": true,
"cypress/globals": true
},
"settings": {
"react": {
"version": "16.8"
"version": "16"
}
}
}

View File

@ -61,7 +61,7 @@ script:
# executing `npm test` scripts individually here, so first one failing will exit the build
- npm run lint || travis_terminate 1
- ./scripts/keeper.sh
- ./scripts/test.sh || travis_terminate 1
- ./scripts/test.sh
- ./scripts/coverage.sh
# Pipe the coverage data to Code Climate
- ./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.client.json client/coverage/lcov.info

4147
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"scripts": {
"start": "react-scripts start",
"build": "CI=false react-scripts --max_old_space_size=4096 build",
"test": "CI=false react-scripts test --coverage --watchAll=false",
"test": "react-scripts test --coverage --watchAll=false",
"test:watch": "react-scripts test --coverage",
"eject": "react-scripts eject",
"coverage": "cat coverage/lcov.info | codacy-coverage --token 8801f827fe1144ffa85cd7da94f2bbf7",
@ -17,6 +17,7 @@
"@oceanprotocol/squid": "^0.8.0",
"@oceanprotocol/typographies": "^0.1.0",
"@sindresorhus/slugify": "^0.9.1",
"@truffle/hdwallet-provider": "^1.0.23",
"axios": "^0.19.0",
"bip39": "^3.0.2",
"classnames": "^2.2.6",
@ -44,15 +45,14 @@
"react-router-dom": "^5.1.2",
"react-transition-group": "^4.3.0",
"shortid": "^2.2.15",
"truffle-hdwallet-provider": "1.0.14",
"web3": "1.2.1"
"truffle-hdwallet-provider": "^1.0.17",
"web3": "^1.2.2"
},
"devDependencies": {
"@react-mock/state": "^0.1.8",
"@testing-library/jest-dom": "^4.2.0",
"@testing-library/react": "^9.3.0",
"@types/classnames": "^2.2.9",
"@types/filesize": "^4.2.0",
"@types/is-url": "^1.2.28",
"@types/jest": "^24.0.20",
"@types/react": "^16.9.11",
@ -64,9 +64,9 @@
"@types/react-paginate": "^6.2.1",
"@types/react-router-dom": "^5.1.0",
"@types/react-transition-group": "^4.2.3",
"@types/shortid": "0.0.29",
"@types/web3": "^1.0.20",
"@types/shortid": "^0.0.29",
"@typescript-eslint/eslint-plugin": "^2.6.0",
"@typescript-eslint/parser": "^2.6.0",
"eslint": "^5.16.0",
"jest-mock-axios": "^3.1.2",
"node-sass": "^4.13.0",

9
client/src/@types/global.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import Web3 from 'web3'
import { Eth } from 'web3/eth'
declare global {
interface Window {
web3: Web3
ethereum: Eth
}
}

View File

@ -1 +0,0 @@
declare module 'ipfs-http-client'

View File

@ -1 +0,0 @@
declare module 'ipfs'

View File

@ -3,3 +3,7 @@
declare module 'ethereum-blockies' {
export function toDataUrl(address: string): string
}
declare module 'ipfs'
declare module 'ipfs-http-client'
declare module 'react-collapsed'

View File

@ -1 +0,0 @@
declare module 'react-collapsed'

View File

@ -1 +0,0 @@
declare module 'truffle-hdwallet-provider'

View File

@ -1,6 +1,6 @@
import Web3 from 'web3'
import { nodeUri } from '../config'
import HDWalletProvider from 'truffle-hdwallet-provider'
import HDWalletProvider from '@truffle/hdwallet-provider'
import { requestFromFaucet } from '../ocean'
const bip39 = require('bip39') // eslint-disable-line @typescript-eslint/no-var-requires
@ -28,7 +28,7 @@ export class BurnerWalletProvider {
const isLogged = await this.isLogged()
if (isLogged) {
mnemonic = (await localStorage.getItem('seedphrase')) as string
mnemonic = localStorage.getItem('seedphrase')
} else {
mnemonic = bip39.generateMnemonic()
localStorage.setItem('seedphrase', mnemonic)
@ -36,12 +36,12 @@ export class BurnerWalletProvider {
localStorage.setItem('logType', 'BurnerWallet')
const provider = new HDWalletProvider(mnemonic, `${nodeUri}`, 0, 1)
this.web3 = new Web3(provider)
this.web3 = new Web3(provider as any)
const accounts = await this.web3.eth.getAccounts()
const balance = await this.web3.eth.getBalance(accounts[0])
// fill with Ether if account balance is empty
balance === '0' && (await requestFromFaucet(provider.addresses[0]))
balance === '0' && (await requestFromFaucet(provider.getAddress(0)))
}
public async logout() {

View File

@ -12,40 +12,6 @@ const POLL_ACCOUNTS = 1000 // every 1s
const POLL_NETWORK = POLL_ACCOUNTS * 60 // every 1 min
const DEFAULT_WEB3 = new Web3(new Web3.providers.HttpProvider(nodeUri)) // default web3
// taken from
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web3/providers.d.ts
interface JsonRPCRequest {
jsonrpc: string
method: string
params: any[]
id: number
}
interface JsonRPCResponse {
jsonrpc: string
id: number
result?: any
error?: string
}
interface Callback<ResultType> {
(error: Error): void
(error: null, val: ResultType): void
}
declare global {
interface Window {
web3: Web3
ethereum: {
enable(): void
send(
payload: JsonRPCRequest,
callback: Callback<JsonRPCResponse>
): any
}
}
}
interface UserProviderState {
isLogged: boolean
isBurner: boolean

View File

@ -5,6 +5,7 @@ import '@testing-library/jest-dom/extend-expect'
// this is just a little hack to silence a warning that we'll get until we
// upgrade to 16.9: https://github.com/facebook/react/pull/14853
const originalError = console.error
const originalWarning = console.warn
beforeAll(() => {
console.error = (...args) => {
@ -13,8 +14,16 @@ beforeAll(() => {
}
originalError.call(console, ...args)
}
console.warn = (...args) => {
if (/Warning.*componentWillMount has been renamed/.test(args[0])) {
return
}
originalWarning.call(console, ...args)
}
})
afterAll(() => {
console.error = originalError
console.warn = originalWarning
})

View File

@ -45,6 +45,9 @@
"url": "https://github.com/oceanprotocol/commons"
},
"jest": {
"preset": "ts-jest"
"preset": "ts-jest",
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
]
}
}