Commit c4aa9b8e authored by Marek Kotewicz's avatar Marek Kotewicz Committed by GitHub
Browse files

Merge pull request #25 from paritytech/standard

Standard
parents 29836a98 f6309069
---
language: node_js
node_js:
- 6
cache:
directories:
- node_modules
install: true
script:
- npm run lint
- npm run test
import React from 'react';
import React from 'react'
import 'react-native'
import App from '../src/components/App'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
import renderer from 'react-test-renderer'
it('renders correctly', () => {
const tree = renderer.create(
<App/>
<App />
)
});
expect(tree).toBeTruthy()
})
import React from 'react';
import React from 'react'
import 'react-native'
import App from '../src/components/App'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
import renderer from 'react-test-renderer'
it('renders correctly', () => {
const tree = renderer.create(
<App/>
<App />
)
});
expect(tree).toBeTruthy()
})
//import mockCamera from './__mocks__/Camera'
/* global jest */
// import mockCamera from './__mocks__/Camera'
jest.unmock('Image')
jest.mock('react-native-camera', () => 'camera')
......@@ -8,6 +9,6 @@ jest.mock('Linking', () => {
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
getInitialURL: jest.fn()
}
})
......@@ -5,7 +5,9 @@
"scripts": {
"build-rust": "cd rust/signer && make ios",
"start": "npm run build-rust && node node_modules/react-native/local-cli/cli.js run-ios",
"test": "jest"
"test": "jest",
"lint": "standard",
"commit": "commit-wizard"
},
"dependencies": {
"bignumber.js": "^4.0.0",
......@@ -21,16 +23,39 @@
"redux": "^3.6.0"
},
"devDependencies": {
"babel-eslint": "^7.2.1",
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.1.0",
"jest-react-native": "^18.0.0",
"react-test-renderer": "15.4.2"
"pre-git": "^3.14.0",
"react-test-renderer": "15.4.2",
"standard": "^9.0.2"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"<rootDir>/jest-setup.js"
]
},
"standard": {
"globals": [
"it",
"describe",
"expect"
],
"parser": "babel-eslint"
},
"config": {
"pre-git": {
"pre-commit": [],
"pre-push": [
"npm run lint -- --fix",
"npm run test"
],
"post-commit": [],
"post-checkout": [],
"post-merge": []
}
}
}
'use strict'
import { ADD_ACCOUNT, SELECT_ACCOUNT, DELETE_ACCOUNT, SET_PIN, CONFIRM_PIN, SET_ACCOUNTS } from '../constants/AccountActions'
import { ADD_ACCOUNT, SELECT_ACCOUNT, DELETE_ACCOUNT, SET_PIN, SET_ACCOUNTS } from '../constants/AccountActions'
export function addAccount(account) {
export function addAccount (account) {
return {
type: ADD_ACCOUNT,
account,
account
}
}
export function selectAccount(account) {
export function selectAccount (account) {
return {
type: SELECT_ACCOUNT,
account,
account
}
}
export function deleteAccount(account) {
export function deleteAccount (account) {
return {
type: DELETE_ACCOUNT,
account,
account
}
}
export function setPin(pin) {
export function setPin (pin) {
return {
type: SET_PIN,
pin,
pin
}
}
export function setAccounts(accounts) {
export function setAccounts (accounts) {
return {
type: SET_ACCOUNTS,
accounts,
accounts
}
}
......@@ -2,17 +2,17 @@
import { NEW_SCANNED_TX, SIGNED_TX } from '../constants/TransactionActions'
export function scannedTx(rlp, transaction) {
export function scannedTx (rlp, transaction) {
return {
type: NEW_SCANNED_TX,
rlp,
transaction,
transaction
}
}
export function signedTx(signature) {
export function signedTx (signature) {
return {
type: SIGNED_TX,
signature: signature,
signature: signature
}
}
......@@ -7,13 +7,13 @@ import AppStyles from '../styles'
export default class AccountDetails extends Component {
static propTypes = {
account: PropTypes.shape({
address: PropTypes.string.isRequired,
address: PropTypes.string.isRequired
}).isRequired,
onDisplayAddressPressed: PropTypes.func.isRequired,
onDeleteAccountPressed: PropTypes.func.isRequired,
onDeleteAccountPressed: PropTypes.func.isRequired
}
render() {
render () {
return (
<ScrollView style={AppStyles.view}>
<Text style={AppStyles.hintText}>Name</Text>
......@@ -45,6 +45,6 @@ export default class AccountDetails extends Component {
const styles = StyleSheet.create({
button: {
flex: 0.5,
flex: 0.5
}
})
'use strict'
import React, { Component, PropTypes } from 'react'
import { Text, View, ListView, RecyclerViewBackedScrollView, StatusBar } from 'react-native'
import { ListView, RecyclerViewBackedScrollView, StatusBar } from 'react-native'
import AccountListRow from './AccountListRow'
import AppStyles from '../styles'
export default class AccountList extends Component {
static propTypes = {
accounts: PropTypes.arrayOf(PropTypes.shape({
address: PropTypes.string.isRequired,
address: PropTypes.string.isRequired
})).isRequired,
onAccountSelected: PropTypes.func.isRequired,
onAccountSelected: PropTypes.func.isRequired
}
constructor(props) {
constructor (props) {
super(props)
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
this.state = {
......@@ -21,13 +21,13 @@ export default class AccountList extends Component {
}
}
componentWillReceiveProps(nextProps) {
componentWillReceiveProps (nextProps) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(nextProps.accounts)
})
}
render() {
render () {
return (
<ListView
style={AppStyles.listView}
......@@ -44,10 +44,10 @@ export default class AccountList extends Component {
/>
)
}}
enableEmptySections={true}
enableEmptySections
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
>
<StatusBar barStyle='light-content'/>
<StatusBar barStyle='light-content' />
</ListView>
)
}
......
......@@ -4,13 +4,12 @@ import React, { Component, PropTypes } from 'react'
import { TouchableHighlight, StyleSheet, View, Text, Image } from 'react-native'
import { blockiesIcon } from '../util/native'
async function displayIcon(self, seed) {
async function displayIcon (self, seed) {
try {
let icon = await blockiesIcon(seed)
self.setState({
icon: icon,
icon: icon
})
} catch (e) {
console.log(e)
}
......@@ -20,15 +19,15 @@ export default class AccountListRow extends Component {
static propTypes = {
upperText: PropTypes.string.isRequired,
lowerText: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired,
onPress: PropTypes.func.isRequired
}
constructor(props) {
constructor (props) {
super(props)
this.state = {}
}
render() {
render () {
displayIcon(this, this.props.lowerText)
return (
......@@ -40,12 +39,12 @@ export default class AccountListRow extends Component {
source={{uri: this.state.icon}}
/>
<View style={{flexDirection: 'column'}}>
<Text style={styles.upperText} ellipsizeMode="middle" numberOfLines={1}>{this.props.upperText}</Text>
<Text style={styles.lowerText} ellipsizeMode="middle" numberOfLines={1}>{this.props.lowerText}</Text>
<Text style={styles.upperText} ellipsizeMode='middle' numberOfLines={1}>{this.props.upperText}</Text>
<Text style={styles.lowerText} ellipsizeMode='middle' numberOfLines={1}>{this.props.lowerText}</Text>
</View>
</View>
<View style={{height: 1, backgroundColor: '#ccc'}}/>
<View style={{height: 1, backgroundColor: '#ddd'}}/>
<View style={{height: 1, backgroundColor: '#ccc'}} />
<View style={{height: 1, backgroundColor: '#ddd'}} />
</View>
</TouchableHighlight>
)
......@@ -54,23 +53,23 @@ export default class AccountListRow extends Component {
const styles = StyleSheet.create({
row: {
backgroundColor: '#F8F8F8',
backgroundColor: '#F8F8F8'
},
square: {
height: 60,
width: 60,
marginRight: 10,
resizeMode: 'contain',
resizeMode: 'contain'
},
upperText: {
marginTop: 20,
width: 200,
fontSize: 16,
color: '#888',
color: '#888'
},
lowerText: {
marginTop: 5,
color: '#aaa',
fontSize: 10,
},
fontSize: 10
}
})
'use strict'
import React, { Component, PropTypes } from 'react'
import { Text, TextInput, View } from 'react-native'
import { TextInput, View } from 'react-native'
import AppStyles from '../styles'
export default class AccountPin extends Component {
static propTypes = {
onNextPressed: PropTypes.func.isRequired,
onNextPressed: PropTypes.func.isRequired
}
constructor(props) {
constructor (props) {
super(props)
this.state = {
text: '',
text: ''
}
}
render() {
render () {
return (
<View style={AppStyles.view}>
<View style={AppStyles.center}>
<TextInput
style={AppStyles.pin}
placeholder='enter pin here'
editable={true}
multiline={false}
autoFocus={true}
returnKeyType='next'
numberOfLines={1}
fontSize={24}
onChangeText={(text) => {this.setState({text: text})}}
value={this.state.text}
onEndEditing={() => { this.props.onNextPressed(this.state.text, this.props.account, this.props.extra) }}
<TextInput
style={AppStyles.pin}
placeholder='enter pin here'
editable
multiline={false}
autoFocus
returnKeyType='next'
numberOfLines={1}
fontSize={24}
onChangeText={(text) => { this.setState({text: text}) }}
value={this.state.text}
onEndEditing={() => { this.props.onNextPressed(this.state.text, this.props.account, this.props.extra) }}
/>
</View>
</View>
</View>
)
}
......
......@@ -6,23 +6,23 @@ import { TextInput, StyleSheet } from 'react-native'
export default class AccountSeed extends Component {
static propTypes = {
seed: PropTypes.string.isRequired,
onChangeText: PropTypes.func.isRequired,
onChangeText: PropTypes.func.isRequired
}
constructor(props) {
constructor (props) {
super(props)
this.state = {
text: this.props.seed
}
}
render() {
render () {
return (
<TextInput
style={styles.input}
placeholder='the brain wallet seed'
editable={true}
multiline={true}
editable
multiline
returnKeyType='default'
numberOfLines={6}
fontSize={12}
......@@ -43,5 +43,5 @@ const styles = StyleSheet.create({
input: {
height: 120,
fontWeight: 'bold'
},
}
})
'use strict'
import React, { Component } from 'react'
import { View, Text, StyleSheet, AppState } from 'react-native'
import { StyleSheet, AppState } from 'react-native'
import { Provider, connect } from 'react-redux'
import { createStore } from 'redux'
import { Actions, ActionConst, Router, Scene } from 'react-native-router-flux'
import { Actions, Router, Scene } from 'react-native-router-flux'
import TabIcon from './TabIcon'
import QrScanner from '../containers/QrScanner'
import AccountList from '../containers/AccountList'
......@@ -25,10 +24,10 @@ loadAccounts().then(accounts => {
const styles = StyleSheet.create({
tabbar: {
backgroundColor: '#343E48',
backgroundColor: '#343E48'
},
navibar: {
backgroundColor: '#343E48',
backgroundColor: '#343E48'
},
navibarTitle: {
color: 'white'
......@@ -46,48 +45,48 @@ const scenes = Actions.create(
<Scene key='txDetails' component={TxDetails} title='Transaction Details'
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='accountEnterPin' title='Enter Pin' component={AccountEnterPin}
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='qrViewTx' title='QR Code' component={QrViewTransaction} rightTitle='Done'
onRight={() => Actions.popTo('left')}
rightButtonTextStyle={styles.navibarTitle}
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
</Scene>
<Scene key='right' title='Accounts' icon={TabIcon} navigationBarStyle={styles.navibar} titleStyle={styles.navibarTitle}>
<Scene key='accountList' title='Accounts' component={AccountList}
rightTitle="Add" onRight={() => Actions.accountNew()} rightButtonTextStyle={styles.navibarTitle}/>
rightTitle='Add' onRight={() => Actions.accountNew()} rightButtonTextStyle={styles.navibarTitle} />
<Scene key='accountNew' component={AccountNew} title='Add Account'
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='accountSetPin' title='Set Pin' component={AccountSetPin}
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='accountConfirmPin' title='Confirm Pin' component={AccountConfirmPin}
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='accountDetails' component={AccountDetails} title='Account Details'
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
<Scene key='qrViewAddress' title='QR Code' component={QrViewAddress}
backTitle='Back'
backButtonTextStyle={styles.navibarTitle}
hideBackImage={true}
hideBackImage
/>
</Scene>
</Scene>
......@@ -95,24 +94,20 @@ const scenes = Actions.create(
)
export default class App extends Component {
constructor(props) {
super(props)
}
render() {
render () {
return (
<Provider store={store}>
<ConnectedRouter scenes={scenes}/>
<ConnectedRouter scenes={scenes} />
</Provider>
)
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
componentDidMount () {
AppState.addEventListener('change', this._handleAppStateChange)
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
componentWillUnmount () {
AppState.removeEventListener('change', this._handleAppStateChange)
}
_handleAppStateChange = (appState) => {
......@@ -127,4 +122,3 @@ export default class App extends Component {
}
}
}
'use strict';
'use strict'
import React, { Component, PropTypes } from 'react'
import { StyleSheet, View, StatusBar } from 'react-native'
import Camera from 'react-native-camera';
import Camera from 'react-native-camera'
import AppStyles from '../styles'
export default class Scanner extends Component {
static propTypes = {
onBarCodeRead: PropTypes.func.isRequired,
onBarCodeRead: PropTypes.func.isRequired
}
render() {
render () {
return (
<Camera onBarCodeRead={this.props.onBarCodeRead} style={AppStyles.view}>
<StatusBar barStyle='light-content'/>
<StatusBar barStyle='light-content' />
<View style={styles.rectangleContainer}>
<View style={styles.rectangle}>
<View style={styles.innerRectangle}/>
<View style={styles.innerRectangle} />
</View>
</View>
</Camera>
......@@ -29,7 +29,7 @@ const styles = StyleSheet.create({
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
backgroundColor: 'transparent'
},
rectangle: {
......@@ -40,7 +40,7 @@ const styles = StyleSheet.create({
height: 250,
width: 250,
borderColor: '#ccc',
backgroundColor: 'transparent',
backgroundColor: 'transparent'