From c2544c2461fe6a839593a0006dc20ca882d52d1e Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 12 Apr 2019 16:09:48 +0200 Subject: [PATCH] fix pair imported accounts with deviceID --- src/actions/ImportAccountActions.js | 17 ++++++++++------- src/reducers/AccountsReducer.js | 11 +++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/actions/ImportAccountActions.js b/src/actions/ImportAccountActions.js index 02a9fae5..21a72088 100644 --- a/src/actions/ImportAccountActions.js +++ b/src/actions/ImportAccountActions.js @@ -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, 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, diff --git a/src/reducers/AccountsReducer.js b/src/reducers/AccountsReducer.js index f4f5fabe..047451de 100644 --- a/src/reducers/AccountsReducer.js +++ b/src/reducers/AccountsReducer.js @@ -62,10 +62,17 @@ export const findDeviceAccounts = ( ): Array => { 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 => {