mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
ignore fresh account in discovery
This commit is contained in:
parent
69e2083615
commit
393a0c4c56
@ -192,20 +192,16 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
|
|||||||
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
|
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
|
||||||
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
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 derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
|
||||||
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
|
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
|
||||||
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');
|
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');
|
||||||
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
|
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
|
||||||
const network = discoveryProcess.network;
|
const network = discoveryProcess.network;
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: ACCOUNT.CREATE,
|
|
||||||
device,
|
|
||||||
network,
|
|
||||||
index: discoveryProcess.accountIndex,
|
|
||||||
path,
|
|
||||||
address: ethAddress
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: check if address was created before
|
// 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);
|
const balance = await getBalanceAsync(web3instance.web3, ethAddress);
|
||||||
if (discoveryProcess.interrupted) return;
|
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);
|
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
|
||||||
if (discoveryProcess.interrupted) return;
|
if (discoveryProcess.interrupted) return;
|
||||||
dispatch(AccountsActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
|
|
||||||
|
|
||||||
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
|
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
|
||||||
|
|
||||||
if (!addressIsEmpty) {
|
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) );
|
dispatch( discoverAccount(device, discoveryProcess) );
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (addressIsEmpty) {
|
||||||
// release acquired sesssion
|
// release acquired sesssion
|
||||||
await TrezorConnect.getFeatures({
|
await TrezorConnect.getFeatures({
|
||||||
device: {
|
device: {
|
||||||
|
@ -11,7 +11,7 @@ import Loader from '~/js/components/common/LoaderCircle';
|
|||||||
import Tooltip from 'rc-tooltip';
|
import Tooltip from 'rc-tooltip';
|
||||||
|
|
||||||
import type { Props } from './index';
|
import type { Props } from './index';
|
||||||
import type { TrezorDevice } from '~/flowtype';
|
import type { TrezorDevice, Accounts } from '~/flowtype';
|
||||||
|
|
||||||
const AccountSelection = (props: Props): ?React$Element<string> => {
|
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 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) => {
|
let selectedAccounts = deviceAccounts.map((account, i) => {
|
||||||
// const url: string = `${baseUrl}/network/${location.state.network}/account/${i}`;
|
// const url: string = `${baseUrl}/network/${location.state.network}/account/${i}`;
|
||||||
const url: string = location.pathname.replace(/account+\/([0-9]*)/, `account/${i}`);
|
const url: string = location.pathname.replace(/account+\/([0-9]*)/, `account/${i}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user