Commit 0195da4e authored by tom's avatar tom

call resources only if user is authenticated

parent 73f78457
...@@ -74,7 +74,7 @@ const AddressVerificationStepAddress = ({ defaultAddress, onContinue }: Props) = ...@@ -74,7 +74,7 @@ const AddressVerificationStepAddress = ({ defaultAddress, onContinue }: Props) =
return <span>Specified address either does not exist or is EOA.</span>; return <span>Specified address either does not exist or is EOA.</span>;
} }
case 'IS_OWNER_ERROR': { case 'IS_OWNER_ERROR': {
return <span>Ownership of this contract address ownership is already verified by this account.</span>; return <span>Ownership of this contract address is already verified by this account.</span>;
} }
case 'OWNERSHIP_VERIFIED_ERROR': { case 'OWNERSHIP_VERIFIED_ERROR': {
return <span>Ownership of this contract address is already verified by another account.</span>; return <span>Ownership of this contract address is already verified by another account.</span>;
......
import { MenuItem, Icon, chakra, useDisclosure } from '@chakra-ui/react'; import { MenuItem, Icon, chakra, useDisclosure } from '@chakra-ui/react';
import { useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import type { TokenVerifiedInfo } from 'types/api/token';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
import iconEdit from 'icons/edit.svg'; import iconEdit from 'icons/edit.svg';
import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import useHasAccount from 'lib/hooks/useHasAccount';
import useRedirectIfNotAuth from 'lib/hooks/useRedirectIfNotAuth'; import useRedirectIfNotAuth from 'lib/hooks/useRedirectIfNotAuth';
import AddressVerificationModal from 'ui/addressVerification/AddressVerificationModal'; import AddressVerificationModal from 'ui/addressVerification/AddressVerificationModal';
...@@ -20,13 +18,25 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => { ...@@ -20,13 +18,25 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => {
const router = useRouter(); const router = useRouter();
const modal = useDisclosure(); const modal = useDisclosure();
const redirectIfNotAuth = useRedirectIfNotAuth(); const redirectIfNotAuth = useRedirectIfNotAuth();
const queryClient = useQueryClient(); const isAuth = useHasAccount();
const verifiedAddressesQuery = useApiQuery('verified_addresses', { const verifiedAddressesQuery = useApiQuery('verified_addresses', {
pathParams: { chainId: appConfig.network.id }, pathParams: { chainId: appConfig.network.id },
queryOptions: {
enabled: isAuth,
},
}); });
const applicationsQuery = useApiQuery('token_info_applications', { const applicationsQuery = useApiQuery('token_info_applications', {
pathParams: { chainId: appConfig.network.id, id: undefined }, pathParams: { chainId: appConfig.network.id, id: undefined },
queryOptions: {
enabled: isAuth,
},
});
const tokenInfoQuery = useApiQuery('token_verified_info', {
pathParams: { hash, chainId: appConfig.network.id },
queryOptions: {
refetchOnMount: false,
},
}); });
const handleAddAddressClick = React.useCallback(() => { const handleAddAddressClick = React.useCallback(() => {
...@@ -52,18 +62,11 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => { ...@@ -52,18 +62,11 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => {
const icon = <Icon as={ iconEdit } boxSize={ 6 } mr={ 2 } p={ 1 }/>; const icon = <Icon as={ iconEdit } boxSize={ 6 } mr={ 2 } p={ 1 }/>;
const content = (() => { const content = (() => {
const verifiedTokenInfo = queryClient.getQueryData<TokenVerifiedInfo>(
getResourceKey(
'token_verified_info',
{ pathParams: { hash, chainId: appConfig.network.id } },
),
);
if (!verifiedAddressesQuery.data?.verifiedAddresses.find(({ contractAddress }) => contractAddress.toLowerCase() === hash.toLowerCase())) { if (!verifiedAddressesQuery.data?.verifiedAddresses.find(({ contractAddress }) => contractAddress.toLowerCase() === hash.toLowerCase())) {
return ( return (
<MenuItem className={ className } onClick={ handleAddAddressClick }> <MenuItem className={ className } onClick={ handleAddAddressClick }>
{ icon } { icon }
<span>{ verifiedTokenInfo?.tokenAddress ? 'Update token info' : 'Add token info' }</span> <span>{ tokenInfoQuery.data?.tokenAddress ? 'Update token info' : 'Add token info' }</span>
</MenuItem> </MenuItem>
); );
} }
...@@ -75,7 +78,7 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => { ...@@ -75,7 +78,7 @@ const TokenInfoMenuItem = ({ className, hash }: Props) => {
{ icon } { icon }
<span> <span>
{ {
hasApplication || verifiedTokenInfo?.tokenAddress ? hasApplication || tokenInfoQuery.data?.tokenAddress ?
'Update token info' : 'Update token info' :
'Add token info' 'Add token info'
} }
......
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