Skip to content

Commit c45fe37

Browse files
authored
Merge pull request #2312 from Web3Auth/feat/defi-positions
Fix external wallets list to automatically show other wallets when total count of wallets is 15 or below
2 parents ec1fcea + 1e6bbd6 commit c45fe37

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

packages/modal/src/ui/components/ConnectWallet/ConnectWallet.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ANALYTICS_EVENTS, type ChainNamespaceType, log, type WALLET_CONNECTOR_TYPE, WALLET_CONNECTORS } from "@web3auth/no-modal";
2-
import { FormEvent, useContext, useMemo, useState } from "react";
2+
import { FormEvent, useContext, useEffect, useMemo, useState } from "react";
33

44
import { CONNECT_WALLET_PAGES } from "../../constants";
55
import { AnalyticsContext } from "../../context/AnalyticsContext";
@@ -126,7 +126,6 @@ function ConnectWallet(props: ConnectWalletProps) {
126126

127127
const handleChainFilterChange = (chain: string) => {
128128
setSelectedChain(chain);
129-
setIsShowAllWallets(false);
130129
};
131130

132131
const filteredButtons = useMemo(() => {
@@ -153,6 +152,16 @@ function ConnectWallet(props: ConnectWalletProps) {
153152
return walletDiscoverySupported ? defaultButtons.length : installedWalletButtons.length;
154153
}, [walletDiscoverySupported, defaultButtons, installedWalletButtons, isShowAllWallets, totalExternalWalletsCount]);
155154

155+
// Automatically show all wallets if there are less than or equal to 15 wallets
156+
// also resets everytime we search causing no. of wallets to change or select different chain
157+
useEffect(() => {
158+
if (walletDiscoverySupported && totalExternalWalletsCount <= 15) {
159+
setIsShowAllWallets(true);
160+
} else {
161+
setIsShowAllWallets(false);
162+
}
163+
}, [walletDiscoverySupported, selectedChain, totalExternalWalletsCount]);
164+
156165
/**
157166
* Wallet click logic
158167
* - For installed wallets
@@ -289,6 +298,7 @@ function ConnectWallet(props: ConnectWalletProps) {
289298
deviceDetails={deviceDetails}
290299
walletConnectUri={walletConnectUri}
291300
buttonRadius={buttonRadius}
301+
isShowAllWallets={isShowAllWallets}
292302
/>
293303
</div>
294304
)}

packages/modal/src/ui/components/ConnectWallet/ConnectWalletList/ConnectWalletList.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useState } from "react";
21
import { useTranslation } from "react-i18next";
32

43
import i18n from "../../../localeImport";
@@ -114,20 +113,20 @@ function ConnectWalletList(props: ConnectWalletListProps) {
114113
deviceDetails,
115114
walletConnectUri,
116115
buttonRadius,
116+
isShowAllWallets,
117117
} = props;
118118

119-
const [showMoreWallets, setShowMoreWallets] = useState(true);
120-
121119
const onShowMoreWalletsClick = () => {
122-
setShowMoreWallets(false);
123120
handleMoreWallets();
124121
};
125122

123+
const showMoreWalletsButton = !isShowAllWallets;
124+
126125
return (
127126
<>
128127
<ul
129128
className={cn("w3a--overflow-y-auto w3a--flex w3a--flex-col w3a--gap-y-2 w3a--h-[280px] w3a--social-container w3a--pr-2.5", {
130-
"w3a--h-[328px]": !showMoreWallets,
129+
"w3a--h-[328px]": !showMoreWalletsButton,
131130
})}
132131
>
133132
{externalButtons.length === 0 ? (
@@ -143,7 +142,7 @@ function ConnectWalletList(props: ConnectWalletListProps) {
143142
/>
144143
)}
145144
</ul>
146-
{showMoreWallets && totalExternalWalletsCount > 15 && !isLoading && initialWalletCount < totalExternalWalletsCount && (
145+
{showMoreWalletsButton && !isLoading && initialWalletCount < totalExternalWalletsCount && (
147146
<MoreWalletsButton
148147
totalExternalWalletsCount={totalExternalWalletsCount}
149148
initialWalletCount={initialWalletCount}

packages/modal/src/ui/components/ConnectWallet/ConnectWalletList/ConnectWalletList.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface ConnectWalletListProps {
1111
buttonRadius: ButtonRadiusType;
1212
handleWalletClick: (button: ExternalButton) => void;
1313
handleMoreWallets: () => void;
14+
isShowAllWallets: boolean;
1415
}
1516

1617
export type WalletsFoundProps = Pick<

0 commit comments

Comments
 (0)