@@ -6,6 +6,7 @@ import { IDisplayedAccountWithBalance } from '../models/accountToDisplay';
66import { useRabbyDispatch , useRabbySelector } from '../store' ;
77import { sortAccountsByBalance } from '../utils/account' ;
88import { getWalletScore } from '../views/ManageAddress/hooks' ;
9+ import { isSameAddress } from '../utils' ;
910
1011export const useAccounts = ( ) => {
1112 const addressSortStore = useRabbySelector (
@@ -61,17 +62,20 @@ export const useAccounts = () => {
6162 return [ normalAccounts , watchModeAccounts ] ;
6263 }
6364 if ( addressSortStore . sortType === 'alphabet' ) {
65+ const sortByAlphabet = (
66+ a : typeof highlightedAccounts [ 0 ] ,
67+ b : typeof highlightedAccounts [ 0 ]
68+ ) =>
69+ ( a ?. alianName || '' ) . localeCompare ( b ?. alianName || '' , 'en' , {
70+ numeric : true ,
71+ } ) ;
6472 return [
65- normalAccounts . sort ( ( a , b ) =>
66- ( a ?. alianName || '' ) . localeCompare ( b ?. alianName || '' , 'en' , {
67- numeric : true ,
68- } )
69- ) ,
70- watchModeAccounts . sort ( ( a , b ) =>
71- ( a ?. alianName || '' ) . localeCompare ( b ?. alianName || '' , 'en' , {
72- numeric : true ,
73- } )
74- ) ,
73+ highlightedAccounts
74+ . concat ( ( data [ '0' ] || [ ] ) . sort ( sortByAlphabet ) )
75+ . filter ( ( e ) => ! ! e ) ,
76+ watchModeHighlightedAccounts
77+ . concat ( ( data [ '1' ] || [ ] ) . sort ( sortByAlphabet ) )
78+ . filter ( ( e ) => ! ! e ) ,
7579 ] ;
7680 }
7781
@@ -88,6 +92,7 @@ export const useAccounts = () => {
8892 normalArr [ KEYRING_CLASS . HARDWARE . LEDGER ] ,
8993 ( a ) => a . hdPathBasePublicKey || nanoid ( )
9094 ) as Dictionary < IDisplayedAccountWithBalance [ ] > ;
95+
9196 return [
9297 [
9398 ...Object . values ( ledgersGroup ) . sort ( ( a , b ) => b . length - a . length ) ,
@@ -101,7 +106,21 @@ export const useAccounts = () => {
101106 sortAccountsByBalance ( watchModeAccounts ) ,
102107 ]
103108 . filter ( ( e ) => Array . isArray ( e ) && e . length > 0 )
104- . sort ( ( a , b ) => getWalletScore ( a ) - getWalletScore ( b ) ) ,
109+ . sort ( ( a , b ) => getWalletScore ( a ) - getWalletScore ( b ) )
110+ . map ( ( groupedAccount ) =>
111+ groupedAccount . sort ( ( a , b ) => {
112+ const isHighlighted = ( item : typeof a ) => {
113+ return highlightedAddresses . some (
114+ ( e ) =>
115+ isSameAddress ( e . address , item . address ) &&
116+ e . brandName === item . brandName
117+ ) ;
118+ } ;
119+ const aScore = isHighlighted ( a ) ? 0 : 1 ;
120+ const bScore = isHighlighted ( b ) ? 0 : 1 ;
121+ return aScore - bScore ;
122+ } )
123+ ) ,
105124 [ ] ,
106125 ] ;
107126 } , [ accountsList , highlightedAddresses , addressSortStore . sortType ] ) ;
0 commit comments