@@ -27,14 +27,17 @@ function AllWalletsUI(props: {
2727 onBack : ( ) => void ;
2828 onSelect : ( wallet : Wallet ) => void ;
2929} ) {
30- const {
31- recommendedWallets,
32- wallets : specifiedWallets ,
33- connectModal,
34- } = useConnectUI ( ) ;
30+ const { itemsToShow, lastItemRef } = useShowMore < HTMLLIElement > ( 10 , 10 ) ;
31+ const { wallets : specifiedWallets , connectModal } = useConnectUI ( ) ;
32+
33+ const walletList = useMemo ( ( ) => {
34+ return walletInfos . filter ( ( wallet ) => {
35+ return specifiedWallets . findIndex ( ( x ) => x . id === wallet . id ) === - 1 ;
36+ } ) ;
37+ } , [ specifiedWallets ] ) ;
3538
3639 const fuseInstance = useMemo ( ( ) => {
37- return new Fuse ( walletInfos , {
40+ return new Fuse ( walletList , {
3841 threshold : 0.4 ,
3942 keys : [
4043 {
@@ -43,39 +46,19 @@ function AllWalletsUI(props: {
4346 } ,
4447 ] ,
4548 } ) ;
46- } , [ ] ) ;
49+ } , [ walletList ] ) ;
4750
4851 const listContainer = useRef < HTMLDivElement | null > ( null ) ;
4952 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
5053 const deferredSearchTerm = useDebouncedValue ( searchTerm , 300 ) ;
5154
52- const walletInfosWithSearch = deferredSearchTerm
55+ const searchResults = deferredSearchTerm
5356 ? fuseInstance . search ( deferredSearchTerm ) . map ( ( result ) => result . item )
54- : walletInfos ;
55-
56- const installedWalletsFirst = sortWallets (
57- walletInfosWithSearch ,
58- recommendedWallets ,
59- ) ;
60-
61- // show specified wallets first
62- const sortedWallets = useMemo ( ( ) => {
63- return installedWalletsFirst . sort ( ( a , b ) => {
64- const aIsSpecified = specifiedWallets . find ( ( w ) => w . id === a . id ) ;
65- const bIsSpecified = specifiedWallets . find ( ( w ) => w . id === b . id ) ;
66- if ( aIsSpecified && ! bIsSpecified ) {
67- return - 1 ;
68- }
69- if ( ! aIsSpecified && bIsSpecified ) {
70- return 1 ;
71- }
72- return 0 ;
73- } ) ;
74- } , [ installedWalletsFirst , specifiedWallets ] ) ;
75-
76- const { itemsToShow, lastItemRef } = useShowMore < HTMLLIElement > ( 10 , 10 ) ;
57+ : walletList ;
7758
78- const walletInfosToShow = sortedWallets . slice ( 0 , itemsToShow ) ;
59+ const walletInfosToShow = useMemo ( ( ) => {
60+ return sortWallets ( searchResults . slice ( 0 , itemsToShow ) ) ;
61+ } , [ searchResults , itemsToShow ] ) ;
7962
8063 return (
8164 < Container fullHeight flex = "column" animate = "fadein" >
0 commit comments