Skip to content

Commit adab7db

Browse files
Revert "Add token info button is missing for accounts without an email (blockscout#2627)"
This reverts commit 4765cbe.
1 parent fd0657f commit adab7db

File tree

3 files changed

+15
-34
lines changed

3 files changed

+15
-34
lines changed

ui/shared/AccountActionsMenu/AccountActionsMenu.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import getQueryParamString from 'lib/router/getQueryParamString';
1010
import Menu from 'ui/shared/chakra/Menu';
1111
import Skeleton from 'ui/shared/chakra/Skeleton';
1212
import IconSvg from 'ui/shared/IconSvg';
13+
import useProfileQuery from 'ui/snippets/auth/useProfileQuery';
1314

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

34+
const profileQuery = useProfileQuery();
35+
3336
const handleButtonClick = React.useCallback(() => {
3437
mixpanel.logEvent(mixpanel.EventTypes.PAGE_WIDGET, { Type: 'Address actions (more button)' });
3538
}, []);
3639

40+
const userWithoutEmail = profileQuery.data && !profileQuery.data.email;
41+
3742
const items = [
3843
{
3944
render: (props: ItemProps) => <MetadataUpdateMenuItem { ...props }/>,
4045
enabled: isTokenInstancePage && showUpdateMetadataItem,
4146
},
4247
{
4348
render: (props: ItemProps) => <TokenInfoMenuItem { ...props }/>,
44-
enabled: config.features.account.isEnabled && isTokenPage && config.features.addressVerification.isEnabled,
49+
enabled: config.features.account.isEnabled && isTokenPage && config.features.addressVerification.isEnabled && !userWithoutEmail,
4550
},
4651
{
4752
render: (props: ItemProps) => <PrivateTagMenuItem { ...props } entityType={ isTxPage ? 'tx' : 'address' }/>,

ui/shared/AccountActionsMenu/items/TokenInfoMenuItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const TokenInfoMenuItem = ({ className, hash, type }: ItemProps) => {
7070
switch (type) {
7171
case 'button': {
7272
return (
73-
<AuthGuard onAuthSuccess={ onAuthSuccess } ensureEmail>
73+
<AuthGuard onAuthSuccess={ onAuthSuccess }>
7474
{ ({ onClick }) => (
7575
<ButtonItem label={ label } icon={ icon } onClick={ onClick } className={ className }/>
7676
) }
@@ -79,7 +79,7 @@ const TokenInfoMenuItem = ({ className, hash, type }: ItemProps) => {
7979
}
8080
case 'menu_item': {
8181
return (
82-
<AuthGuard onAuthSuccess={ onAuthSuccess } ensureEmail>
82+
<AuthGuard onAuthSuccess={ onAuthSuccess }>
8383
{ ({ onClick }) => (
8484
<MenuItem className={ className } onClick={ onClick }>
8585
{ icon }

ui/snippets/auth/AuthGuard.tsx

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useDisclosure } from '@chakra-ui/react';
22
import React from 'react';
33

44
import AuthModal from './AuthModal';
5-
import useProfileQuery from './useProfileQuery';
5+
import useIsAuth from './useIsAuth';
66

77
interface InjectedProps {
88
onClick: () => void;
@@ -11,51 +11,27 @@ interface InjectedProps {
1111
interface Props {
1212
children: (props: InjectedProps) => React.ReactNode;
1313
onAuthSuccess: () => void;
14-
ensureEmail?: boolean;
1514
}
1615

17-
const AuthGuard = ({ children, onAuthSuccess, ensureEmail }: Props) => {
16+
const AuthGuard = ({ children, onAuthSuccess }: Props) => {
1817
const authModal = useDisclosure();
19-
const profileQuery = useProfileQuery();
18+
const isAuth = useIsAuth();
2019

2120
const handleClick = React.useCallback(() => {
22-
if (profileQuery.data) {
23-
if (ensureEmail && !profileQuery.data.email) {
24-
authModal.onOpen();
25-
} else {
26-
onAuthSuccess();
27-
}
28-
} else {
29-
authModal.onOpen();
30-
}
31-
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);
21+
isAuth ? onAuthSuccess() : authModal.onOpen();
22+
}, [ authModal, isAuth, onAuthSuccess ]);
3223

3324
const handleModalClose = React.useCallback((isSuccess?: boolean) => {
3425
if (isSuccess) {
35-
if (ensureEmail && !profileQuery.data?.email) {
36-
// If the user has logged in and has not added an email
37-
// we need to close the modal and open it again
38-
// so the initial screen will be correct
39-
authModal.onClose();
40-
window.setTimeout(() => {
41-
authModal.onOpen();
42-
}, 500);
43-
return;
44-
}
4526
onAuthSuccess();
4627
}
4728
authModal.onClose();
48-
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);
29+
}, [ authModal, onAuthSuccess ]);
4930

5031
return (
5132
<>
5233
{ children({ onClick: handleClick }) }
53-
{ authModal.isOpen && (
54-
<AuthModal
55-
onClose={ handleModalClose }
56-
initialScreen={ profileQuery.data && !profileQuery.data.email && ensureEmail ? { type: 'email' } : { type: 'select_method' } }
57-
/>
58-
) }
34+
{ authModal.isOpen && <AuthModal onClose={ handleModalClose } initialScreen={{ type: 'select_method' }}/> }
5935
</>
6036
);
6137
};

0 commit comments

Comments
 (0)