ignore fresh account in discovery

pull/2/merge
Szymon Lesisz 6 years ago
parent 69e2083615
commit 393a0c4c56

@ -192,20 +192,16 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const completed: boolean = discoveryProcess.completed;
discoveryProcess.completed = false;
const derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
const network = discoveryProcess.network;
dispatch({
type: ACCOUNT.CREATE,
device,
network,
index: discoveryProcess.accountIndex,
path,
address: ethAddress
});
// TODO: check if address was created before
@ -285,19 +281,30 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const balance = await getBalanceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return;
dispatch(
AccountsActions.setBalance(ethAddress, network, device.state || 'undefined', web3instance.web3.fromWei(balance.toString(), 'ether'))
);
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return;
dispatch(AccountsActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
if (!addressIsEmpty) {
dispatch( discoverAccount(device, discoveryProcess) );
} else {
if (!addressIsEmpty || (addressIsEmpty && completed) || (addressIsEmpty && discoveryProcess.accountIndex === 0)) {
dispatch({
type: ACCOUNT.CREATE,
device,
network,
index: discoveryProcess.accountIndex,
path,
address: ethAddress
});
dispatch(
AccountsActions.setBalance(ethAddress, network, device.state || 'undefined', web3instance.web3.fromWei(balance.toString(), 'ether'))
);
dispatch(AccountsActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
if (!completed)
dispatch( discoverAccount(device, discoveryProcess) );
}
if (addressIsEmpty) {
// release acquired sesssion
await TrezorConnect.getFeatures({
device: {

@ -11,7 +11,7 @@ import Loader from '~/js/components/common/LoaderCircle';
import Tooltip from 'rc-tooltip';
import type { Props } from './index';
import type { TrezorDevice } from '~/flowtype';
import type { TrezorDevice, Accounts } from '~/flowtype';
const AccountSelection = (props: Props): ?React$Element<string> => {
@ -29,7 +29,8 @@ const AccountSelection = (props: Props): ?React$Element<string> => {
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
const deviceAccounts: Array<any> = findDeviceAccounts(accounts, selected, location.state.network);
const deviceAccounts: Accounts = findDeviceAccounts(accounts, selected, location.state.network);
let selectedAccounts = deviceAccounts.map((account, i) => {
// const url: string = `${baseUrl}/network/${location.state.network}/account/${i}`;
const url: string = location.pathname.replace(/account+\/([0-9]*)/, `account/${i}`);

Loading…
Cancel
Save