Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort receive accounts in swap section #16265

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 'taproot' }),
getWalletAccount({ symbol: 'btc', accountType: 'ledger' }),
getWalletAccount({ symbol: 'btc', accountType: 'legacy' }),
getWalletAccount({ symbol: 'btc', accountType: 'segwit' }),
getWalletAccount({ symbol: 'btc', accountType: 'ledger' }),
getWalletAccount({ symbol: 'btc', accountType: 'taproot' }),
];

expect(runFilterReceiveAccouns({ symbol: 'btc' })).toEqual(filteredAccounts);
Expand Down
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,
};
Comment on lines +18 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Bitcoiners will not be happy to have legacy accounts before segwit and taproot

I would expect something like:

  1. normal (BTC, ETH, SOL,...)
  2. taproot (BTC)
  3. segwit (BTC)
  4. coinjoin (BTC)
  5. ledger (ETH, SOL)
  6. legacy (BTC, ETH)
  7. imported (??? mobile)

Please someone confirm @hynek-jina @marekrjpolak

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have to have some ordering in Suite because it logically orders accounts in sidebar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would stick to that and reuse it
Screenshot 2025-01-14 at 15 41 39


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
);
});
};
Loading