Commit 663171f3 authored by Max Alekseenko's avatar Max Alekseenko

fix tooltip

parent cb844b8a
...@@ -70,13 +70,13 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { ...@@ -70,13 +70,13 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
isOpen={ isPopoverOpen } isOpen={ isPopoverOpen }
onClose={ setIsPopoverOpen.off } onClose={ setIsPopoverOpen.off }
> >
<WalletTooltip <Box ml={ 2 }>
isDisabled={ isMobile === undefined || isMobile } <PopoverTrigger>
isWalletConnected={ isWalletConnected } <WalletTooltip
isAutoConnectDisabled={ isAutoConnectDisabled } isDisabled={ isMobile === undefined || isMobile }
> isWalletConnected={ isWalletConnected }
<Box ml={ 2 }> isAutoConnectDisabled={ isAutoConnectDisabled }
<PopoverTrigger> >
<Button <Button
className={ className } className={ className }
variant={ variant } variant={ variant }
...@@ -96,9 +96,9 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { ...@@ -96,9 +96,9 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
</> </>
) : 'Connect wallet' } ) : 'Connect wallet' }
</Button> </Button>
</PopoverTrigger> </WalletTooltip>
</Box> </PopoverTrigger>
</WalletTooltip> </Box>
{ isWalletConnected && ( { isWalletConnected && (
<PopoverContent w="235px"> <PopoverContent w="235px">
<PopoverBody padding="24px 16px 16px 16px"> <PopoverBody padding="24px 16px 16px 16px">
......
import { Tooltip, useBoolean, useOutsideClick } from '@chakra-ui/react'; import { Tooltip, useBoolean, useOutsideClick, Box } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
...@@ -15,11 +15,11 @@ type Props = { ...@@ -15,11 +15,11 @@ type Props = {
const LOCAL_STORAGE_KEY = 'wallet-connect-tooltip-shown'; const LOCAL_STORAGE_KEY = 'wallet-connect-tooltip-shown';
const WalletTooltip = ({ children, isDisabled, isMobile, isWalletConnected, isAutoConnectDisabled }: Props) => { const WalletTooltip = ({ children, isDisabled, isMobile, isWalletConnected, isAutoConnectDisabled }: Props, ref: React.ForwardedRef<HTMLDivElement>) => {
const router = useRouter(); const router = useRouter();
const [ isTooltipShown, setIsTooltipShown ] = useBoolean(false); const [ isTooltipShown, setIsTooltipShown ] = useBoolean(false);
const ref = React.useRef(null); const innerRef = React.useRef(null);
useOutsideClick({ ref, handler: setIsTooltipShown.off }); useOutsideClick({ ref: innerRef, handler: setIsTooltipShown.off });
const label = React.useMemo(() => { const label = React.useMemo(() => {
if (isWalletConnected) { if (isWalletConnected) {
...@@ -62,20 +62,22 @@ const WalletTooltip = ({ children, isDisabled, isMobile, isWalletConnected, isAu ...@@ -62,20 +62,22 @@ const WalletTooltip = ({ children, isDisabled, isMobile, isWalletConnected, isAu
}, [ setIsTooltipShown, isDisabled, router, isAppPage ]); }, [ setIsTooltipShown, isDisabled, router, isAppPage ]);
return ( return (
<Tooltip <Box ref={ ref }>
label={ label } <Tooltip
textAlign="center" label={ label }
padding={ 2 } textAlign="center"
isDisabled={ isDisabled || (isWalletConnected && !isAppPage) } padding={ 2 }
openDelay={ 500 } isDisabled={ isDisabled || (isWalletConnected && !isAppPage) }
isOpen={ isTooltipShown || (isMobile ? false : undefined) } openDelay={ 500 }
onClose={ setIsTooltipShown.off } isOpen={ isTooltipShown || (isMobile ? false : undefined) }
display={ isMobile ? { base: 'flex', lg: 'none' } : { base: 'none', lg: 'flex' } } onClose={ setIsTooltipShown.off }
ref={ ref } display={ isMobile ? { base: 'flex', lg: 'none' } : { base: 'none', lg: 'flex' } }
> ref={ innerRef }
{ children } >
</Tooltip> { children }
</Tooltip>
</Box>
); );
}; };
export default WalletTooltip; export default React.forwardRef(WalletTooltip);
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