|
|
@ -3,7 +3,7 @@
|
|
|
|
import * as ACCOUNT from 'actions/constants/account';
|
|
|
|
import * as ACCOUNT from 'actions/constants/account';
|
|
|
|
import * as IMPORT from 'actions/constants/importAccount';
|
|
|
|
import * as IMPORT from 'actions/constants/importAccount';
|
|
|
|
import * as NOTIFICATION from 'actions/constants/notification';
|
|
|
|
import * as NOTIFICATION from 'actions/constants/notification';
|
|
|
|
import type { AsyncAction, TrezorDevice, Network, Dispatch, GetState } from 'flowtype';
|
|
|
|
import type { AsyncAction, Account, TrezorDevice, Network, Dispatch, GetState } from 'flowtype';
|
|
|
|
import * as BlockchainActions from 'actions/ethereum/BlockchainActions';
|
|
|
|
import * as BlockchainActions from 'actions/ethereum/BlockchainActions';
|
|
|
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
|
|
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
|
|
|
import TrezorConnect from 'trezor-connect';
|
|
|
|
import TrezorConnect from 'trezor-connect';
|
|
|
@ -21,6 +21,15 @@ export type ImportAccountAction =
|
|
|
|
error: ?string,
|
|
|
|
error: ?string,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const findIndex = (accounts: Array<Account>, network: Network, device: TrezorDevice): number => {
|
|
|
|
|
|
|
|
return accounts.filter(
|
|
|
|
|
|
|
|
a =>
|
|
|
|
|
|
|
|
a.imported === true &&
|
|
|
|
|
|
|
|
a.network === network.shortcut &&
|
|
|
|
|
|
|
|
a.deviceID === (device.features || {}).device_id
|
|
|
|
|
|
|
|
).length;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const importAddress = (
|
|
|
|
export const importAddress = (
|
|
|
|
address: string,
|
|
|
|
address: string,
|
|
|
|
network: Network,
|
|
|
|
network: Network,
|
|
|
@ -33,20 +42,14 @@ export const importAddress = (
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let payload;
|
|
|
|
let payload;
|
|
|
|
const index = getState().accounts.filter(
|
|
|
|
|
|
|
|
a =>
|
|
|
|
|
|
|
|
a.imported === true &&
|
|
|
|
|
|
|
|
a.network === network.shortcut &&
|
|
|
|
|
|
|
|
device &&
|
|
|
|
|
|
|
|
a.deviceState === device.state
|
|
|
|
|
|
|
|
).length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (network.type === 'ethereum') {
|
|
|
|
if (network.type === 'ethereum') {
|
|
|
|
const account = await dispatch(
|
|
|
|
const account = await dispatch(
|
|
|
|
BlockchainActions.discoverAccount(device, address, network.shortcut)
|
|
|
|
BlockchainActions.discoverAccount(device, address, network.shortcut)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const index = findIndex(getState().accounts, network, device);
|
|
|
|
|
|
|
|
|
|
|
|
const empty = account.nonce <= 0 && account.balance === '0';
|
|
|
|
const empty = account.nonce <= 0 && account.balance === '0';
|
|
|
|
payload = {
|
|
|
|
payload = {
|
|
|
|
imported: true,
|
|
|
|
imported: true,
|
|
|
@ -97,6 +100,7 @@ export const importAddress = (
|
|
|
|
|
|
|
|
|
|
|
|
const account = response.payload;
|
|
|
|
const account = response.payload;
|
|
|
|
const empty = account.sequence <= 0 && account.balance === '0';
|
|
|
|
const empty = account.sequence <= 0 && account.balance === '0';
|
|
|
|
|
|
|
|
const index = findIndex(getState().accounts, network, device);
|
|
|
|
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
payload = {
|
|
|
|
imported: true,
|
|
|
|
imported: true,
|
|
|
|