diff --git a/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts b/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts index afae0fd64a1..de4a05ccd16 100644 --- a/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts +++ b/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts @@ -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); }); @@ -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); diff --git a/suite-common/wallet-utils/src/filterReceiveAccounts.ts b/suite-common/wallet-utils/src/filterReceiveAccounts.ts index 7013953e102..a26fb618ed4 100644 --- a/suite-common/wallet-utils/src/filterReceiveAccounts.ts +++ b/suite-common/wallet-utils/src/filterReceiveAccounts.ts @@ -15,6 +15,16 @@ export const isDebugOnlyAccountType = ( return !!accountTypeInfo?.isDebugOnlyAccountType; }; +const accountTypeOrder: Record = { + normal: 0, + ledger: 1, + legacy: 2, + imported: 3, + segwit: 4, + coinjoin: 5, + taproot: 6, +}; + type FilterReceiveAccountsProps = { accounts: Account[]; deviceState?: StaticSessionId; @@ -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 + ); + }); };