Commit 847ec0a2 authored by Max Alekseenko's avatar Max Alekseenko

update tooltips

parent bf0b87ac
...@@ -70,7 +70,11 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { ...@@ -70,7 +70,11 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
isOpen={ isPopoverOpen } isOpen={ isPopoverOpen }
onClose={ setIsPopoverOpen.off } onClose={ setIsPopoverOpen.off }
> >
<WalletTooltip isDisabled={ isWalletConnected || isMobile === undefined || isMobile }> <WalletTooltip
isDisabled={ isMobile === undefined || isMobile }
isWalletConnected={ isWalletConnected }
isAutoConnectDisabled={ isAutoConnectDisabled }
>
<Box ml={ 2 }> <Box ml={ 2 }>
<PopoverTrigger> <PopoverTrigger>
<Button <Button
......
...@@ -28,7 +28,12 @@ const WalletMenuMobile = () => { ...@@ -28,7 +28,12 @@ const WalletMenuMobile = () => {
return ( return (
<> <>
<WalletTooltip isDisabled={ isWalletConnected || isMobile === undefined || !isMobile } isMobile> <WalletTooltip
isDisabled={ isMobile === undefined || !isMobile }
isMobile
isWalletConnected={ isWalletConnected }
isAutoConnectDisabled={ isAutoConnectDisabled }
>
<IconButton <IconButton
aria-label="wallet menu" aria-label="wallet menu"
icon={ isWalletConnected ? icon={ isWalletConnected ?
......
...@@ -9,38 +9,46 @@ type Props = { ...@@ -9,38 +9,46 @@ type Props = {
children: React.ReactNode; children: React.ReactNode;
isDisabled?: boolean; isDisabled?: boolean;
isMobile?: boolean; isMobile?: boolean;
isWalletConnected?: boolean;
isAutoConnectDisabled?: boolean;
}; };
const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => { const LOCAL_STORAGE_KEY = 'wallet-connect-tooltip-shown';
const WalletTooltip = ({ children, isDisabled, isMobile, isWalletConnected, isAutoConnectDisabled }: Props) => {
const router = useRouter(); 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 label = React.useMemo(() => {
const isAppPage = router.pathname === '/apps/[id]'; if (isWalletConnected) {
const defaultLabel = <span>Your wallet is used to interact with<br/>apps and contracts in the explorer</span>; if (isAutoConnectDisabled) {
const label = isAppPage ? return <span>Your wallet is not<br/>connected to this app.<br/>Connect your wallet<br/>in the app directly</span>;
<span>Connect once to use your wallet with<br/>all apps in the DAppscout marketplace!</span> : }
defaultLabel; return <span>Your wallet is connected<br/>with Blockscout</span>;
const localStorageKey = `${ isAppPage ? 'dapp-' : '' }wallet-connect-tooltip-shown`; }
return { defaultLabel, label, localStorageKey }; return <span>Connect your wallet<br/>to Blockscout for<br/>full-featured access</span>;
}, [ router.pathname ]); }, [ isWalletConnected, isAutoConnectDisabled ]);
const isAppPage = router.pathname === '/apps/[id]';
React.useEffect(() => { React.useEffect(() => {
const wasShown = window.localStorage.getItem(localStorageKey); const wasShown = window.localStorage.getItem(LOCAL_STORAGE_KEY);
const isMarketplacePage = [ '/apps', '/apps/[id]' ].includes(router.pathname); const isMarketplacePage = router.pathname === '/apps';
const isTooltipShowAction = router.query.action === 'tooltip'; const isTooltipShowAction = router.query.action === 'tooltip';
const isConnectWalletAction = router.query.action === 'connect'; const isConnectWalletAction = router.query.action === 'connect';
const needToShow = (!wasShown && !isConnectWalletAction) || isTooltipShowAction; const needToShow = (isAppPage && !isConnectWalletAction) || isTooltipShowAction || (!wasShown && isMarketplacePage);
let timer1: ReturnType<typeof setTimeout>; let timer1: ReturnType<typeof setTimeout>;
let timer2: ReturnType<typeof setTimeout>; let timer2: ReturnType<typeof setTimeout>;
if (!isDisabled && isMarketplacePage && needToShow) { if (!isDisabled && needToShow) {
timer1 = setTimeout(() => { timer1 = setTimeout(() => {
setIsTooltipShown.on(); setIsTooltipShown.on();
window.localStorage.setItem(localStorageKey, 'true');
timer2 = setTimeout(() => setIsTooltipShown.off(), 5 * SECOND); timer2 = setTimeout(() => setIsTooltipShown.off(), 5 * SECOND);
if (!wasShown && isMarketplacePage) {
window.localStorage.setItem(LOCAL_STORAGE_KEY, 'true');
}
if (isTooltipShowAction) { if (isTooltipShowAction) {
removeQueryParam(router, 'action'); removeQueryParam(router, 'action');
} }
...@@ -51,14 +59,14 @@ const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => { ...@@ -51,14 +59,14 @@ const WalletTooltip = ({ children, isDisabled, isMobile }: Props) => {
clearTimeout(timer1); clearTimeout(timer1);
clearTimeout(timer2); clearTimeout(timer2);
}; };
}, [ setIsTooltipShown, localStorageKey, isDisabled, router ]); }, [ setIsTooltipShown, isDisabled, router, isAppPage ]);
return ( return (
<Tooltip <Tooltip
label={ isTooltipShown ? label : defaultLabel } label={ label }
textAlign="center" textAlign="center"
padding={ 2 } padding={ 2 }
isDisabled={ isDisabled } isDisabled={ isDisabled || (isWalletConnected && !isAppPage) }
openDelay={ 500 } openDelay={ 500 }
isOpen={ isTooltipShown || (isMobile ? false : undefined) } isOpen={ isTooltipShown || (isMobile ? false : undefined) }
onClose={ setIsTooltipShown.off } onClose={ setIsTooltipShown.off }
......
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