Skip to content

Commit aa0b8c4

Browse files
authored
Fix All Wallets UI in Connect (#2850)
1 parent 41be954 commit aa0b8c4

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

.changeset/young-balloons-suffer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix "All wallets" UI in Connect
6+
7+
- Remove duplicated entry for "inApp"
8+
- Remove wallets specified by developer

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/AllWalletsUI.tsx

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)