Skip to content

[react] Remove unnecessary ConnectModal opening #2375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silly-moles-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@thirdweb-dev/react": patch
---

Remove unnecessary ConnectModal auto opening.

This also fixes the issue where Connect Modal opens on page load when `ThirdwebProvider` is dynamically imported and rendered in the app.
34 changes: 0 additions & 34 deletions packages/react/src/wallet/ConnectWallet/Modal/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useDisconnect,
useThirdwebAuthContext,
useUser,
useWallet,
useWalletContext,
useWallets,
} from "@thirdweb-dev/react-core";
Expand Down Expand Up @@ -241,41 +240,8 @@ export const ConnectModal = () => {
});
}, [initialScreen, setIsWalletModalOpen, setScreen]);

const [prevConnectionStatus, setPrevConnectionStatus] =
useState(connectionStatus);

useEffect(() => {
setPrevConnectionStatus(connectionStatus);
}, [connectionStatus]);

const disconnect = useDisconnect();

const wallet = useWallet();
const isWrapperConnected = !!wallet?.getPersonalWallet();

const isWrapperScreen =
typeof screen !== "string" && !!screen.personalWallets;

// reopen the screen to complete wrapper wallet's next step after connecting a personal wallet
useEffect(() => {
if (
!isWrapperConnected &&
isWrapperScreen &&
!isWalletModalOpen &&
connectionStatus === "connected" &&
prevConnectionStatus === "connecting"
) {
setIsWalletModalOpen(true);
}
}, [
isWalletModalOpen,
connectionStatus,
setIsWalletModalOpen,
isWrapperScreen,
isWrapperConnected,
prevConnectionStatus,
]);

useEffect(() => {
if (!isWalletModalOpen) {
onModalUnmount(() => {
Expand Down