refactored getSelectedAccount, createAccount

pull/495/head
slowbackspace 5 years ago
parent 715da870a7
commit 27f35b097d

@ -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;
};

@ -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

Loading…
Cancel
Save