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 authored and tomasklim committed Feb 18, 2025
1 parent 4df0565 commit 3f232b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ describe('filter receive accounts', () => {

it('returns all accounts when debug mode is on', () => {
const filteredAccounts = [
getWalletAccount({ symbol: 'eth', accountType: 'legacy' }),
getWalletAccount({ symbol: 'eth', accountType: 'normal' }),
getWalletAccount({ symbol: 'eth', accountType: 'ledger' }),
getWalletAccount({ symbol: 'eth', accountType: 'legacy' }),
];
expect(runFilterReceiveAccouns({})).toEqual(filteredAccounts);
});
Expand All @@ -99,10 +99,10 @@ describe('filter receive accounts', () => {

it('excludes coinjoin accounts for BTC network (also tests isAnotherNetwork and isCoinjoinAccount methods)', () => {
const filteredAccounts = [
getWalletAccount({ symbol: 'btc', accountType: 'ledger' }),
getWalletAccount({ symbol: 'btc', accountType: 'taproot' }),
getWalletAccount({ symbol: 'btc', accountType: 'legacy' }),
getWalletAccount({ symbol: 'btc', accountType: 'segwit' }),
getWalletAccount({ symbol: 'btc', accountType: 'ledger' }),
getWalletAccount({ symbol: 'btc', accountType: 'legacy' }),
];

expect(runFilterReceiveAccouns({ symbol: 'btc' })).toEqual(filteredAccounts);
Expand Down
20 changes: 10 additions & 10 deletions suite-common/wallet-utils/src/filterReceiveAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { AccountType, NetworkSymbol, getNetwork } from '@suite-common/wallet-con
import { Account } from '@suite-common/wallet-types';
import { StaticSessionId } from '@trezor/connect';

import { sortByCoin } from './accountUtils';

export const isDebugOnlyAccountType = (
accountType: AccountType,
symbol?: NetworkSymbol,
Expand Down Expand Up @@ -38,14 +40,12 @@ export const filterReceiveAccounts = ({
account.accountType === 'normal' && account.index === 0;
const isCoinjoinAccount = (account: Account) => account.accountType === 'coinjoin';

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

return sortByCoin(accounts.filter(isRelevantAccount));
};

0 comments on commit 3f232b6

Please sign in to comment.