Skip to content

Commit 3fd7430

Browse files
committed
show loader when connecting to Metamask on mobile
1 parent bcc92c4 commit 3fd7430

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { WALLET_CONNECTORS, type WalletRegistryItem } from "@web3auth/no-modal";
2-
import Bowser from "bowser";
32
import { JSX, useCallback, useContext, useMemo, useState } from "react";
43
import { useTranslation } from "react-i18next";
54

65
import { CONNECT_WALLET_PAGES, DEFAULT_METAMASK_WALLET_REGISTRY_ITEM, PAGES } from "../../constants";
76
import { BodyState, RootContext } from "../../context/RootContext";
87
import { ThemedContext } from "../../context/ThemeContext";
9-
import { browser, ExternalButton, mobileOs, MODAL_STATUS, os, platform, TOAST_TYPE, ToastType } from "../../interfaces";
8+
import { ExternalButton, mobileOs, MODAL_STATUS, TOAST_TYPE, ToastType } from "../../interfaces";
109
import i18n from "../../localeImport";
1110
import { cn, getBrowserExtensionUrl, getBrowserName, getIcons, getMobileInstallLink, getOsName } from "../../utils";
1211
import BottomSheet from "../BottomSheet";
@@ -42,6 +41,7 @@ function Root(props: RootProps) {
4241
isSmsPasswordLessLoginVisible,
4342
preHandleExternalWalletClick,
4443
uiConfig,
44+
deviceDetails,
4545
} = props;
4646

