Skip to content

Commit

Permalink
fix(suite): swap accounts sort
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Jan 8, 2025
1 parent b3c19a7 commit 9230c39
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions suite-common/wallet-utils/src/filterReceiveAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const isDebugOnlyAccountType = (
return !!accountTypeInfo?.isDebugOnlyAccountType;
};

const accountTypeOrder: Record<AccountType, number> = {
normal: 0,
ledger: 1,
legacy: 2,
imported: 3,
segwit: 4,
coinjoin: 5,
taproot: 6,
};

type FilterReceiveAccountsProps = {
accounts: Account[];
deviceState?: StaticSessionId;
Expand All @@ -38,14 +48,21 @@ export const filterReceiveAccounts = ({
account.accountType === 'normal' && account.index === 0;
const isCoinjoinAccount = (account: Account) => account.accountType === 'coinjoin';

return accounts.filter(
account =>
const isRelevantAccount = (account: Account) => {
return (
isSameDevice(account) &&
isSameNetwork(account) &&
!isCoinjoinAccount(account) &&
shouldDisplayDebugOnly(account) &&
(isNotEmptyAccount(account) ||
isVisibleAccount(account) ||
isFirstNormalAccount(account)),
);
isFirstNormalAccount(account))
);
};

return accounts.filter(isRelevantAccount).sort((a, b) => {
return (
accountTypeOrder[a.accountType] - accountTypeOrder[b.accountType] || a.index - b.index
);
});
};

0 comments on commit 9230c39

Please sign in to comment.