Unverified Commit 2d119711 authored by Thibaut Sardan's avatar Thibaut Sardan Committed by GitHub
Browse files

Merge pull request #235 from paritytech/tbaut-fix-race-account-creation

Fix race condition at account creation
parents 1bc3cbc7 9a05e075
......@@ -64,6 +64,7 @@ class AccountBackupView extends React.PureComponent {
accounts.lockAccount(selected);
AppState.removeEventListener('change', this._handleAppStateChange);
}
render() {
const { accounts, navigation } = this.props;
const isNew = navigation.getParam('isNew');
......
......@@ -112,7 +112,7 @@ class AccountNewView extends React.Component {
<Button
buttonStyles={styles.nextStep}
title="Next Step"
disabled={ !validateSeed(selected.seed).valid }
disabled={!validateSeed(selected.seed).valid}
onPress={() => {
validateSeed(selected.seed).valid &&
this.props.navigation.navigate('AccountBackup', {
......
......@@ -25,7 +25,6 @@ import Background from '../components/Background';
import Button from '../components/Button';
import TextInput from '../components/TextInput';
import AccountsStore from '../stores/AccountsStore';
import { accountId } from '../util/account';
export default class AccountPin extends React.PureComponent {
render() {
......@@ -55,21 +54,21 @@ class AccountPinView extends React.PureComponent {
const { accounts, navigation } = this.props;
const accountCreation = navigation.getParam('isNew');
const { pin } = this.state;
const account = accountCreation ? accounts.getNew() : accounts.getSelected();
if (
this.state.pin.length >= 6 &&
this.state.pin === this.state.confirmation
) {
let account = null;
if (accountCreation) {
account = accounts.getNew();
await accounts.submitNew(pin);
await accounts.select(account);
navigation.popToTop();
navigation.navigate('AccountList', {
accountId: accountId(account)
const resetAction = StackActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'AccountList' }),
]
});
this.props.navigation.dispatch(resetAction);
} else {
account = accounts.getSelected();
await accounts.save(account, pin);
const resetAction = StackActions.reset({
index: 1,
......@@ -121,7 +120,6 @@ class AccountPinView extends React.PureComponent {
focus={this.state.focusConfirmation}
onChangeText={confirmation => this.setState({ confirmation: confirmation, pinMismatch: false, pinTooShort: false })}
value={this.state.confirmation}
onSubmitEditing={this.submit}
/>
<Button
onPress={this.submit}
......
......@@ -78,10 +78,6 @@ export default class AccountsStore extends Container<AccountsState> {
this.setState({});
}
resetNew() {
this.setState({ newAccount: empty() });
}
getNew(): Account {
return this.state.newAccount;
}
......@@ -116,15 +112,21 @@ export default class AccountsStore extends Container<AccountsState> {
});
}
async loadAccountTxs() {}
async loadAccountTxs() { }
async save(account, pin = null) {
try {
//only save an account if the seed isn't empty
if (account.seed === ''){
return;
}
if (pin && account.seed) {
let encryptedSeed = await encryptData(account.seed, pin);
delete account.seed;
account.encryptedSeed = encryptedSeed;
}
account.updatedAt = new Date().getTime();
await saveAccount(account);
} catch (e) {
......
......@@ -6760,6 +6760,11 @@ react-native-markdown-renderer@^3.2.8:
prop-types "^15.5.10"
react-native-fit-image "^1.5.2"
react-native-popup-menu@^0.15.0:
version "0.15.5"
resolved "https://registry.yarnpkg.com/react-native-popup-menu/-/react-native-popup-menu-0.15.5.tgz#3f5d7e58f4af8ef108481d5ec2df44e007f3698e"
integrity sha512-9Lgj3HQgemrEDddiDGS9x/5U9jLdo9hzYpGqohmIBe7n+z9VN1P/VxOr951WZAq6GPUHnNDXBBM/7Mun+1v5hw==
react-native-qrcode@^0.2.7:
version "0.2.7"
resolved "https://registry.yarnpkg.com/react-native-qrcode/-/react-native-qrcode-0.2.7.tgz#d103166fb1a5b53643e8bf7b88c0672e689ac4f8"
......
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