Commit 3504d596 authored by tom goriunov's avatar tom goriunov Committed by GitHub

Merge pull request #1450 from blockscout/new-tooltip-for-connect-wallet-button

Add new text for `connect wallet` button tooltip
parents af9693d7 4bc4e408
...@@ -2,6 +2,7 @@ import type { ButtonProps } from '@chakra-ui/react'; ...@@ -2,6 +2,7 @@ import type { ButtonProps } from '@chakra-ui/react';
import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button, Box, useBoolean } from '@chakra-ui/react'; import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button, Box, useBoolean } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useIsMobile from 'lib/hooks/useIsMobile';
import AddressIdenticon from 'ui/shared/entities/address/AddressIdenticon'; import AddressIdenticon from 'ui/shared/entities/address/AddressIdenticon';
import HashStringShorten from 'ui/shared/HashStringShorten'; import HashStringShorten from 'ui/shared/HashStringShorten';
import useWallet from 'ui/snippets/walletMenu/useWallet'; import useWallet from 'ui/snippets/walletMenu/useWallet';
...@@ -18,6 +19,7 @@ const WalletMenuDesktop = ({ isHomePage }: Props) => { ...@@ -18,6 +19,7 @@ const WalletMenuDesktop = ({ isHomePage }: Props) => {
const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet(); const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet();
const { themedBackground, themedBorderColor, themedColor } = useMenuButtonColors(); const { themedBackground, themedBorderColor, themedColor } = useMenuButtonColors();
const [ isPopoverOpen, setIsPopoverOpen ] = useBoolean(false); const [ isPopoverOpen, setIsPopoverOpen ] = useBoolean(false);
const isMobile = useIsMobile();
const variant = React.useMemo(() => { const variant = React.useMemo(() => {
if (isWalletConnected) { if (isWalletConnected) {
...@@ -55,7 +57,7 @@ const WalletMenuDesktop = ({ isHomePage }: Props) => { ...@@ -55,7 +57,7 @@ const WalletMenuDesktop = ({ isHomePage }: Props) => {
isOpen={ isPopoverOpen } isOpen={ isPopoverOpen }
onClose={ setIsPopoverOpen.off } onClose={ setIsPopoverOpen.off }
> >
<WalletTooltip isDisabled={ isWalletConnected }> <WalletTooltip isDisabled={ isWalletConnected || isMobile === undefined || isMobile }>
<Box ml={ 2 }> <Box ml={ 2 }>
<PopoverTrigger> <PopoverTrigger>
<Button <Button
......
...@@ -2,6 +2,7 @@ import { Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclosure, IconBu ...@@ -2,6 +2,7 @@ import { Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclosure, IconBu
import React from 'react'; import React from 'react';
import walletIcon from 'icons/wallet.svg'; import walletIcon from 'icons/wallet.svg';
import useIsMobile from 'lib/hooks/useIsMobile';
import AddressIdenticon from 'ui/shared/entities/address/AddressIdenticon'; import AddressIdenticon from 'ui/shared/entities/address/AddressIdenticon';
import useWallet from 'ui/snippets/walletMenu/useWallet'; import useWallet from 'ui/snippets/walletMenu/useWallet';
import WalletMenuContent from 'ui/snippets/walletMenu/WalletMenuContent'; import WalletMenuContent from 'ui/snippets/walletMenu/WalletMenuContent';
...@@ -13,10 +14,11 @@ const WalletMenuMobile = () => { ...@@ -13,10 +14,11 @@ const WalletMenuMobile = () => {
const { isOpen, onOpen, onClose } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();
const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet(); const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet();
const { themedBackground, themedBorderColor, themedColor } = useMenuButtonColors(); const { themedBackground, themedBorderColor, themedColor } = useMenuButtonColors();
const isMobile = useIsMobile();
return ( return (
<> <>
<WalletTooltip isDisabled={ isWalletConnected } isMobile> <WalletTooltip isDisabled={ isWalletConnected || isMobile === undefined || !isMobile } isMobile>
<IconButton <IconButton
aria-label="wallet menu" aria-label="wallet menu"
icon={ isWalletConnected ? icon={ isWalletConnected ?
......
import { Tooltip, useBoolean, useOutsideClick } from '@chakra-ui/react'; import { Tooltip, useBoolean, useOutsideClick } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
type Props = { type Props = {
...@@ -8,22 +9,33 @@ type Props = { ...@@ -8,22 +9,33 @@ type Props = {
}; };
const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => { const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => {
const router = useRouter();
const [ isTooltipShown, setIsTooltipShown ] = useBoolean(false); const [ isTooltipShown, setIsTooltipShown ] = useBoolean(false);
const ref = React.useRef(null); const ref = React.useRef(null);
useOutsideClick({ ref, handler: setIsTooltipShown.off }); useOutsideClick({ ref, handler: setIsTooltipShown.off });
const { defaultLabel, label, localStorageKey } = React.useMemo(() => {
const isAppPage = router.pathname === '/apps/[id]';
const defaultLabel = <span>Your wallet is used to interact with<br/>apps and contracts in the explorer</span>;
const label = isAppPage ?
<span>Connect once to use your wallet with<br/>all apps in the DAppscout marketplace!</span> :
defaultLabel;
const localStorageKey = `${ isAppPage ? 'dapp-' : '' }wallet-connect-tooltip-shown`;
return { defaultLabel, label, localStorageKey };
}, [ router.pathname ]);
React.useEffect(() => { React.useEffect(() => {
const key = `wallet-connect-tooltip-shown-${ isMobile ? 'mobile' : 'desktop' }`; const wasShown = window.localStorage.getItem(localStorageKey);
const wasShown = window.localStorage.getItem(key); if (!isDisabled && !wasShown) {
if (!wasShown) {
setIsTooltipShown.on(); setIsTooltipShown.on();
window.localStorage.setItem(key, 'true'); window.localStorage.setItem(localStorageKey, 'true');
setTimeout(() => setIsTooltipShown.off(), 3000);
} }
}, [ setIsTooltipShown, isMobile ]); }, [ setIsTooltipShown, localStorageKey, isDisabled ]);
return ( return (
<Tooltip <Tooltip
label={ <span>Your wallet is used to interact with<br/>apps and contracts in the explorer</span> } label={ isTooltipShown ? label : defaultLabel }
textAlign="center" textAlign="center"
padding={ 2 } padding={ 2 }
isDisabled={ isDisabled } isDisabled={ isDisabled }
......
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