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