mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-15 21:08:57 +00:00
fix pair imported accounts with deviceID
This commit is contained in:
parent
c2d03631a4
commit
c2544c2461
@ -3,7 +3,7 @@
|
||||
import * as ACCOUNT from 'actions/constants/account';
|
||||
import * as IMPORT from 'actions/constants/importAccount';
|
||||
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 LocalStorageActions from 'actions/LocalStorageActions';
|
||||
import TrezorConnect from 'trezor-connect';
|
||||
@ -21,6 +21,13 @@ export type ImportAccountAction =
|
||||
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 = (
|
||||
address: string,
|
||||
network: Network,
|
||||
@ -39,9 +46,7 @@ export const importAddress = (
|
||||
BlockchainActions.discoverAccount(device, address, network.shortcut)
|
||||
);
|
||||
|
||||
const index = getState().accounts.filter(
|
||||
a => a.imported === true && a.network === network.shortcut
|
||||
).length;
|
||||
const index = findIndex(getState().accounts, network, device);
|
||||
|
||||
const empty = account.nonce <= 0 && account.balance === '0';
|
||||
payload = {
|
||||
@ -93,9 +98,7 @@ export const importAddress = (
|
||||
|
||||
const account = response.payload;
|
||||
const empty = account.sequence <= 0 && account.balance === '0';
|
||||
const index = getState().accounts.filter(
|
||||
a => a.imported === true && a.network === network.shortcut
|
||||
).length;
|
||||
const index = findIndex(getState().accounts, network, device);
|
||||
|
||||
payload = {
|
||||
imported: true,
|
||||
|
@ -62,10 +62,17 @@ export const findDeviceAccounts = (
|
||||
): Array<Account> => {
|
||||
if (network) {
|
||||
return state.filter(
|
||||
addr => (addr.deviceState === device.state || addr.imported) && addr.network === network
|
||||
addr =>
|
||||
(addr.deviceState === device.state ||
|
||||
(addr.imported && addr.deviceID === (device.features || {}).device_id)) &&
|
||||
addr.network === network
|
||||
);
|
||||
}
|
||||
return state.filter(addr => addr.deviceState === device.state || addr.imported);
|
||||
return state.filter(
|
||||
addr =>
|
||||
addr.deviceState === device.state ||
|
||||
(addr.imported && addr.deviceID === (device.features || {}).device_id)
|
||||
);
|
||||
};
|
||||
|
||||
const createAccount = (state: State, account: Account): State => {
|
||||
|
Loading…
Reference in New Issue
Block a user