From 27f35b097db575299674209f7c03ed42beb1aff2 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 9 Apr 2019 23:36:32 +0200 Subject: [PATCH] refactored getSelectedAccount, createAccount --- src/reducers/AccountsReducer.js | 5 ++++- src/reducers/utils/index.js | 11 +---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/reducers/AccountsReducer.js b/src/reducers/AccountsReducer.js index 14a9b275..304f13a6 100644 --- a/src/reducers/AccountsReducer.js +++ b/src/reducers/AccountsReducer.js @@ -75,8 +75,11 @@ const createAccount = (state: State, account: Account): State => { } const newState: State = [...state]; newState.push(account); + // sort the accounts array so the imported accounts always come before discovered accounts - newState.sort((a, b) => b.imported - a.imported || a.index - b.index); + if (account.imported) { + newState.sort((a, b) => b.imported - a.imported || a.index - b.index); + } return newState; }; diff --git a/src/reducers/utils/index.js b/src/reducers/utils/index.js index 6528a7b1..41422f4c 100644 --- a/src/reducers/utils/index.js +++ b/src/reducers/utils/index.js @@ -89,18 +89,9 @@ export const getSelectedAccount = (state: State): ?Account => { ? parseInt(locationState.account.substr(1), 10) : parseInt(locationState.account, 10); - if (isImported) { - return state.accounts.find( - a => - a.imported === true && - a.deviceState === device.state && - a.index === index && - a.network === locationState.network - ); - } return state.accounts.find( a => - a.imported === false && + a.imported === isImported && a.deviceState === device.state && a.index === index && a.network === locationState.network