Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token info button is missing for accounts without an email #2627

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ui/shared/AccountActionsMenu/AccountActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import getQueryParamString from 'lib/router/getQueryParamString';
import Menu from 'ui/shared/chakra/Menu';
import Skeleton from 'ui/shared/chakra/Skeleton';
import IconSvg from 'ui/shared/IconSvg';
import useProfileQuery from 'ui/snippets/auth/useProfileQuery';

import MetadataUpdateMenuItem from './items/MetadataUpdateMenuItem';
import PrivateTagMenuItem from './items/PrivateTagMenuItem';
Expand All @@ -31,22 +30,18 @@ const AccountActionsMenu = ({ isLoading, className, showUpdateMetadataItem }: Pr
const isTokenInstancePage = router.pathname === '/token/[hash]/instance/[id]';
const isTxPage = router.pathname === '/tx/[hash]';

const profileQuery = useProfileQuery();

const handleButtonClick = React.useCallback(() => {
mixpanel.logEvent(mixpanel.EventTypes.PAGE_WIDGET, { Type: 'Address actions (more button)' });
}, []);

const userWithoutEmail = profileQuery.data && !profileQuery.data.email;

const items = [
{
render: (props: ItemProps) => <MetadataUpdateMenuItem { ...props }/>,
enabled: isTokenInstancePage && showUpdateMetadataItem,
},
{
render: (props: ItemProps) => <TokenInfoMenuItem { ...props }/>,
enabled: config.features.account.isEnabled && isTokenPage && config.features.addressVerification.isEnabled && !userWithoutEmail,
enabled: config.features.account.isEnabled && isTokenPage && config.features.addressVerification.isEnabled,
},
{
render: (props: ItemProps) => <PrivateTagMenuItem { ...props } entityType={ isTxPage ? 'tx' : 'address' }/>,
Expand Down
4 changes: 2 additions & 2 deletions ui/shared/AccountActionsMenu/items/TokenInfoMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const TokenInfoMenuItem = ({ className, hash, type }: ItemProps) => {
switch (type) {
case 'button': {
return (
<AuthGuard onAuthSuccess={ onAuthSuccess }>
<AuthGuard onAuthSuccess={ onAuthSuccess } ensureEmail>
{ ({ onClick }) => (
<ButtonItem label={ label } icon={ icon } onClick={ onClick } className={ className }/>
) }
Expand All @@ -79,7 +79,7 @@ const TokenInfoMenuItem = ({ className, hash, type }: ItemProps) => {
}
case 'menu_item': {
return (
<AuthGuard onAuthSuccess={ onAuthSuccess }>
<AuthGuard onAuthSuccess={ onAuthSuccess } ensureEmail>
{ ({ onClick }) => (
<MenuItem className={ className } onClick={ onClick }>
{ icon }
Expand Down
38 changes: 31 additions & 7 deletions ui/snippets/auth/AuthGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDisclosure } from '@chakra-ui/react';
import React from 'react';

import AuthModal from './AuthModal';
import useIsAuth from './useIsAuth';
import useProfileQuery from './useProfileQuery';

interface InjectedProps {
onClick: () => void;
Expand All @@ -11,27 +11,51 @@ interface InjectedProps {
interface Props {
children: (props: InjectedProps) => React.ReactNode;
onAuthSuccess: () => void;
ensureEmail?: boolean;
}

const AuthGuard = ({ children, onAuthSuccess }: Props) => {
const AuthGuard = ({ children, onAuthSuccess, ensureEmail }: Props) => {
const authModal = useDisclosure();
const isAuth = useIsAuth();
const profileQuery = useProfileQuery();

const handleClick = React.useCallback(() => {
isAuth ? onAuthSuccess() : authModal.onOpen();
}, [ authModal, isAuth, onAuthSuccess ]);
if (profileQuery.data) {
if (ensureEmail && !profileQuery.data.email) {
authModal.onOpen();
} else {
onAuthSuccess();
}
} else {
authModal.onOpen();
}
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);

const handleModalClose = React.useCallback((isSuccess?: boolean) => {
if (isSuccess) {
if (ensureEmail && !profileQuery.data?.email) {
// If the user has logged in and has not added an email
// we need to close the modal and open it again
// so the initial screen will be correct
authModal.onClose();
window.setTimeout(() => {
authModal.onOpen();
}, 500);
return;
}
onAuthSuccess();
}
authModal.onClose();
}, [ authModal, onAuthSuccess ]);
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);

return (
<>
{ children({ onClick: handleClick }) }
{ authModal.isOpen && <AuthModal onClose={ handleModalClose } initialScreen={{ type: 'select_method' }}/> }
{ authModal.isOpen && (
<AuthModal
onClose={ handleModalClose }
initialScreen={ profileQuery.data && !profileQuery.data.email && ensureEmail ? { type: 'email' } : { type: 'select_method' } }
/>
) }
</>
);
};
Expand Down
Loading