Commit efd60589 authored by Thibaut Sardan's avatar Thibaut Sardan
Browse files

Merge branch 'master' into tbaut-fix-autofocus

parents 9b3b281c 34671962
......@@ -17,8 +17,7 @@
'use strict';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet, KeyboardAvoidingView } from 'react-native';
import { View, Text, StyleSheet } from 'react-native';
import { StackActions, NavigationActions } from 'react-navigation';
import { Subscribe } from 'unstated';
import AccountsStore from '../stores/AccountsStore';
......@@ -47,7 +46,9 @@ class AccountPinView extends React.PureComponent {
state = {
pin: '',
confirmation: '',
focusConfirmation: false
focusConfirmation: false,
pinTooShort: false,
pinMismatch: false
};
async submit() {
......@@ -81,19 +82,30 @@ class AccountPinView extends React.PureComponent {
accountId: accountId(account)
});
}
} else {
if (this.state.pin.length < 6) {
this.setState({ pinTooShort: true });
} else if (this.state.pin !== this.state.confirmation)
this.setState({ pinMismatch: true });
}
}
showHintOrError = () => {
if (this.state.pinTooShort) {
return <Text style={styles.errorText}>Your pin must be at least 6 digits long!</Text>
} else if (this.state.pinMismatch) {
return <Text style={styles.errorText}>Pin codes don't match!</Text>
}
return (<Text style={styles.hintText}>Choose a PIN code with 6 or more digits</Text>)
}
render() {
const { accounts, type, navigation } = this.props;
const title = 'ACCOUNT PIN';
return (
<View style={styles.body}>
<Background />
<Text style={styles.titleTop}>{title}</Text>
<Text style={styles.hintText}>
Please make your PIN 6 or more digits
</Text>
{this.showHintOrError()}
<Text style={styles.title}>PIN</Text>
<PinInput
autoFocus
......@@ -102,14 +114,14 @@ class AccountPinView extends React.PureComponent {
onSubmitEditing={() => {
this.setState({ focusConfirmation: true });
}}
onChangeText={pin => this.setState({ pin })}
onChangeText={pin => this.setState({ pin: pin, pinMismatch: false, pinTooShort: false })}
value={this.state.pin}
/>
<Text style={styles.title}>CONFIRM PIN</Text>
<PinInput
returnKeyType="done"
focus={this.state.focusConfirmation}
onChangeText={confirmation => this.setState({ confirmation })}
onChangeText={confirmation => this.setState({ confirmation: confirmation, pinMismatch: false, pinTooShort: false })}
value={this.state.confirmation}
onSubmitEditing={this.submit}
/>
......@@ -152,18 +164,6 @@ const styles = StyleSheet.create({
flex: 1,
overflow: 'hidden'
},
bodyContainer: {
flex: 1,
flexDirection: 'column',
justifyContent: 'space-between'
},
top: {
flex: 1
},
bottom: {
flexBasis: 50,
paddingBottom: 15
},
title: {
fontFamily: 'Manifold CF',
color: colors.bg_text_sec,
......@@ -187,10 +187,15 @@ const styles = StyleSheet.create({
fontSize: 12,
paddingBottom: 20
},
errorText: {
fontFamily: 'Manifold CF',
textAlign: 'center',
color: colors.bg_alert,
fontWeight: '700',
fontSize: 12,
paddingBottom: 20
},
pinInput: {
marginBottom: 20
},
nextStep: {
marginTop: 20
}
});
......@@ -19,11 +19,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
Alert,
View,
Text,
StyleSheet,
KeyboardAvoidingView
StyleSheet
} from 'react-native';
import debounce from 'debounce';
import { StackActions, NavigationActions } from 'react-navigation';
......@@ -32,7 +30,6 @@ import AccountsStore from '../stores/AccountsStore';
import ScannerStore from '../stores/ScannerStore';
import Background from '../components/Background';
import TextInput from '../components/TextInput';
import Button from '../components/Button';
import colors from '../colors';
export class AccountUnlockAndSign extends React.PureComponent {
......@@ -43,11 +40,17 @@ export class AccountUnlockAndSign extends React.PureComponent {
<AccountUnlockView
{...this.props}
accounts={accounts}
nextButtonTitle="Sign"
onChange={async pin => {
checkPin={async (pin) => {
try {
const txRequest = scannerStore.getTXRequest();
let res = await scannerStore.signData(pin);
scannerStore.getTXRequest();
await scannerStore.signData(pin);
return true
} catch (e) {
return false
}
}}
navigate={
() => {
const resetAction = StackActions.reset({
index: 2,
actions: [
......@@ -57,8 +60,8 @@ export class AccountUnlockAndSign extends React.PureComponent {
]
});
this.props.navigation.dispatch(resetAction);
} catch (e) {}
}}
}
}
/>
)}
</Subscribe>
......@@ -73,45 +76,22 @@ export class AccountUnlock extends React.Component {
{accounts => (
<AccountUnlockView
{...this.props}
onChange={async pin => {
if (await accounts.unlockAccount(accounts.getSelected(), pin)) {
const resetAction = StackActions.reset({
index: 3,
actions: [
NavigationActions.navigate({ routeName: 'AccountList' }),
NavigationActions.navigate({ routeName: 'AccountDetails' }),
NavigationActions.navigate({ routeName: 'AccountEdit' }),
NavigationActions.navigate({ routeName: 'AccountBackup' })
]
});
this.props.navigation.dispatch(resetAction);
}
checkPin={async (pin) => {
console.log('checkPin')
return await accounts.unlockAccount(accounts.getSelected(), pin)
}}
accounts={accounts}
/>
)}
</Subscribe>
);
}
}
export class AccountUnlockAndChangePin extends React.PureComponent {
render() {
return (
<Subscribe to={[AccountsStore]}>
{accounts => (
<AccountUnlockView
{...this.props}
onChange={async pin => {
try {
if (await accounts.unlockAccount(accounts.getSelected(), pin)) {
this.props.navigation.navigate('AccountPin', {
isChange: true
});
}
} catch (e) {}
navigate={() => {
const resetAction = StackActions.reset({
index: 3,
actions: [
NavigationActions.navigate({ routeName: 'AccountList' }),
NavigationActions.navigate({ routeName: 'AccountDetails' }),
NavigationActions.navigate({ routeName: 'AccountEdit' }),
NavigationActions.navigate({ routeName: 'AccountBackup' })
]
});
this.props.navigation.dispatch(resetAction);
}}
accounts={accounts}
/>
)}
</Subscribe>
......@@ -120,30 +100,42 @@ export class AccountUnlockAndChangePin extends React.PureComponent {
}
class AccountUnlockView extends React.PureComponent {
state = {
pin: ''
};
static propTypes = {
onChange: PropTypes.func.isRequired,
nextButtonTitle: PropTypes.string
checkPin: PropTypes.func.isRequired,
hasWrongPin: PropTypes.bool
};
state = {
pin: '',
hasWrongPin: false
};
showErrorMessage = () => {
return this.state.hasWrongPin ? 'Wrong pin, please try again' : '';
}
render() {
const { accounts } = this.props;
return (
<View style={styles.body}>
<Background />
<Text style={styles.titleTop}>UNLOCK ACCOUNT</Text>
<Text style={styles.errorText}>{this.showErrorMessage()}</Text>
<Text style={styles.title}>PIN</Text>
<PinInput
onChangeText={pin => {
this.setState({ pin });
if (pin.length < 1) {
onChangeText={async (pin) => {
this.setState({ pin: pin })
if (pin.length < 4) {
return;
}
debounce(this.props.onChange, 200)(pin);
if (await this.props.checkPin(pin)) {
this.props.navigate()
} else if (pin.length > 5) {
this.setState({ hasWrongPin: true })
}
}}
value={this.state.pin}
/>
</View>
......@@ -178,18 +170,6 @@ const styles = StyleSheet.create({
flex: 1,
overflow: 'hidden'
},
bodyContainer: {
flex: 1,
flexDirection: 'column',
justifyContent: 'space-between'
},
top: {
flex: 1
},
bottom: {
flexBasis: 50,
paddingBottom: 15
},
title: {
fontFamily: 'Manifold CF',
color: colors.bg_text_sec,
......@@ -205,18 +185,15 @@ const styles = StyleSheet.create({
paddingBottom: 20,
textAlign: 'center'
},
hintText: {
errorText: {
fontFamily: 'Manifold CF',
textAlign: 'center',
color: colors.bg_text_sec,
color: colors.bg_alert,
fontWeight: '700',
fontSize: 12,
paddingBottom: 20
},
pinInput: {
marginBottom: 20
},
nextStep: {
marginTop: 20
}
});
......@@ -18,10 +18,9 @@
import { Container } from 'unstated';
import debounce from 'debounce';
import { loadAccounts, saveAccount, deleteAccount } from '../util/db';
import { loadAccounts, saveAccount } from '../util/db';
import { encryptData, decryptData, brainWalletAddress } from '../util/native';
import { accountId, empty } from '../util/account';
import { NETWORK_TYPE, NETWORK_ID } from '../constants';
export type Account = {
name: string,
......@@ -117,7 +116,7 @@ export default class AccountsStore extends Container<AccountsState> {
});
}
async loadAccountTxs() {}
async loadAccountTxs() { }
async save(account, pin = null) {
try {
......@@ -134,7 +133,6 @@ export default class AccountsStore extends Container<AccountsState> {
}
async deleteAccount(account) {
// deleteAccount(account)
account.archived = true;
this.state.accounts.set(accountId(account), account);
this.setState({
......
......@@ -17,10 +17,9 @@
// @flow
import { Container } from 'unstated';
import transaction from '../util/transaction';
import { keccak, ethSign, brainWalletSign, decryptData } from '../util/native';
import { saveTx, loadAccountTxs } from '../util/db';
import { accountId } from '../util/account';``
import { NETWORK_TITLES, NETWORK_IDS } from '../constants';
import { keccak, brainWalletSign, decryptData } from '../util/native';
import { saveTx } from '../util/db';
import { NETWORK_TITLES } from '../constants';
import { type Account } from './AccountsStore';
type TXRequest = Object;
......@@ -76,7 +75,7 @@ export default class ScannerStore extends Container<ScannerState> {
if (!sender.encryptedSeed) {
throw new Error(
`No private key found for account ${
txRequest.data.account
txRequest.data.account
} found in your signer key storage for the ${networkTitle} chain.`
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment