@@ -27,14 +27,17 @@ function AllWalletsUI(props: {
27
27
onBack : ( ) => void ;
28
28
onSelect : ( wallet : Wallet ) => void ;
29
29
} ) {
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 ] ) ;
35
38
36
39
const fuseInstance = useMemo ( ( ) => {
37
- return new Fuse ( walletInfos , {
40
+ return new Fuse ( walletList , {
38
41
threshold : 0.4 ,
39
42
keys : [
40
43
{
@@ -43,39 +46,19 @@ function AllWalletsUI(props: {
43
46
} ,
44
47
] ,
45
48
} ) ;
46
- } , [ ] ) ;
49
+ } , [ walletList ] ) ;
47
50
48
51
const listContainer = useRef < HTMLDivElement | null > ( null ) ;
49
52
const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
50
53
const deferredSearchTerm = useDebouncedValue ( searchTerm , 300 ) ;
51
54
52
- const walletInfosWithSearch = deferredSearchTerm
55
+ const searchResults = deferredSearchTerm
53
56
? 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 ;
77
58
78
- const walletInfosToShow = sortedWallets . slice ( 0 , itemsToShow ) ;
59
+ const walletInfosToShow = useMemo ( ( ) => {
60
+ return sortWallets ( searchResults . slice ( 0 , itemsToShow ) ) ;
61
+ } , [ searchResults , itemsToShow ] ) ;
79
62
80
63
return (
81
64
< Container fullHeight flex = "column" animate = "fadein" >
0 commit comments