Commit 261724c4 authored by tom's avatar tom

fix behaviour "connect wallet" button on contract page

parent 45aac833
...@@ -5,29 +5,15 @@ import config from 'configs/app'; ...@@ -5,29 +5,15 @@ import config from 'configs/app';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import useWeb3Wallet from 'lib/web3/useWallet'; import useWeb3Wallet from 'lib/web3/useWallet';
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import AddressEntity from 'ui/shared/entities/address/AddressEntity';
import useIsAuth from 'ui/snippets/auth/useIsAuth';
import useSignInWithWallet from 'ui/snippets/auth/useSignInWithWallet';
interface Props { interface Props {
isLoading?: boolean; isLoading?: boolean;
} }
const ContractConnectWallet = ({ isLoading }: Props) => { const ContractConnectWallet = ({ isLoading }: Props) => {
const signInWithWallet = useSignInWithWallet({ source: 'Smart contracts' });
const isAuth = useIsAuth();
const web3Wallet = useWeb3Wallet({ source: 'Smart contracts' }); const web3Wallet = useWeb3Wallet({ source: 'Smart contracts' });
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const shouldSignIn = config.features.account.isEnabled && !isAuth;
const handleConnectClick = React.useCallback(() => {
if (shouldSignIn) {
signInWithWallet.start();
} else {
web3Wallet.connect();
}
}, [ signInWithWallet, web3Wallet, shouldSignIn ]);
const content = (() => { const content = (() => {
if (!web3Wallet.isConnected) { if (!web3Wallet.isConnected) {
return ( return (
...@@ -35,10 +21,10 @@ const ContractConnectWallet = ({ isLoading }: Props) => { ...@@ -35,10 +21,10 @@ const ContractConnectWallet = ({ isLoading }: Props) => {
<span>Disconnected</span> <span>Disconnected</span>
<Button <Button
ml={ 3 } ml={ 3 }
onClick={ handleConnectClick } onClick={ web3Wallet.connect }
size="sm" size="sm"
variant="outline" variant="outline"
isLoading={ shouldSignIn ? signInWithWallet.isPending : web3Wallet.isOpen } isLoading={ web3Wallet.isOpen }
loadingText="Connect wallet" loadingText="Connect wallet"
> >
Connect wallet Connect wallet
......
...@@ -27,7 +27,7 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }: ...@@ -27,7 +27,7 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }:
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const { data, isLoading } = profileQuery; const { data, isLoading } = profileQuery;
const web3AccountWithDomain = useWeb3AccountWithDomain(!data?.address_hash); const web3AccountWithDomain = useWeb3AccountWithDomain(true);
const { isAutoConnectDisabled } = useMarketplaceContext(); const { isAutoConnectDisabled } = useMarketplaceContext();
React.useEffect(() => { React.useEffect(() => {
...@@ -37,10 +37,6 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }: ...@@ -37,10 +37,6 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }:
}, [ isLoading ]); }, [ isLoading ]);
const content = (() => { const content = (() => {
if (!data) {
return 'Log in';
}
if (web3AccountWithDomain.address) { if (web3AccountWithDomain.address) {
return ( return (
<HStack gap={ 2 }> <HStack gap={ 2 }>
...@@ -52,6 +48,10 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }: ...@@ -52,6 +48,10 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }:
); );
} }
if (!data) {
return 'Log in';
}
return ( return (
<HStack gap={ 2 }> <HStack gap={ 2 }>
<IconSvg name="profile" boxSize={ 5 }/> <IconSvg name="profile" boxSize={ 5 }/>
...@@ -73,7 +73,7 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }: ...@@ -73,7 +73,7 @@ const UserProfileButton = ({ profileQuery, size, variant, onClick, isPending }:
size={ size } size={ size }
variant={ variant } variant={ variant }
onClick={ onClick } onClick={ onClick }
data-selected={ Boolean(data) } data-selected={ Boolean(data) || Boolean(web3AccountWithDomain.address) }
data-warning={ isAutoConnectDisabled } data-warning={ isAutoConnectDisabled }
fontSize="sm" fontSize="sm"
lineHeight={ 5 } lineHeight={ 5 }
......
import { Box, Divider, Flex, Link, VStack } from '@chakra-ui/react'; import { Box, Button, Divider, Flex, Link, VStack } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import type { NavLink } from './types'; import type { NavLink } from './types';
...@@ -46,16 +46,27 @@ const navLinks: Array<NavLink> = [ ...@@ -46,16 +46,27 @@ const navLinks: Array<NavLink> = [
].filter(Boolean); ].filter(Boolean);
interface Props { interface Props {
data: UserInfo; data: UserInfo | undefined;
onClose: () => void; onClose: () => void;
onLogin: () => void;
onAddEmail: () => void; onAddEmail: () => void;
onAddAddress: () => void; onAddAddress: () => void;
} }
const UserProfileContent = ({ data, onClose, onAddEmail, onAddAddress }: Props) => { const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress }: Props) => {
const { isAutoConnectDisabled } = useMarketplaceContext(); const { isAutoConnectDisabled } = useMarketplaceContext();
const logout = useLogout(); const logout = useLogout();
if (!data) {
return (
<Box>
{ isAutoConnectDisabled && <UserWalletAutoConnectAlert/> }
{ config.features.blockchainInteraction.isEnabled && <UserProfileContentWallet onClose={ onClose }/> }
<Button mt={ 3 } onClick={ onLogin } size="sm" w="100%">Log in</Button>
</Box>
);
}
return ( return (
<Box> <Box>
{ isAutoConnectDisabled && <UserWalletAutoConnectAlert/> } { isAutoConnectDisabled && <UserWalletAutoConnectAlert/> }
...@@ -65,6 +76,7 @@ const UserProfileContent = ({ data, onClose, onAddEmail, onAddAddress }: Props) ...@@ -65,6 +76,7 @@ const UserProfileContent = ({ data, onClose, onAddEmail, onAddAddress }: Props)
href={ route({ pathname: '/auth/profile' }) } href={ route({ pathname: '/auth/profile' }) }
icon="profile" icon="profile"
onClick={ onClose } onClick={ onClose }
py="8px"
/> />
<Box fontSize="xs" lineHeight={ 4 } fontWeight="500" borderColor="divider" borderWidth="1px" borderRadius="base"> <Box fontSize="xs" lineHeight={ 4 } fontWeight="500" borderColor="divider" borderWidth="1px" borderRadius="base">
...@@ -85,7 +97,7 @@ const UserProfileContent = ({ data, onClose, onAddEmail, onAddAddress }: Props) ...@@ -85,7 +97,7 @@ const UserProfileContent = ({ data, onClose, onAddEmail, onAddAddress }: Props)
</Flex> </Flex>
</Box> </Box>
{ config.features.blockchainInteraction.isEnabled ? <UserProfileContentWallet onClose={ onClose }/> : <Divider/> } { config.features.blockchainInteraction.isEnabled && <UserProfileContentWallet onClose={ onClose } mt={ 3 }/> }
<VStack as="ul" spacing="0" alignItems="flex-start" overflow="hidden" mt={ 3 }> <VStack as="ul" spacing="0" alignItems="flex-start" overflow="hidden" mt={ 3 }>
{ navLinks.map((item) => ( { navLinks.map((item) => (
......
import type { SpaceProps } from '@chakra-ui/react';
import { Box } from '@chakra-ui/react'; import { Box } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
...@@ -6,9 +7,11 @@ import type { NavLink } from './types'; ...@@ -6,9 +7,11 @@ import type { NavLink } from './types';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
import LinkInternal from 'ui/shared/links/LinkInternal'; import LinkInternal from 'ui/shared/links/LinkInternal';
type Props = NavLink type Props = NavLink & {
py?: SpaceProps['py'];
}
const UserProfileContentNavLink = ({ href, icon, text, onClick }: Props) => { const UserProfileContentNavLink = ({ href, icon, text, onClick, py }: Props) => {
return ( return (
<LinkInternal <LinkInternal
...@@ -16,7 +19,7 @@ const UserProfileContentNavLink = ({ href, icon, text, onClick }: Props) => { ...@@ -16,7 +19,7 @@ const UserProfileContentNavLink = ({ href, icon, text, onClick }: Props) => {
display="flex" display="flex"
alignItems="center" alignItems="center"
columnGap={ 3 } columnGap={ 3 }
py="14px" py={ py ?? '14px' }
color="initial" color="initial"
_hover={{ textDecoration: 'none', color: 'link_hovered' }} _hover={{ textDecoration: 'none', color: 'link_hovered' }}
onClick={ onClick } onClick={ onClick }
......
import { Box, Button, Flex, IconButton, useColorModeValue } from '@chakra-ui/react'; import { chakra, Box, Button, Flex, IconButton, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import delay from 'lib/delay'; import delay from 'lib/delay';
...@@ -10,9 +10,10 @@ import IconSvg from 'ui/shared/IconSvg'; ...@@ -10,9 +10,10 @@ import IconSvg from 'ui/shared/IconSvg';
interface Props { interface Props {
onClose?: () => void; onClose?: () => void;
className?: string;
} }
const UserProfileContentWallet = ({ onClose }: Props) => { const UserProfileContentWallet = ({ onClose, className }: Props) => {
const walletSnippetBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50'); const walletSnippetBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
const web3Wallet = useWeb3Wallet({ source: 'Profile dropdown' }); const web3Wallet = useWeb3Wallet({ source: 'Profile dropdown' });
...@@ -70,7 +71,7 @@ const UserProfileContentWallet = ({ onClose }: Props) => { ...@@ -70,7 +71,7 @@ const UserProfileContentWallet = ({ onClose }: Props) => {
})(); })();
return ( return (
<Box mt={ 3 }> <Box className={ className }>
<Flex px={ 2 } py={ 1 } mb={ 1 } fontSize="xs" lineHeight={ 4 } fontWeight="500"> <Flex px={ 2 } py={ 1 } mb={ 1 } fontSize="xs" lineHeight={ 4 } fontWeight="500">
<span>Wallet for apps or contracts</span> <span>Wallet for apps or contracts</span>
<Hint label="Wallet for apps or contracts" boxSize={ 4 } ml={ 1 }/> <Hint label="Wallet for apps or contracts" boxSize={ 4 } ml={ 1 }/>
...@@ -80,4 +81,4 @@ const UserProfileContentWallet = ({ onClose }: Props) => { ...@@ -80,4 +81,4 @@ const UserProfileContentWallet = ({ onClose }: Props) => {
); );
}; };
export default React.memo(UserProfileContentWallet); export default React.memo(chakra(UserProfileContentWallet));
...@@ -6,6 +6,7 @@ import type { Screen } from 'ui/snippets/auth/types'; ...@@ -6,6 +6,7 @@ import type { Screen } from 'ui/snippets/auth/types';
import config from 'configs/app'; import config from 'configs/app';
import * as mixpanel from 'lib/mixpanel'; import * as mixpanel from 'lib/mixpanel';
import useAccount from 'lib/web3/useAccount';
import Popover from 'ui/shared/chakra/Popover'; import Popover from 'ui/shared/chakra/Popover';
import AuthModal from 'ui/snippets/auth/AuthModal'; import AuthModal from 'ui/snippets/auth/AuthModal';
import useProfileQuery from 'ui/snippets/auth/useProfileQuery'; import useProfileQuery from 'ui/snippets/auth/useProfileQuery';
...@@ -30,9 +31,10 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => ...@@ -30,9 +31,10 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) =>
const profileQuery = useProfileQuery(); const profileQuery = useProfileQuery();
const signInWithWallet = useSignInWithWallet({}); const signInWithWallet = useSignInWithWallet({});
const { address: web3Address } = useAccount();
const handleProfileButtonClick = React.useCallback(() => { const handleProfileButtonClick = React.useCallback(() => {
if (profileQuery.data) { if (profileQuery.data || web3Address) {
mixpanel.logEvent(mixpanel.EventTypes.ACCOUNT_ACCESS, { Action: 'Dropdown open' }); mixpanel.logEvent(mixpanel.EventTypes.ACCOUNT_ACCESS, { Action: 'Dropdown open' });
profileMenu.onOpen(); profileMenu.onOpen();
return; return;
...@@ -44,7 +46,7 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => ...@@ -44,7 +46,7 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) =>
} }
authModal.onOpen(); authModal.onOpen();
}, [ profileQuery.data, router.pathname, authModal, profileMenu, signInWithWallet ]); }, [ profileQuery.data, router.pathname, authModal, profileMenu, signInWithWallet, web3Address ]);
const handleAddEmailClick = React.useCallback(() => { const handleAddEmailClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'email', isAuth: true }); setAuthInitialScreen({ type: 'email', isAuth: true });
...@@ -68,12 +70,13 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => ...@@ -68,12 +70,13 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) =>
isPending={ signInWithWallet.isPending } isPending={ signInWithWallet.isPending }
/> />
</PopoverTrigger> </PopoverTrigger>
{ profileQuery.data && ( { (profileQuery.data || web3Address) && (
<PopoverContent w="280px"> <PopoverContent w="280px">
<PopoverBody> <PopoverBody>
<UserProfileContent <UserProfileContent
data={ profileQuery.data } data={ profileQuery.data }
onClose={ profileMenu.onClose } onClose={ profileMenu.onClose }
onLogin={ authModal.onOpen }
onAddEmail={ handleAddEmailClick } onAddEmail={ handleAddEmailClick }
onAddAddress={ handleAddAddressClick } onAddAddress={ handleAddAddressClick }
/> />
......
...@@ -6,6 +6,7 @@ import type { Screen } from 'ui/snippets/auth/types'; ...@@ -6,6 +6,7 @@ import type { Screen } from 'ui/snippets/auth/types';
import config from 'configs/app'; import config from 'configs/app';
import * as mixpanel from 'lib/mixpanel'; import * as mixpanel from 'lib/mixpanel';
import useAccount from 'lib/web3/useAccount';
import AuthModal from 'ui/snippets/auth/AuthModal'; import AuthModal from 'ui/snippets/auth/AuthModal';
import useProfileQuery from 'ui/snippets/auth/useProfileQuery'; import useProfileQuery from 'ui/snippets/auth/useProfileQuery';
import useSignInWithWallet from 'ui/snippets/auth/useSignInWithWallet'; import useSignInWithWallet from 'ui/snippets/auth/useSignInWithWallet';
...@@ -24,9 +25,10 @@ const UserProfileMobile = () => { ...@@ -24,9 +25,10 @@ const UserProfileMobile = () => {
const profileQuery = useProfileQuery(); const profileQuery = useProfileQuery();
const signInWithWallet = useSignInWithWallet({}); const signInWithWallet = useSignInWithWallet({});
const { address: web3Address } = useAccount();
const handleProfileButtonClick = React.useCallback(() => { const handleProfileButtonClick = React.useCallback(() => {
if (profileQuery.data) { if (profileQuery.data || web3Address) {
mixpanel.logEvent(mixpanel.EventTypes.ACCOUNT_ACCESS, { Action: 'Dropdown open' }); mixpanel.logEvent(mixpanel.EventTypes.ACCOUNT_ACCESS, { Action: 'Dropdown open' });
profileMenu.onOpen(); profileMenu.onOpen();
return; return;
...@@ -38,7 +40,7 @@ const UserProfileMobile = () => { ...@@ -38,7 +40,7 @@ const UserProfileMobile = () => {
} }
authModal.onOpen(); authModal.onOpen();
}, [ profileQuery.data, router.pathname, authModal, profileMenu, signInWithWallet ]); }, [ profileQuery.data, web3Address, router.pathname, authModal, profileMenu, signInWithWallet ]);
const handleAddEmailClick = React.useCallback(() => { const handleAddEmailClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'email', isAuth: true }); setAuthInitialScreen({ type: 'email', isAuth: true });
...@@ -57,7 +59,7 @@ const UserProfileMobile = () => { ...@@ -57,7 +59,7 @@ const UserProfileMobile = () => {
variant="header" variant="header"
onClick={ handleProfileButtonClick } onClick={ handleProfileButtonClick }
/> />
{ profileQuery.data && ( { (profileQuery.data || web3Address) && (
<Drawer <Drawer
isOpen={ profileMenu.isOpen } isOpen={ profileMenu.isOpen }
placement="right" placement="right"
...@@ -70,6 +72,7 @@ const UserProfileMobile = () => { ...@@ -70,6 +72,7 @@ const UserProfileMobile = () => {
<UserProfileContent <UserProfileContent
data={ profileQuery.data } data={ profileQuery.data }
onClose={ profileMenu.onClose } onClose={ profileMenu.onClose }
onLogin={ authModal.onOpen }
onAddEmail={ handleAddEmailClick } onAddEmail={ handleAddEmailClick }
onAddAddress={ handleAddAddressClick } onAddAddress={ handleAddAddressClick }
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment