Skip to content

Commit d69b6f5

Browse files
authored
Merge pull request #2316 from Web3Auth/fix/all-wallets-button-not-showing
Fix threshold for showing all wallets buttons
2 parents 3286675 + 339a37e commit d69b6f5

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function ConnectWallet(props: ConnectWalletProps) {
1919
walletConnectUri,
2020
metamaskConnectUri,
2121
walletRegistry,
22-
allExternalButtons,
22+
allRegistryButtons,
2323
customConnectorButtons,
2424
connectorVisibilityMap,
2525
deviceDetails,
@@ -62,21 +62,21 @@ function ConnectWallet(props: ConnectWalletProps) {
6262

6363
const allUniqueButtons = useMemo(() => {
6464
const uniqueButtonSet = new Set();
65-
return customConnectorButtons.concat(allExternalButtons).filter((button) => {
65+
return customConnectorButtons.concat(allRegistryButtons).filter((button) => {
6666
if (uniqueButtonSet.has(button.name)) return false;
6767
uniqueButtonSet.add(button.name);
6868
return true;
6969
});
70-
}, [allExternalButtons, customConnectorButtons]);
70+
}, [allRegistryButtons, customConnectorButtons]);
7171

7272
const defaultButtonKeys = useMemo(() => new Set(Object.keys(walletRegistry.default)), [walletRegistry]);
7373

7474
const defaultButtons = useMemo(() => {
7575
// display order: default injected buttons > custom adapter buttons > default non-injected buttons
7676
const buttons = [
77-
...allExternalButtons.filter((button) => button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
77+
...allRegistryButtons.filter((button) => button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
7878
...customConnectorButtons,
79-
...allExternalButtons.filter((button) => !button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
79+
...allRegistryButtons.filter((button) => !button.hasInjectedWallet && defaultButtonKeys.has(button.name)),
8080
].sort((a, b) => {
8181
// favor MetaMask over other wallets
8282
if (a.name === WALLET_CONNECTORS.METAMASK && b.name === WALLET_CONNECTORS.METAMASK) {
@@ -101,7 +101,7 @@ function ConnectWallet(props: ConnectWalletProps) {
101101
return true;
102102
})
103103
.filter((button) => selectedChain === "all" || button.chainNamespaces?.includes(selectedChain as ChainNamespaceType));
104-
}, [allExternalButtons, customConnectorButtons, defaultButtonKeys, selectedChain]);
104+
}, [allRegistryButtons, customConnectorButtons, defaultButtonKeys, selectedChain]);
105105

106106
const installedWalletButtons = useMemo(() => {
107107
const visibilityMap = connectorVisibilityMap;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ConnectWalletProps {
88
walletConnectUri: string | undefined;
99
metamaskConnectUri: string | undefined;
1010
walletRegistry?: WalletRegistry;
11-
allExternalButtons: ExternalButton[];
11+
allRegistryButtons: ExternalButton[];
1212
customConnectorButtons: ExternalButton[];
1313
connectorVisibilityMap: Record<string, boolean>;
1414
deviceDetails: { platform: platform; browser: browser; os: os };

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function Login(props: LoginProps) {
5050
isDark,
5151
handleSocialLoginClick,
5252
totalExternalWallets,
53+
remainingUndisplayedWallets,
5354
isEmailPasswordLessLoginVisible,
5455
isSmsPasswordLessLoginVisible,
5556
handleExternalWalletBtnClick,
@@ -509,7 +510,7 @@ function Login(props: LoginProps) {
509510
))}
510511

511512
{/* EXTERNAL WALLETS DISCOVERY */}
512-
{totalExternalWallets > 3 && (
513+
{remainingUndisplayedWallets > 0 && (
513514
<button
514515
type="button"
515516
className={cn("w3a--btn !w3a--justify-between w3a--group w3a--relative w3a--overflow-hidden", {
@@ -520,12 +521,12 @@ function Login(props: LoginProps) {
520521
onClick={handleConnectWallet}
521522
>
522523
<p className="w3a--text-base w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white">{t("modal.external.all-wallets")}</p>
523-
{showExternalWalletCount && totalExternalWallets > 0 && (
524+
{showExternalWalletCount && (
524525
<div
525526
id="external-wallet-count"
526527
className="w3a--absolute w3a--right-4 w3a--top-1/2 w3a--w-auto -w3a--translate-y-1/2 w3a--rounded-full w3a--bg-app-primary-100 w3a--px-2.5 w3a--py-0.5 w3a--text-xs w3a--font-medium w3a--text-app-primary-800 w3a--transition-all w3a--delay-300 w3a--duration-300 group-hover:w3a--translate-x-6 group-hover:w3a--opacity-0 group-hover:w3a--delay-0 dark:w3a--border dark:w3a--border-app-primary-500 dark:w3a--bg-transparent dark:w3a--text-app-primary-500"
527528
>
528-
{totalExternalWallets - 1}
529+
{remainingUndisplayedWallets}
529530
</div>
530531
)}
531532
<img

packages/modal/src/ui/components/Login/Login.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface LoginProps {
3232
isEmailPasswordLessLoginVisible: boolean;
3333
isSmsPasswordLessLoginVisible: boolean;
3434
totalExternalWallets: number;
35+
remainingUndisplayedWallets: number;
3536
logoAlignment?: LogoAlignmentType;
3637
buttonRadius?: ButtonRadiusType;
3738
deviceDetails: { platform: platform; browser: browser; os: os };

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function Root(props: RootProps) {
278278
[connectorVisibilityMap, chainNamespaces, config, deviceDetails.platform, isWalletConnectConnectorIncluded]
279279
);
280280

281-
const allButtons = useMemo(() => {
281+
const allRegistryButtons = useMemo(() => {
282282
return [...generateWalletButtons(walletRegistry.default), ...generateWalletButtons(walletRegistry.others)];
283283
}, [generateWalletButtons, walletRegistry.default, walletRegistry.others]);
284284

@@ -303,7 +303,7 @@ function Root(props: RootProps) {
303303
const metamaskConnectorIdx = installedConnectors.findIndex((x) => x.name === WALLET_CONNECTORS.METAMASK && !x.hasInjectedWallet);
304304
if (metamaskConnectorIdx !== -1) {
305305
const metamaskConnector = installedConnectors[metamaskConnectorIdx];
306-
let metamaskRegistryButton = allButtons.find((button) => button.name === WALLET_CONNECTORS.METAMASK);
306+
let metamaskRegistryButton = allRegistryButtons.find((button) => button.name === WALLET_CONNECTORS.METAMASK);
307307
if (!metamaskRegistryButton) {
308308
// use the default metamask registry item if it's not in the registry
309309
metamaskRegistryButton = generateWalletButtons({
@@ -321,7 +321,7 @@ function Root(props: RootProps) {
321321

322322
// make metamask the first button and limit the number of buttons
323323
return installedConnectors;
324-
}, [allButtons, config, connectorVisibilityMap, generateWalletButtons]);
324+
}, [allRegistryButtons, config, connectorVisibilityMap, generateWalletButtons]);
325325

326326
const customConnectorButtons = useMemo(() => {
327327
return installedConnectorButtons.filter((button) => !button.hasInjectedWallet);
@@ -336,14 +336,20 @@ function Root(props: RootProps) {
336336
.slice(0, displayInstalledExternalWallets ? MAX_TOP_INSTALLED_CONNECTORS : 1);
337337
}, [installedConnectorButtons, displayInstalledExternalWallets]);
338338

339-
const totalExternalWallets = useMemo(() => {
340-
const uniqueWalletSet = new Set();
341-
return allButtons.concat(installedConnectorButtons).filter((button) => {
342-
if (uniqueWalletSet.has(button.name)) return false;
343-
uniqueWalletSet.add(button.name);
339+
const allExternalWallets = useMemo(() => {
340+
const uniqueButtonSet = new Set();
341+
return installedConnectorButtons.concat(allRegistryButtons).filter((button) => {
342+
if (uniqueButtonSet.has(button.name)) return false;
343+
uniqueButtonSet.add(button.name);
344344
return true;
345+
});
346+
}, [allRegistryButtons, installedConnectorButtons]);
347+
348+
const remainingUndisplayedWallets = useMemo(() => {
349+
return allExternalWallets.filter((button) => {
350+
return !topInstalledConnectorButtons.includes(button);
345351
}).length;
346-
}, [allButtons, installedConnectorButtons]);
352+
}, [allExternalWallets, topInstalledConnectorButtons]);
347353

348354
const handleSocialLoginHeight = () => {
349355
setIsSocialLoginsExpanded((prev) => !prev);
@@ -481,7 +487,8 @@ function Root(props: RootProps) {
481487
installedExternalWalletConfig={topInstalledConnectorButtons}
482488
isEmailPasswordLessLoginVisible={isEmailPasswordLessLoginVisible}
483489
isSmsPasswordLessLoginVisible={isSmsPasswordLessLoginVisible}
484-
totalExternalWallets={totalExternalWallets}
490+
totalExternalWallets={allExternalWallets.length}
491+
remainingUndisplayedWallets={remainingUndisplayedWallets}
485492
logoAlignment={logoAlignment}
486493
buttonRadius={buttonRadiusType}
487494
deviceDetails={deviceDetails}
@@ -499,7 +506,7 @@ function Root(props: RootProps) {
499506
metamaskConnectUri={modalState.metamaskConnectUri}
500507
config={modalState.externalWalletsConfig}
501508
walletRegistry={walletRegistry}
502-
allExternalButtons={allButtons}
509+
allRegistryButtons={allRegistryButtons}
503510
connectorVisibilityMap={connectorVisibilityMap}
504511
customConnectorButtons={customConnectorButtons}
505512
deviceDetails={deviceDetails}

0 commit comments

Comments
 (0)