4747
const {
@@ -99,16 +99,6 @@ function Root(props: RootProps) {
9999
};
100100

101101
// Wallet Details
102-
const deviceDetails = useMemo<{ platform: platform; browser: browser; os: mobileOs }>(() => {
103-
if (typeof window === "undefined") return { platform: "mobile", browser: "chrome", os: "ios" };
104-
const browserData = Bowser.getParser(window.navigator.userAgent);
105-
return {
106-
platform: browserData.getPlatformType() as platform,
107-
browser: browserData.getBrowserName().toLowerCase() as browser,
108-
os: browserData.getOSName() as mobileOs,
109-
};
110-
}, []);
111-
112102
const mobileInstallLinks = useMemo<JSX.Element[]>(() => {
113103
if (deviceDetails.platform === "desktop") return [];
114104
const installConfig = bodyState.installLinks?.wallet?.walletRegistryItem?.app || {};
@@ -490,11 +480,7 @@ function Root(props: RootProps) {
490480
totalExternalWallets={totalExternalWallets}
491481
logoAlignment={logoAlignment}
492482
buttonRadius={buttonRadiusType}
493-
deviceDetails={{
494-
platform: deviceDetails.platform,
495-
browser: deviceDetails.browser,
496-
os: deviceDetails.os as os,
497-
}}
483+
deviceDetails={deviceDetails}
498484
handleSocialLoginClick={handleSocialLoginClick}
499485
handleExternalWalletBtnClick={onExternalWalletBtnClick}
500486
handleSocialLoginHeight={handleSocialLoginHeight}
@@ -512,11 +498,7 @@ function Root(props: RootProps) {
512498
allExternalButtons={allButtons}
513499
connectorVisibilityMap={connectorVisibilityMap}
514500
customConnectorButtons={customConnectorButtons}
515-
deviceDetails={{
516-
platform: deviceDetails.platform,
517-
browser: deviceDetails.browser,
518-
os: deviceDetails.os as os,
519-
}}
501+
deviceDetails={deviceDetails}
520502
chainNamespace={chainNamespaces}
521503
buttonRadius={buttonRadiusType}
522504
handleWalletDetailsHeight={handleWalletDetailsHeight}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ChainNamespaceType, WalletRegistry } from "@web3auth/no-modal";
22

3-
import { ModalState, SocialLoginEventType, SocialLoginsConfig, UIConfig } from "../../interfaces";
3+
import { browser, ModalState, os, platform, SocialLoginEventType, SocialLoginsConfig, UIConfig } from "../../interfaces";
44

55
export interface RootProps {
66
appLogo?: string;
@@ -18,6 +18,7 @@ export interface RootProps {
1818
isEmailPasswordLessLoginVisible: boolean;
1919
isSmsPasswordLessLoginVisible: boolean;
2020
uiConfig: UIConfig;
21+
deviceDetails: { platform: platform; browser: browser; os: os };
2122
handleSocialLoginClick: (params: SocialLoginEventType) => void;
2223
handleExternalWalletBtnClick?: (flag: boolean) => void;
2324
preHandleExternalWalletClick: (params: { connector: string; chainNamespace?: ChainNamespaceType }) => void;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function Widget(props: WidgetProps) {
2222
chainNamespaces,
2323
walletRegistry,
2424
uiConfig,
25+
deviceDetails,
2526
} = props;
2627

2728
const { widgetType } = uiConfig;
@@ -219,6 +220,7 @@ function Widget(props: WidgetProps) {
219220
isEmailPasswordLessLoginVisible={isEmailPasswordLessLoginVisible}
220221
isSmsPasswordLessLoginVisible={isSmsPasswordLessLoginVisible}
221222
uiConfig={uiConfig}
223+
deviceDetails={deviceDetails}
222224
/>
223225
)}
224226
</Modal>
@@ -250,6 +252,7 @@ function Widget(props: WidgetProps) {
250252
isEmailPasswordLessLoginVisible={isEmailPasswordLessLoginVisible}
251253
isSmsPasswordLessLoginVisible={isSmsPasswordLessLoginVisible}
252254
uiConfig={uiConfig}
255+
deviceDetails={deviceDetails}
253256
/>
254257
)}
255258
</Embed>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { SafeEventEmitter } from "@web3auth/auth";
22
import { ChainNamespaceType, WalletRegistry } from "@web3auth/no-modal";
33

4-
import { ExternalWalletEventType, SocialLoginEventType, StateEmitterEvents, UIConfig } from "../../interfaces";
4+
import { browser, ExternalWalletEventType, os, platform, SocialLoginEventType, StateEmitterEvents, UIConfig } from "../../interfaces";
55

66
export interface WidgetProps {
77
stateListener: SafeEventEmitter<StateEmitterEvents>;
88
appLogo?: string;
99
appName?: string;
1010
chainNamespaces: ChainNamespaceType[];
1111
walletRegistry?: WalletRegistry;
12+
uiConfig: UIConfig;
13+
deviceDetails: { platform: platform; browser: browser; os: os };
1214
handleSocialLoginClick: (params: SocialLoginEventType) => void;
1315
handleExternalWalletClick: (params: ExternalWalletEventType) => void;
1416
handleShowExternalWallets: (externalWalletsInitialized: boolean) => void;
1517
closeModal: () => void;
16-
uiConfig: UIConfig;
1718
}

packages/modal/src/ui/loginModal.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
type Web3AuthNoModalEvents,
2727
WIDGET_TYPE,
2828
} from "@web3auth/no-modal";
29+
import Bowser from "bowser";
2930
import { createRoot } from "react-dom/client";
3031

3132
import { getLoginModalAnalyticsProperties } from "../utils";
@@ -34,11 +35,14 @@ import { DEFAULT_LOGO_DARK, DEFAULT_LOGO_LIGHT, DEFAULT_ON_PRIMARY_COLOR, DEFAUL
3435
import { AnalyticsContext } from "./context/AnalyticsContext";
3536
import { ThemedContext } from "./context/ThemeContext";
3637
import {
38+
browser,
3739
ExternalWalletEventType,
3840
LoginModalCallbacks,
3941
LoginModalProps,
4042
MODAL_STATUS,
4143
ModalState,
44+
os,
45+
platform,
4246
SocialLoginEventType,
4347
StateEmitterEvents,
4448
UIConfig,
@@ -112,6 +116,16 @@ export class LoginModal {
112116
return this.uiConfig.mode === "dark" || (this.uiConfig.mode === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches);
113117
}
114118

119+
get deviceDetails() {
120+
if (typeof window === "undefined") return { platform: "mobile" as platform, browser: "chrome" as browser, os: "ios" as os };
121+
const browserData = Bowser.getParser(window.navigator.userAgent);
122+
return {
123+
platform: browserData.getPlatformType() as platform,
124+
browser: browserData.getBrowserName().toLowerCase() as browser,
125+
os: browserData.getOSName() as os,
126+
};
127+
}
128+
115129
initModal = async (): Promise<void> => {
116130
const darkState = { isDark: this.isDark };
117131

@@ -249,6 +263,7 @@ export class LoginModal {
249263
appName={this.uiConfig.appName}
250264
chainNamespaces={this.chainNamespaces}
251265
walletRegistry={this.walletRegistry}
266+
deviceDetails={this.deviceDetails}
252267
handleShowExternalWallets={this.handleShowExternalWallets}
253268
handleExternalWalletClick={this.handleExternalWalletClick}
254269
handleSocialLoginClick={this.handleSocialLoginClick}
@@ -394,7 +409,7 @@ export class LoginModal {
394409

395410
// don't show loader in case of metamask qr code, because currently it listens for incoming connections without any user interaction
396411
const isMetamaskInjected = this.externalWalletsConfig?.[WALLET_CONNECTORS.METAMASK]?.isInjected;
397-
if (data?.connector === WALLET_CONNECTORS.METAMASK && !isMetamaskInjected) return;
412+
if (data?.connector === WALLET_CONNECTORS.METAMASK && !isMetamaskInjected && this.deviceDetails.platform === "desktop") return;
398413

399414
this.setState({ status: MODAL_STATUS.CONNECTING });
400415
});

0 commit comments

Comments
 (0)