Skip to content

Commit 7b35788

Browse files
committed
fixes metamask autoconnect in mobile
1 parent c120f3a commit 7b35788

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

packages/modal/src/modalManager.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,8 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
603603
}): Promise<void> => {
604604
try {
605605
const connector = this.getConnector(params.connector as WALLET_CONNECTOR_TYPE, params.loginParams?.chainNamespace);
606-
// auto-connect WalletConnect and non-injected MetaMask in background to generate QR code URI without interfering with user's selected connection
607-
const shouldStartConnectionInBackground =
608-
connector.name === WALLET_CONNECTORS.WALLET_CONNECT_V2 || (connector.name === WALLET_CONNECTORS.METAMASK && !connector.isInjected);
606+
// auto-connect WalletConnect in background to generate QR code URI without interfering with user's selected connection
607+
const shouldStartConnectionInBackground = connector.name === WALLET_CONNECTORS.WALLET_CONNECT_V2;
609608
if (shouldStartConnectionInBackground) {
610609
const initialChain = this.getInitialChainIdForConnector(connector);
611610
await connector.connect({ chainId: initialChain.chainId });
@@ -648,30 +647,30 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
648647
}
649648

650649
// handle MM session refresh if MM is not injected
651-
const metamaskConnector = this.getConnector(WALLET_CONNECTORS.METAMASK);
652-
if (metamaskConnector && !metamaskConnector.isInjected) {
653-
const status = metamaskConnector?.status;
654-
log.debug("trying refreshing MM session", visibility, status);
655-
if (visibility && (status === CONNECTOR_STATUS.READY || status === CONNECTOR_STATUS.CONNECTING)) {
656-
log.debug("refreshing MM session");
657-
658-
// refreshing session for MM whenever modal is opened.
659-
try {
660-
const initialChain = this.getInitialChainIdForConnector(metamaskConnector);
661-
metamaskConnector.connect({ chainId: initialChain.chainId });
662-
} catch (error) {
663-
log.error(`Error while connecting to MM`, error);
664-
}
665-
}
666-
if (
667-
!visibility &&
668-
this.status === CONNECTOR_STATUS.CONNECTED &&
669-
(status === CONNECTOR_STATUS.READY || status === CONNECTOR_STATUS.CONNECTING)
670-
) {
671-
log.debug("this stops MM connector from trying to reconnect once proposal expires");
672-
metamaskConnector.status = CONNECTOR_STATUS.READY;
673-
}
674-
}
650+
// const metamaskConnector = this.getConnector(WALLET_CONNECTORS.METAMASK);
651+
// if (metamaskConnector && !metamaskConnector.isInjected) {
652+
// const status = metamaskConnector?.status;
653+
// log.debug("trying refreshing MM session", visibility, status);
654+
// if (visibility && (status === CONNECTOR_STATUS.READY || status === CONNECTOR_STATUS.CONNECTING)) {
655+
// log.debug("refreshing MM session");
656+
657+
// // refreshing session for MM whenever modal is opened.
658+
// try {
659+
// const initialChain = this.getInitialChainIdForConnector(metamaskConnector);
660+
// metamaskConnector.connect({ chainId: initialChain.chainId });
661+
// } catch (error) {
662+
// log.error(`Error while connecting to MM`, error);
663+
// }
664+
// }
665+
// if (
666+
// !visibility &&
667+
// this.status === CONNECTOR_STATUS.CONNECTED &&
668+
// (status === CONNECTOR_STATUS.READY || status === CONNECTOR_STATUS.CONNECTING)
669+
// ) {
670+
// log.debug("this stops MM connector from trying to reconnect once proposal expires");
671+
// metamaskConnector.status = CONNECTOR_STATUS.READY;
672+
// }
673+
// }
675674
};
676675

677676
private getChainNamespaces = (): ChainNamespaceType[] => {

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,17 @@ function Login(props: LoginProps) {
356356
});
357357
// for non-injected Metamask, show QR code to connect
358358
if (wallet.name === WALLET_CONNECTORS.METAMASK && !wallet.hasInjectedWallet) {
359-
setBodyState({
360-
...bodyState,
361-
metamaskQrCode: {
362-
show: true,
363-
wallet: wallet,
364-
},
365-
});
359+
handleExternalWalletClick({ connector: wallet.name });
360+
// We should show QR code only if the wallet is not installed.
361+
if (!wallet.isInstalled) {
362+
setBodyState({
363+
...bodyState,
364+
metamaskQrCode: {
365+
show: true,
366+
wallet: wallet,
367+
},
368+
});
369+
}
366370
return;
367371
}
368372

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ function Widget(props: WidgetProps) {
185185
}
186186

187187
// auto connect to MetaMask if not injected to generate QR code URI for mobile connection
188-
const mmAvailable =
189-
modalState.externalWalletsConfig[WALLET_CONNECTORS.METAMASK] && !modalState.externalWalletsConfig[WALLET_CONNECTORS.METAMASK]?.isInjected;
190-
if (mmAvailable && !modalState.metamaskConnectUri && typeof handleExternalWalletClick === "function") {
191-
handleExternalWalletClick({ connector: WALLET_CONNECTORS.METAMASK });
192-
}
188+
// const mmAvailable =
189+
// modalState.externalWalletsConfig[WALLET_CONNECTORS.METAMASK] && !modalState.externalWalletsConfig[WALLET_CONNECTORS.METAMASK]?.isInjected;
190+
// if (mmAvailable && !modalState.metamaskConnectUri && typeof handleExternalWalletClick === "function") {
191+
// handleExternalWalletClick({ connector: WALLET_CONNECTORS.METAMASK });
192+
// }
193193
}
194194
}, [modalState, handleExternalWalletClick]);
195195

0 commit comments

Comments
 (0)