Skip to content

Commit

Permalink
updated logic for pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha committed Dec 5, 2023
1 parent eb5ff33 commit ceefd58
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1764,19 +1764,23 @@ export function getCustomTokenAmount(state) {

export function getUpdatedAndSortedAccounts(state) {
const accounts = getMetaMaskAccountsOrdered(state);
const pinnedAccounts = getPinnedAccountsList(state);
const pinnedAddresses = getPinnedAccountsList(state);

accounts.forEach((account) => {
account.pinned = Boolean(pinnedAccounts?.includes(account.address));
account.pinned = Boolean(pinnedAddresses?.includes(account.address));
});

const sortedSearchResults = accounts.slice().sort((a, b) => {
if (a.pinned && !b.pinned) {
return -1; // a comes first
} else if (!a.pinned && b.pinned) {
return 1; // b comes first
}
return 0; // keep the order unchanged
});
const notPinnedAccounts = accounts.filter(
(account) => !pinnedAddresses.includes(account.address),
);

const sortedPinnedAccounts = pinnedAddresses
.map((address) => accounts.find((account) => account.address === address))
.filter((account) =>
Boolean(account && pinnedAddresses.includes(account.address)),
);

const sortedSearchResults = [...sortedPinnedAccounts, ...notPinnedAccounts];

return sortedSearchResults;
}
Expand Down

0 comments on commit ceefd58

Please sign in to comment.