Skip to content

Commit

Permalink
Merge pull request #199 from GoodDollar/166155436-code-conventions
Browse files Browse the repository at this point in the history
(Chore) Code conventions
  • Loading branch information
sirpy committed Jun 12, 2019
2 parents 609baa9 + c93c254 commit 215f54b
Show file tree
Hide file tree
Showing 138 changed files with 944 additions and 590 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -4,5 +4,6 @@ assets
config
flow-typed
scripts
public/ZoomAuthentication.js
/*.js
/src/serviceWorker.js
106 changes: 100 additions & 6 deletions .eslintrc
@@ -1,6 +1,7 @@
{
"extends": [
"react-app",
"eslint:recommended",
"plugin:flowtype/recommended",
"plugin:import/recommended",
"plugin:prettier/recommended",
Expand Down Expand Up @@ -33,25 +34,118 @@
".js",
".android.js",
".ios.js",
".web.js"
".web.js",
".native.js"
]
}
},
"dependencies/resolver": {
"node": {
"paths": [
"src"
]
},
"extensions": [
".js",
".android.js",
".ios.js",
".web.js",
".native.js"
]
}
},
"rules": {
"prettier/prettier": "error",
"react/prop-types": "off",
"react/display-name": "off",
"react-hooks/rules-of-hooks": "warn",
"react-hooks/rules-of-hooks": "error",
"dependencies/no-cycles": "error",
"dependencies/no-unresolved": [
"import/no-unresolved": "error",
"import/first": "error",
"import/no-duplicates": "error",
"import/order": [
"warn",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index"
]
}
],
"sort-imports": [
"warn",
{
"ignore": [
"web3"
"ignoreCase": true,
"ignoreDeclarationSort": true
}
],
"no-console": [
"error",
{
"allow": [
"info"
]
}
],
"import/no-unresolved": "warn"
"no-await-in-loop": "error",
"curly": "error",
"dot-notation": "error",
"no-else-return": "error",
"no-implicit-coercion": [
"error",
{
"boolean": false
}
],
"no-return-await": "error",
"no-useless-catch": "error",
"require-await": "error",
"array-bracket-newline": [
"error",
{
"multiline": true
}
],
"block-spacing": "error",
"brace-style": [
"error",
"1tbs",
{
"allowSingleLine": true
}
],
"camelcase": [
"error",
{
"ignoreDestructuring": true,
"properties": "never"
}
],
"comma-dangle": "error",
"comma-spacing": "error",
"computed-property-spacing": "error",
"lines-between-class-members": "error",
"lines-around-comment": [
"error",
{
"beforeBlockComment": true,
"beforeLineComment": true,
"allowBlockStart": true,
"allowObjectStart": true,
"allowArrayStart": true,
"allowClassStart": true,
"afterBlockComment": false,
"afterLineComment": false,
"allowBlockEnd": false,
"allowObjectEnd": false,
"allowArrayEnd": false,
"allowClassEnd": false
}
],
"no-negated-condition": "error"
}
}
59 changes: 36 additions & 23 deletions loadtest/loadTest.js
@@ -1,15 +1,14 @@
import './mock-browser'
import { GoodWallet } from '../src/lib/wallet/GoodWallet'
import fs from 'fs'
import bip39 from 'bip39-light'
import faker from 'faker'
import FormData from 'form-data'
import fetch from 'node-fetch'
import { GoodWallet } from '../src/lib/wallet/GoodWallet'
import { GoodWalletLogin } from '../src/lib/login/GoodWalletLogin'
import { UserStorage } from '../src/lib/gundb/UserStorage'
import Config from '../src/config/config'
import API from '../src/lib/API/api'
import faker from 'faker'
import range from 'lodash/range'
import FormData from 'form-data'
import fs from 'fs'
import fetch from 'node-fetch'
const Timeout = (timeout = 3000) => {
return new Promise((res, rej) => {
setTimeout(res, timeout)
Expand Down Expand Up @@ -42,11 +41,13 @@ export const mytest = async i => {
let login = new GoodWalletLogin(wallet, storage)
await storage.ready
let creds = await login.auth()
// console.log({ creds })

// console.info({ creds })
var randomName = faker.name.findName() // Rowan Nikolaus
var randomEmail = faker.internet.email() // Kassandra.Haley@erich.biz
var randomCard = faker.phone.phoneNumber('+97250#######')
// console.log(randomCard, randomName, randomEmail)

// console.info(randomCard, randomName, randomEmail)
let adduser = await Promise.race([
Timeout(20000).then(x => {
throw new Error('adduser timeout')
Expand All @@ -58,8 +59,10 @@ export const mytest = async i => {
walletAddress: wallet.account
})
])
console.log('/user/add:', adduser.data)
if (adduser.data.ok !== 1) throw new Error('adduser failed')
console.info('/user/add:', adduser.data)
if (adduser.data.ok !== 1) {
throw new Error('adduser failed')
}
await storage.setProfile({
fullName: randomName,
email: randomEmail,
Expand All @@ -73,15 +76,23 @@ export const mytest = async i => {
createReq(wallet.getAccountForType('zoomId'), creds.jwt).then(r => r.json())
])

console.log('/verify/facerecognition:', fr)
if (fr.ok !== 1) throw new Error(`FR failed`)
console.info('/verify/facerecognition:', fr)
if (fr.ok !== 1) {
throw new Error(`FR failed`)
}
let gunres = 0
await new Promise((res, rej) => {
gun.get('users/byemail').once(r => {
if (r && r.err) rej(new Error(r.err))
if (!r) rej(new Error('Empty gun data'))
else if (++gunres === 1) res()
if (r && r.err) {
rej(new Error(r.err))
}
if (!r) {
rej(new Error('Empty gun data'))
} else if (++gunres === 1) {
res()
}
})

// // gun.get('users/bymobile').open(r => {
// // if (r.err) rej(new Error(r.err))
// // else if (++gunres === 2) res()
Expand All @@ -92,8 +103,8 @@ export const mytest = async i => {
// // })
})
} catch (error) {
console.log(`Test failed`, error)
failedTests[error.message] !== undefined ? (failedTests[error.message] += 1) : (failedTests[error.message] = 1)
console.info(`Test failed`, error)
failedTests[error.message] === undefined ? (failedTests[error.message] = 1) : (failedTests[error.message] += 1)
} finally {
// fs.unlinkSync('./loadtest/loadtest' + i + '.json')
}
Expand All @@ -102,19 +113,21 @@ const run = async numTests => {
let promises = []
for (let i = 0; i < numTests; i++) {
promises[i] = mytest(i)
// eslint-disable-next-line no-await-in-loop
await Timeout(10000)
}
console.log('Waiting for tests to finish...')
console.info('Waiting for tests to finish...')
await Promise.all(promises)
console.log('Done running tests', { total: promises.length, failedTests })
console.log('Waiting for server memory stats')
console.info('Done running tests', { total: promises.length, failedTests })
console.info('Waiting for server memory stats')
await Timeout(5000)
console.log('Done. Quiting')
console.info('Done. Quiting')
process.exit(-1)
}
let numTests = process.argv[2]
console.log('arrgs', process.argv, numTests)
console.info('arrgs', process.argv, numTests)
run(numTests)

// describe('load test', () => {
// it('loadtest', async () => {
// const doLogin = async () => {
Expand All @@ -124,7 +137,7 @@ run(numTests)
// expect(wallet).toBeTruthy()
// let login = new GoodWalletLogin(wallet)
// let creds = await login.auth()
// console.log({ creds })
// console.info({ creds })
// return expect(creds).toBeTruthy()
// }
// let promises = range(3).map(i => doLogin())
Expand Down
9 changes: 5 additions & 4 deletions loadtest/mock-browser.js
@@ -1,9 +1,10 @@
import { LocalStorage } from 'node-localStorage'
import Config from '../src/config/config'
import { LocalStorage } from 'node-localstorage'
import Gun from 'gun'
import SEA from 'gun/sea'
import load from 'gun/lib/load'
import 'gun/lib/load'
import Config from '../src/config/config'

// eslint-disable-next-line no-unused-vars
const extend = (() => {
Gun.chain.putAck = function(data, cb) {
var gun = this,
Expand Down Expand Up @@ -61,4 +62,4 @@ global.window = {}
global.window.localStorage = new LocalStorage('./localStorage.tmp')
global.gun = Gun([Config.gunPublicUrl])
global.Gun = Gun
console.log('here')
console.info('here')
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -27,7 +27,8 @@
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
"bundlesize:check": "bundlesize",
"flow": "flow",
"fix-lint": "eslint --fix ./src",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"docs": "node scripts/docs.js"
},
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions src/App.js
Expand Up @@ -2,11 +2,9 @@
import React, { Component } from 'react'
import { Platform, SafeAreaView, StyleSheet, View } from 'react-native'
import { Provider as PaperProvider } from 'react-native-paper'

// import { loadReCaptcha } from 'recaptcha-v3-react'

import Config from './config/config'
import userStorage from './lib/gundb/UserStorage'
import logger from './lib/logger/pino-logger'
import GDStore from './lib/undux/GDStore'
import { WebRouter } from './Router'

Expand Down Expand Up @@ -63,5 +61,6 @@ if (Platform.OS === 'web') {
const { hot } = require('react-hot-loader')
hotWrapper = hot
}

//$FlowFixMe
export default hotWrapper(module)(App)
3 changes: 2 additions & 1 deletion src/__tests__/App.js
@@ -1,7 +1,8 @@
import React from 'react'

// Note: test renderer must be required after react-native.
import App from '../App'
import renderer from 'react-test-renderer'
import App from '../App'

describe('App', () => {
it('renders without errors', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/appNavigation/AppNavigation.js
Expand Up @@ -2,14 +2,14 @@
import { createSwitchNavigator } from '@react-navigation/core'
import React from 'react'
import type { Store } from 'undux'
import { navigationOptions } from './navigationConfig'

// TODO: Should we do this diferently?
import homeIcon from '../../assets/homeIcon.png'

import GDStore from '../../lib/undux/GDStore'
import Dashboard from '../dashboard/Dashboard'
import Profile from '../profile/Profile'
import { navigationOptions } from './navigationConfig'

/**
* @type
Expand Down Expand Up @@ -50,6 +50,7 @@ const AppNavigator = createSwitchNavigator(routes, { initialRouteName })
class AppNavigation extends React.Component<AppNavigationProps, AppNavigationState> {
render() {
const account = this.props.store.get('account')

// `account.ready` will be set to `true` after retrieving the required user information in `updateAll`,
// if not ready will display a blank screen (`null`)
return account.ready ? <AppNavigator navigation={this.props.navigation} screenProps={{ routes }} /> : null
Expand Down
3 changes: 2 additions & 1 deletion src/components/appNavigation/NavBar.js
@@ -1,6 +1,6 @@
//@flow
import React from 'react'
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import backButton from '../../assets/backButton.png'

/**
Expand All @@ -10,6 +10,7 @@ type NavBarProps = {
goBack?: () => void,
title: string
}

/**
* NavigationBar shows title and back button
* @name NavBar
Expand Down

0 comments on commit 215f54b

Please sign in to comment.