Skip to content

Commit e935ecd

Browse files
committed
feat: disable back button when only external wallets available
1 parent c610f93 commit e935ecd

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function ConnectWallet(props: ConnectWalletProps) {
2525
deviceDetails,
2626
buttonRadius = "pill",
2727
chainNamespace,
28+
isExternalWalletModeOnly,
2829
onBackClick,
2930
handleExternalWalletClick,
3031
handleWalletDetailsHeight,
@@ -235,10 +236,18 @@ function ConnectWallet(props: ConnectWalletProps) {
235236
return walletConnectUri;
236237
}, [metamaskConnectUri, selectedButton, selectedWallet, walletConnectUri]);
237238

239+
const disableBackButton = useMemo(() => {
240+
// If wallet is selected, show the back button
241+
if (selectedWallet) return false;
242+
// Otherwise, if external wallet mode only, login screen is skipped so back button is not needed
243+
if (isExternalWalletModeOnly) return true;
244+
return false;
245+
}, [selectedWallet, isExternalWalletModeOnly]);
246+
238247
return (
239248
<div className="w3a--relative w3a--flex w3a--flex-1 w3a--flex-col w3a--gap-y-4">
240249
{/* Header */}
241-
<ConnectWalletHeader onBackClick={handleBack} currentPage={currentPage} selectedButton={selectedButton} />
250+
<ConnectWalletHeader disableBackButton={disableBackButton} onBackClick={handleBack} currentPage={currentPage} selectedButton={selectedButton} />
242251
{/* Body */}
243252
{selectedWallet ? (
244253
<ConnectWalletQrCode

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ConnectWalletProps {
1414
deviceDetails: { platform: platform; browser: browser; os: os };
1515
chainNamespace: ChainNamespaceType[];
1616
buttonRadius: ButtonRadiusType;
17+
isExternalWalletModeOnly: boolean;
1718
onBackClick?: (flag: boolean) => void;
1819
handleExternalWalletClick: (params: { connector: string; chainNamespace?: ChainNamespaceType }) => void;
1920
handleWalletDetailsHeight: () => void;

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import i18n from "../../../localeImport";
55
import { ConnectWalletHeaderProps } from "./ConnectWalletHeader.type";
66

77
function ConnectWalletHeader(props: ConnectWalletHeaderProps) {
8-
const { onBackClick, currentPage, selectedButton } = props;
8+
const { disableBackButton, onBackClick, currentPage, selectedButton } = props;
99
const [t] = useTranslation(undefined, { i18n });
1010

1111
const handleBack = () => {
@@ -16,25 +16,29 @@ function ConnectWalletHeader(props: ConnectWalletHeaderProps) {
1616

1717
return (
1818
<div className="w3a--flex w3a--items-center w3a--justify-between">
19-
<button
20-
type="button"
21-
className="w3a--z-20 w3a--flex w3a--size-5 w3a--cursor-pointer w3a--items-center w3a--justify-center w3a--rounded-full"
22-
onClick={handleBack}
23-
>
24-
<svg
25-
xmlns="http://www.w3.org/2000/svg"
26-
fill="none"
27-
viewBox="0 0 20 20"
28-
className="w3a--text-app-gray-500 hover:w3a--text-app-gray-900 dark:w3a--text-app-gray-200 dark:hover:w3a--text-app-white"
19+
{!disableBackButton ? (
20+
<button
21+
type="button"
22+
className="w3a--z-20 w3a--flex w3a--size-5 w3a--cursor-pointer w3a--items-center w3a--justify-center w3a--rounded-full"
23+
onClick={handleBack}
2924
>
30-
<path
31-
fill="currentColor"
32-
fillRule="evenodd"
33-
d="M9.707 16.707a1 1 0 0 1-1.414 0l-6-6a1 1 0 0 1 0-1.414l6-6a1 1 0 0 1 1.414 1.414L5.414 9H17a1 1 0 1 1 0 2H5.414l4.293 4.293a1 1 0 0 1 0 1.414"
34-
clipRule="evenodd"
35-
/>
36-
</svg>
37-
</button>
25+
<svg
26+
xmlns="http://www.w3.org/2000/svg"
27+
fill="none"
28+
viewBox="0 0 20 20"
29+
className="w3a--text-app-gray-500 hover:w3a--text-app-gray-900 dark:w3a--text-app-gray-200 dark:hover:w3a--text-app-white"
30+
>
31+
<path
32+
fill="currentColor"
33+
fillRule="evenodd"
34+
d="M9.707 16.707a1 1 0 0 1-1.414 0l-6-6a1 1 0 0 1 0-1.414l6-6a1 1 0 0 1 1.414 1.414L5.414 9H17a1 1 0 1 1 0 2H5.414l4.293 4.293a1 1 0 0 1 0 1.414"
35+
clipRule="evenodd"
36+
/>
37+
</svg>
38+
</button>
39+
) : (
40+
<div />
41+
)}
3842
<p className="w3a--text-base w3a--font-medium w3a--text-app-gray-900 dark:w3a--text-app-white">
3943
{currentPage === CONNECT_WALLET_PAGES.SELECTED_WALLET
4044
? selectedButton?.displayName

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ExternalButton } from "../../../interfaces";
22

33
export interface ConnectWalletHeaderProps {
4+
disableBackButton?: boolean;
45
onBackClick: () => void;
56
currentPage: string;
67
selectedButton: ExternalButton;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ function Root(props: RootProps) {
9898
if (handleExternalWalletBtnClick) handleExternalWalletBtnClick(flag);
9999
};
100100

101+
const isExternalWalletModeOnly = useMemo(() => {
102+
return !showPasswordLessInput && !areSocialLoginsVisible;
103+
}, [areSocialLoginsVisible, showPasswordLessInput]);
104+
101105
// Wallet Details
102106
const mobileInstallLinks = useMemo<JSX.Element[]>(() => {
103107
if (deviceDetails.platform === "desktop") return [];
@@ -502,6 +506,7 @@ function Root(props: RootProps) {
502506
chainNamespace={chainNamespaces}
503507
buttonRadius={buttonRadiusType}
504508
handleWalletDetailsHeight={handleWalletDetailsHeight}
509+
isExternalWalletModeOnly={isExternalWalletModeOnly}
505510
onBackClick={onBackClick}
506511
handleExternalWalletClick={preHandleExternalWalletClick}
507512
/>

0 commit comments

Comments
 (0)