Skip to content

Commit

Permalink
[React] Fix sign in button display logic (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges authored Nov 1, 2023
1 parent 570d71e commit 789700c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-toys-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/react": patch
---

Fix sign in connect button display logic
12 changes: 7 additions & 5 deletions packages/react/src/wallet/ConnectWallet/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = (props) => {
const { user } = useUser();
const disconnect = useDisconnect();

const shouldSignIn = !!authConfig?.authUrl && !!address && !user?.address;
const addressAndUserAddressMismatched = address !== user?.address;
const connectedButNotSignedIn =
!!authConfig?.authUrl &&
!!address &&
(!user?.address || address !== user?.address);

const requiresSignIn = props.auth?.loginOptional
? false
: shouldSignIn || addressAndUserAddressMismatched;
: connectedButNotSignedIn;

const supportedTokens = useMemo(() => {
if (!props.supportedTokens) {
Expand All @@ -195,10 +197,10 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = (props) => {

// if wallet gets disconnected, close the signature modal
useEffect(() => {
if (!activeWallet && !addressAndUserAddressMismatched) {
if (!activeWallet) {
setShowSignatureModal(false);
}
}, [activeWallet, addressAndUserAddressMismatched]);
}, [activeWallet]);

return (
<CustomThemeProvider theme={theme}>
Expand Down

0 comments on commit 789700c

Please sign in to comment.