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

Revert "fix(): done"

This reverts commit 5ea64735.
parent 5ea64735
......@@ -74,7 +74,7 @@ class AccountNewView extends React.Component {
<AccountIconChooser
value={selected && selected.seed && selected.address}
onChange={({ address, seed, bip39 }) => {
accounts.updateNew({ address, seed, validBip39Seed: bip39 });
accounts.updateNew({ address, seed, validBip39Seed: bip39 }, false);
}}
/>
<Text style={styles.title}>ACCOUNT NAME</Text>
......
......@@ -17,7 +17,7 @@
'use strict';
import React from 'react';
import { Alert, SafeAreaView, StyleSheet, ScrollView, Text } from 'react-native';
import { Alert, findNodeHandle, SafeAreaView, StyleSheet, ScrollView, Text, View } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
import { Subscribe } from 'unstated';
......@@ -26,13 +26,11 @@ import AccountCard from '../components/AccountCard';
import AccountSeed from '../components/AccountSeed';
import Background from '../components/Background';
import Button from '../components/Button';
import NetworkButton from '../components/NetworkButton';
import TextInput from '../components/TextInput';
import { NETWORK_LIST } from '../constants';
import AccountsStore from '../stores/AccountsStore';
import { validateSeed } from '../util/account';
import { debounce } from '../util/debounce'
import { brainWalletAddress } from '../util/native';
import NetworkButton from '../components/NetworkButton';
export default class AccountRecover extends React.Component {
static navigationOptions = {
......@@ -51,20 +49,8 @@ export default class AccountRecover extends React.Component {
class AccountRecoverView extends React.Component {
constructor(...args) {
super(...args);
this.state = { seed: ''}
}
addressGeneration = (seed) => {
const { accounts } = this.props;
brainWalletAddress(seed)
.then(({ address, bip39 }) => accounts.updateNew({address, validBip39Seed: bip39}))
.catch(console.error);
}
debouncedAddressGeneration = debounce(this.addressGeneration, 200)
render() {
const { accounts } = this.props;
const selected = accounts.getNew();
......@@ -101,10 +87,9 @@ class AccountRecoverView extends React.Component {
<AccountSeed
valid={validateSeed(selected.seed, selected.validBip39Seed).valid}
onChangeText={seed => {
this.debouncedAddressGeneration(seed);
this.setState({seed});
accounts.updateNew({ seed });
}}
value={this.state.seed}
value={selected.seed}
/>
<AccountCard
style={{ marginTop: 20 }}
......
......@@ -16,10 +16,11 @@
// @flow
import debounce from 'debounce';
import { Container } from 'unstated';
import { accountId, empty } from '../util/account';
import { loadAccounts, saveAccount } from '../util/db';
import { decryptData, encryptData } from '../util/native';
import { brainWalletAddress, decryptData, encryptData } from '../util/native';
export type Account = {
name: string,
......@@ -64,8 +65,35 @@ export default class AccountsStore extends Container<AccountsState> {
});
}
updateNew(accountUpdate: Object) {
this.setState({ newAccount : {...this.state.newAccount, ...accountUpdate} })
updateNew(accountUpdate: Object, recalculateAddress: boolean = true) {
// Object.assign(this.state.newAccount, accountUpdate);
// const { seed } = this.state.newAccount;
// if (typeof seed === 'string') {
// debounce(async () => {
// const { bip39, address } = await brainWalletAddress(seed);
// Object.assign(this.state.newAccount, { address, validBip39Seed: bip39 });
// this.setState({});
// }, 200)();
// }
// this.setState({});
const { newAccount } = this.state;
const { seed } = accountUpdate;
console.log('hop',accountUpdate)
if ( seed && recalculateAddress ){
this.setState({newAccount :{...newAccount, seed}});
debounce(async () => {
const { bip39, address } = await brainWalletAddress(seed);
console.log('back',{ newAccount : {...newAccount, ...accountUpdate, address, validBip39Seed: bip39} })
this.setState({ newAccount : {...newAccount, ...accountUpdate, address, validBip39Seed: bip39} })
console.log('we update to',{ newAccount : {...newAccount, ...accountUpdate, address, validBip39Seed: bip39} })
}, 200)()
} else {
this.setState({ newAccount : {...newAccount, ...accountUpdate} })
console.log('without calculation',{ newAccount : {...newAccount, ...accountUpdate} })
}
}
getNew(): Account {
......
/**
* Creates and returns a new debounced version of the passed function that will
* postpone its execution until after wait milliseconds have elapsed since
* the last time it was invoked.
*
* @type {T} item type
* @param {(any) => any} function to debounce
* @param {number} time in milliseconds
*
*
* @return {any} the debounced function
*/
export function debounce (fn, time) {
let timeout;
return function() {
const functionCall = () => fn.apply(this, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}
}
\ No newline at end of file
......@@ -2191,7 +2191,7 @@ data-urls@^1.0.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"
debounce@^1.2.0:
debounce@^1.0.0, debounce@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.0.tgz#44a540abc0ea9943018dc0eaa95cce87f65cd131"
integrity sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg==
......
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